- Joined
- Jan 2, 2014
- Messages
- 306
- Thread Author
- #1
A bit more specific than it would be for OSRS, maybe I'm complicating it too much but atleast it works
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: