Jump to content

Random question


Saiyan

Recommended Posts

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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