Botre Posted June 8, 2014 Share Posted June 8, 2014 (edited) Mainly useful for combat situations with aggressive monsters: package myplayer.Botrepreneur; import java.util.ArrayList; import java.util.List; import java.util.Random; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.Script; public class WhoIsInteractingWithMe { /** * @author Botrepreneur * @Version: 00.21 */ public static List<NPC> getList(Script script) { List<NPC> returnList = new ArrayList<NPC>(); List<NPC> allList = script.npcs.getAll(); if (allList != null && !allList.isEmpty()) { for (NPC npc : allList) { if (npc != null && npc.getInteracting() != null && npc.getInteracting().getName().equals(script.myPlayer().getName())) { returnList.add(npc); } } } return returnList; } public static NPC getRandom(Script script) { List<NPC> list = WhoIsInteractingWithMe.getList(script); return list != null && !list.isEmpty() ? list.get(new Random().nextInt(list.size()) - 1) : null; } public static NPC getClosest(Script script) { double lowestDistance = Double.MAX_VALUE; List<NPC> allList = script.npcs.getAll(); List<NPC> closestList = new ArrayList<NPC>(); if (allList != null && !allList.isEmpty()) { for (NPC npc : allList) { if (npc == null || !npc.exists() || npc.getInteracting() == null || !npc.getInteracting().getName().equals(script.myPlayer().getName())) { continue; } if (npc.getPosition().distance(script.myPosition()) < lowestDistance) { closestList.clear(); closestList.add(npc); lowestDistance = npc.getPosition().distance(script.myPosition()); } else if (npc.getPosition().distance(script.myPosition()) == lowestDistance) { closestList.add(npc); } } } return closestList != null && !closestList.isEmpty() ? closestList.get(new Random().nextInt(closestList.size()) - 1) : null; } } Edited July 5, 2014 by Botrepreneur Link to comment Share on other sites More sharing options...
Swizzbeat Posted June 8, 2014 Share Posted June 8, 2014 Or can't you just do player/character.getInteracting()? Link to comment Share on other sites More sharing options...
Nitrousek Posted June 8, 2014 Share Posted June 8, 2014 Or can't you just do player/character.getInteracting()? No, he wants to get all the NPCs attacking him, useful when you've got a lot of them and they're agressive. player get interacting wouldn't do the job, because: 1. you may not be interacting 2. if interacting, it's one NPC, and it's not used for the same purpose. 1 Link to comment Share on other sites More sharing options...
PolishCivil Posted June 17, 2014 Share Posted June 17, 2014 Possible solutions:Mulit area:A filter all npcs that are interacting with you, when you're not interacting any and you're under attack.A result - the npc you want to attack first.B filter all npcs that are interacting you, when you're attacking npc. B result - now you have npc that you want to attack next (after killing the current one) Single areaA simply filter all npcs that are interacting with you when you're not interacting any and you're under attack.A result - the npc you want to attack, or run away from it.You want to make such things in other thread. 1 Link to comment Share on other sites More sharing options...
Botre Posted July 5, 2014 Author Share Posted July 5, 2014 Updated Link to comment Share on other sites More sharing options...
ProtectedForum Posted July 24, 2014 Share Posted July 24, 2014 very nice code Link to comment Share on other sites More sharing options...