Resource isInCombat for RS3

Discussion in 'Tutorials & Resources' started by Viewer, Nov 9, 2014.

  1. Viewer

    Joined:
    Jan 2, 2014
    Messages:
    303
    Likes Received:
    71
    A bit more specific than it would be for OSRS, maybe I'm complicating it too much but atleast it works :p

    Code (Text):
    1.  
    2. private static List<Actor> getLoadedActors() {
    3.         final List<Actor> list = new ArrayList<>();
    4.         list.addAll(Npcs.getLoaded());
    5.         list.addAll(Players.getLoaded());
    6.         return list;
    7.     }
    8.  
    9.     private static Actor getNearestFightingMe() {
    10.         final List<Actor> allInteractingWithMe = new ArrayList<>();
    11.         for (Actor a : getLoadedActors()) {
    12.             if (a != null && a.getTarget() != null && a.getTarget().equals(Players.getLocal())) {
    13.                 allInteractingWithMe.add(a);
    14.             }
    15.         }
    16.         if (allInteractingWithMe.size() > 0) {
    17.             return Sort.byDistance(allInteractingWithMe).get(0);
    18.         } else return null;
    19.     }
    20.  
    21.    
    22. public static boolean isInCombat(Actor actor) {
    23.         if (actor != null) {
    24.             final CombatGauge health = actor.getHealthGauge();
    25.             if (health == null || health.getPercent() > 0) {
    26.                 final Actor enemy = getNearestFightingMe();
    27.                 if (enemy != null && enemy.isValid()) {
    28.                     final CombatGauge enemyHealth = enemy.getHealthGauge();
    29.                     if (enemyHealth == null || enemyHealth.getPercent() > 0) {
    30.                         return true;
    31.                     }
    32.                 } else {
    33.                     final Actor target = actor.getTarget();
    34.                     if (target != null && target.isValid()) {
    35.                         final CombatGauge targetHealth = target.getHealthGauge();
    36.                         if (targetHealth != null && targetHealth.getPercent() > 0) {
    37.                             return true;
    38.                         }
    39.                     }
    40.                 }
    41.             }
    42.         }
    43.         return false;
    44.     }
    45.  
     
    #1 Viewer, Nov 9, 2014
    Last edited: Nov 10, 2014
    Savior likes this.
  2. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    610
    Likes Received:
    242
    Are we allowed to use this, if so, what do we have to include?
     
  3. Calle

    Joined:
    Nov 23, 2013
    Messages:
    48
    Likes Received:
    10
    he posted it open source, means you're allowed to use it :p, should be easy enough to use.
    OP: Nice @Viewer
     
  4. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    610
    Likes Received:
    242
    I made this and seems to work fine. And a lot less complicated :p

    Code (Text):
    1.     public static boolean isInCombat (final Actor a) {
    2.         return a.getTarget() != null || !Npcs.newQuery().filter(new Filter<Npc>() {
    3.             @Override
    4.             public boolean accepts(Npc npc) {
    5.                 return npc.getTarget() != null && npc.getTarget().equals(a);
    6.             }
    7.         }).results().isEmpty();
    8.     }
     
    Viewer likes this.
  5. Ozzy

    Joined:
    Nov 5, 2014
    Messages:
    504
    Likes Received:
    159
    Yeah I used a similar approach, gotta love queries.
     
  6. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    610
    Likes Received:
    242
    Oh yeah, your fighter is working now, just set the "eat at" value to zero :p
     
    Ozzy likes this.
  7. Viewer

    Joined:
    Jan 2, 2014
    Messages:
    303
    Likes Received:
    71
    Yeah haha a lot less complicated :p
     

Share This Page

Loading...