Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Efficiency and new query calls

Joined
Apr 21, 2019
Messages
40
Hey guys im noticing whenever I poll for enemies to attack in my fighter bot I am having substantial stuttering and lag during the new query. The query in question is as follows, and makes sure enemies found are within my defined area constraints.

Npc cow = Npcs.newQuery().names(Pattern.compile("Cow")).actions("Attack").visible().reachable().within(StoredVariables.CowAreaA, StoredVariables.CowAreaB, StoredVariables.CowAreaC).filter(x -> x != null && x.getHealthGauge() == null && x.getTarget() == null && x.getPosition() != Players.getLocal().getPosition()).results().nearest(bot.StoredVariables.DistanceAlgorithm);

Is there a more efficient way to write such a query, maybe I don't need as many null checks?
 
Joined
Oct 21, 2018
Messages
415
.nearest() will already return the nearest npc anyways, but yes, checking only around the players position could improve the performance, but might not be necessary
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
7,745
maybe I don't need as many null checks
Null checking too much is never really an issue as it's so quick

Honestly I'd just recommend running the line repeatedly, taking out a chunk from it each time and see which removal causes a dramatic speedup. But yeah it's probably the visibility or reachability. Or maybe your sort algorithm depending on what it is.
 
Top