Jump to content

Useful Entity related methods


Cory
 Share

Recommended Posts


public static RS2Object closestObjectWithAction(Script script, String action) {

List<RS2Object> allObjects = script.client.getCurrentRegion().getObjects();

List<RS2Object> objects = new ArrayList<RS2Object>();

if(allObjects != null && allObjects.size() > 0) {

for(RS2Object object : allObjects) {

if(object != null && hasAction(object, action))

objects.add(object);

}

}

return (RS2Object) closest(script, objects);

}

public static NPC closestNPCWithAction(Script script, String action) {

List<NPC> allNPCs = script.client.getLocalNPCs();

List<NPC> NPCs = new ArrayList<NPC>();

if(allNPCs != null && allNPCs.size() > 0) {

for(NPC npc : allNPCs) {

if(npc != null && hasAction(npc, action))

NPCs.add(npc);

}

}

return (NPC) closest(script, NPCs);

}

public static Entity closest(Script script, List<? extends Entity> entities) {

Entity closest = null;

for (Entity entity : entities) {

if(closest == null)

closest = entity;

if(script.distance(entity) < script.distance(closest))

closest = entity;

}

return closest;

}

public static boolean hasAction(NPC npc, String action) {

NPCDefinition i = npc.getDefinition();

return hasAction(i.getActions(), action);

}

public static boolean hasAction(RS2Object object, String action) {

ObjectDefinition i = object.getDefinition();

return hasAction(i.getActions(), action);

}

public static boolean hasAction(String[] actions, String action) {

for(String a : actions) {

if(action.equals(a))

return true;

}

return false;

}

Edited by Cory
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...