Jump to content

Random question


Recommended Posts

Posted

This may possibly be a stupid question but why is it that some people store RS2Objects/NPC's i.e 

 

I've always wondered is this bad coding or is there any benefit at all in doing this?

public class ClassName extends Script { 
private NPC npcName;
 
@[member=Override] public void onStart() {
npcName = getNpcs().closest(npc -> npc.getName().equals("Name") && npc.hasAction("Attack") && npc.getHealthPercent() > 0 && !npc.isUnderAttack());
 
}
 
@[member=Override]
public int onLoop() throws InterruptedException { 
if(npcName != null && !getCombat().isFighting() && !myPlayer().isUnderAttack() && !myPlayer().isInteracting(npcName)) {
npcName.interact("Attack");
//cond sleep etc
}
else { //else stuff
}
return int of choice;
}
 

I've seen some people doing this and from my understanding, they store the NPC name/filter conditions into the NPC variable that they create but in the onLoop() they'll call the variable and the pre-set filter conditions?

 

(Sorry if that doesn't make sense)

 

TLDR; why would people do this?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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