1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Best/Fastest way to perform NPC selection

Discussion in 'Developer Support' started by krock69, Sep 23, 2018.

  1. krock69

    Joined:
    Jul 10, 2018
    Messages:
    6
    Likes Received:
    0
    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 (Text):
    1.  
    2. private Npc selectNPC() {
    3.     Npc toAttack = Npcs.newQuery()
    4.             .names("xxx")
    5.             .within(Area)
    6.             .results()
    7.             .sortByDistance()
    8.             .first();
    9.     if (toAttack== null
    10.             || !toAttack.isValid()
    11.             || toAttack.getHealthGauge() != null
    12.             || toAttack.getTarget() != null) {
    13.         return selectNPC();
    14.     }
    15.     return toAttack;
    16. }
    17.  
    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
     
  2. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,117
    Likes Received:
    1,374
    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.
     
  3. S Q U R E L

    Joined:
    May 30, 2018
    Messages:
    203
    Likes Received:
    84
    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.
     
    CuppaJava likes this.
  4. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,117
    Likes Received:
    1,374
    Oh I didn't notice the recursion, whoops haha
     
  5. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    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.
     
  6. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,117
    Likes Received:
    1,374
    Ignore my original post, there's lots wrong with your code (and my code, probably) :rolleyes:
     
  7. krock69

    Joined:
    Jul 10, 2018
    Messages:
    6
    Likes Received:
    0
    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?

    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.
     

Share This Page

Loading...