Welcome!

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

Sign up now!
RuneMate will permanently shut down on August 7, 2026
due to events outside our control. You can continue using RuneMate until this date after which it will no longer be available. Thank you to everyone that contributed to RuneMate's success and to the community for the opportunity to serve you all these years.

  • Learn about RuneMate Vault and how its zero knowledge local encryption already protects your sensitive information.
  • Edit or delete your RuneMate account from your Account Settings.
  • All account upgrade subscriptions have been cancelled. No action required.

Resource isInCombat for RS3

Discretion is advised
Joined
Jan 2, 2014
Messages
306
A bit more specific than it would be for OSRS, maybe I'm complicating it too much but atleast it works :p

Code:
private static List<Actor> getLoadedActors() {
        final List<Actor> list = new ArrayList<>();
        list.addAll(Npcs.getLoaded());
        list.addAll(Players.getLoaded());
        return list;
    }

    private static Actor getNearestFightingMe() {
        final List<Actor> allInteractingWithMe = new ArrayList<>();
        for (Actor a : getLoadedActors()) {
            if (a != null && a.getTarget() != null && a.getTarget().equals(Players.getLocal())) {
                allInteractingWithMe.add(a);
            }
        }
        if (allInteractingWithMe.size() > 0) {
            return Sort.byDistance(allInteractingWithMe).get(0);
        } else return null;
    }

   
public static boolean isInCombat(Actor actor) {
        if (actor != null) {
            final CombatGauge health = actor.getHealthGauge();
            if (health == null || health.getPercent() > 0) {
                final Actor enemy = getNearestFightingMe();
                if (enemy != null && enemy.isValid()) {
                    final CombatGauge enemyHealth = enemy.getHealthGauge();
                    if (enemyHealth == null || enemyHealth.getPercent() > 0) {
                        return true;
                    }
                } else {
                    final Actor target = actor.getTarget();
                    if (target != null && target.isValid()) {
                        final CombatGauge targetHealth = target.getHealthGauge();
                        if (targetHealth != null && targetHealth.getPercent() > 0) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
 
Last edited:
Joined
Nov 26, 2014
Messages
616
I made this and seems to work fine. And a lot less complicated :p

Code:
    public static boolean isInCombat (final Actor a) {
        return a.getTarget() != null || !Npcs.newQuery().filter(new Filter<Npc>() {
            @Override
            public boolean accepts(Npc npc) {
                return npc.getTarget() != null && npc.getTarget().equals(a);
            }
        }).results().isEmpty();
    }
 
Joined
Nov 5, 2014
Messages
505
I made this and seems to work fine. And a lot less complicated :p

Code:
    public static boolean isInCombat (final Actor a) {
        return a.getTarget() != null || !Npcs.newQuery().filter(new Filter<Npc>() {
            @Override
            public boolean accepts(Npc npc) {
                return npc.getTarget() != null && npc.getTarget().equals(a);
            }
        }).results().isEmpty();
    }

Yeah I used a similar approach, gotta love queries.
 
Discretion is advised
Joined
Jan 2, 2014
Messages
306
I made this and seems to work fine. And a lot less complicated :p

Code:
    public static boolean isInCombat (final Actor a) {
        return a.getTarget() != null || !Npcs.newQuery().filter(new Filter<Npc>() {
            @Override
            public boolean accepts(Npc npc) {
                return npc.getTarget() != null && npc.getTarget().equals(a);
            }
        }).results().isEmpty();
    }

Yeah haha a lot less complicated :p
 
Top