(Resolved) Problems establishing if player is in combat

Discussion in 'Client & Site Support' started by Ozzy, Dec 9, 2014.

  1. Ozzy

    Joined:
    Nov 5, 2014
    Messages:
    504
    Likes Received:
    159
    I'm having loads of trouble trying to establish if the local player is in combat, methods which have worked fine in the past are now not working correctly.

    I've tried a few different ways, but this is the method which I have used in the past which is consistently returning false even when the player is attacking and being attacked by loads of different npcs.

    Code (Text):
    1. private Boolean isInCombat(Actor a) {
    2.         return a.getTarget() != null || !Npcs.newQuery().within(fightArea).filter(new Filter<Npc>() {
    3.             @Override
    4.             public boolean accepts(Npc npc) {
    5.                 return npc.getTarget() == a;
    6.             }
    7.         }).results().isEmpty();
    8.     }
    Any idea what's up with this?

    Thanks

    @Cloud
     
  2. Cloud

    Cloud The Developer

    Joined:
    Jul 28, 2013
    Messages:
    2,323
    Likes Received:
    754
    The first bug I see is npc.getTarget() == a should be .equals instead
     
  3. Ozzy

    Joined:
    Nov 5, 2014
    Messages:
    504
    Likes Received:
    159
    Thanks, I've read up on why that fixed the problem and I've updated my code.
     

Share This Page

Loading...