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 Best/Fastest way to perform NPC selection

Joined
Jul 10, 2018
Messages
6
All

I can't tell if it's the runemate api or my code that is just quite frankly causing long pauses between NPC selection (in a combat bot).

Code:
private Npc selectNPC() {
    Npc toAttack = Npcs.newQuery()
            .names("xxx")
            .within(Area)
            .results()
            .sortByDistance()
            .first();
    if (toAttack== null
            || !toAttack.isValid()
            || toAttack.getHealthGauge() != null
            || toAttack.getTarget() != null) {
        return selectNPC();
    }
    return toAttack;
}

This is my code for selecting an NPC to attack. It's got a couple of problems that I would like some insight on.

Sometimes, for no apparent reason/with no correlation to other events, it simply takes 10-15 seconds to attack the next NPC, despite having multiple valid NPCs. It also sometimes will attack NPCs in combat with others or attack a different NPC than it's already attacking, however these happen infrequently enough to not be a major issue like the long delays.

So -- what's the definitive way to select an NPC for combat? Where am I going wrong? I feel like there should be an API class specifically made with the expertise of the core coders that does this.

Thanks!

also -- if someone could point me to a developer chat/discord that'd be great thanks
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
7,099
Typically dev text chatter happens in slack, and discord is apparently used for voice chat (but I've never been on the RM discord) Join RuneMate Chat | RuneMate

At a glance your code looks fine to me. In my experience sometimes RuneMate just craps out for a little while. But I'm interested to see if anyone else has a better explaination.
 
Joined
May 30, 2018
Messages
203
If nobody moves your method will enter an infinite loop, because it always finds the first npc in the query, and if that npc is bad, then it recurses forever. Your cpu is probably committing suicide when you run this code lol.

Haven't done this stuff in a while but if you use a predicate (or something similar, I forgot) you can filter from npcs with the desired traits (so you won't have to check for validity). Also, stick with one action per loop.
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
7,099
If nobody moves your method will enter an infinite loop, because it always finds the first npc in the query, and if that npc is bad, then it recurses forever. Your cpu is probably committing suicide when you run this code lol.

Haven't done this stuff in a while but if you use a predicate (or something similar, I forgot) you can filter from npcs with the desired traits (so you won't have to check for validity). Also, stick with one action per loop.
Oh I didn't notice the recursion, whoops haha
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
Also doing isValid on something just returned by a query is pointless because if it wasn't valid it wouldn't be a possible input into the query to begin with.
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
7,099
Ignore my original post, there's lots wrong with your code (and my code, probably) :rolleyes:
 
Joined
Jul 10, 2018
Messages
6
If nobody moves your method will enter an infinite loop, because it always finds the first npc in the query, and if that npc is bad, then it recurses forever. Your cpu is probably committing suicide when you run this code lol.

Haven't done this stuff in a while but if you use a predicate (or something similar, I forgot) you can filter from npcs with the desired traits (so you won't have to check for validity). Also, stick with one action per loop.

Ok this is probably what it was, because it would happen when the local player wouldn't move. Also, I had previously added an Execution delay but edited it out for brevity to protect CPU.

What do you mean one action per loop?

Also doing isValid on something just returned by a query is pointless because if it wasn't valid it wouldn't be a possible input into the query to begin with.
Cloud -- could you elaborate on the proper, definitive way to select an NPC for combat purposes? I feel like since you built this thing you could offer the best insight. What checks are needed? Which work better than others?

I appreciate the help guys.
 
Top