Jump to content

Preventing Spam Clicking of Monsters


Warpclaw

Recommended Posts

Well I am basically done with my Pest Control script (which will be free), but the only issue I am having is that it will try to attack shifters until no tomorrow. This is because the myPlayer().isUnderAttack() wont work since the shifters in pest control wont be attacking you. And I cant make it so shifter.isUnderAttack() since it wont attack the shifter since other players will be attacking it. I want to be able to make it so that if I am attacking a shifter, regardless of whether I am being attacked or the shifter is being attacked by other players, the script wont try to attack another shifter since the script will recognize that shifter as a shifter that is available to attack. The script will stop attacking the shifter I'd be currently attacking and will attack another one that is closer since I have npcs.getClosest("Shifter").

 

Thanks!

Link to comment
Share on other sites

Well I am basically done with my Pest Control script (which will be free), but the only issue I am having is that it will try to attack shifters until no tomorrow. This is because the myPlayer().isUnderAttack() wont work since the shifters in pest control wont be attacking you. And I cant make it so shifter.isUnderAttack() since it wont attack the shifter since other players will be attacking it. I want to be able to make it so that if I am attacking a shifter, regardless of whether I am being attacked or the shifter is being attacked by other players, the script wont try to attack another shifter since the script will recognize that shifter as a shifter that is available to attack. The script will stop attacking the shifter I'd be currently attacking and will attack another one that is closer since I have npcs.getClosest("Shifter").

Thanks!

I haven't made a combat script yet, but did you try to get the npc that the player is Interacting with? If it's null, attack.

Link to comment
Share on other sites

You could always do the following if I'm understanding you correctly:

if(myPlayer().getInteracting() == null){
   //attack shifter
}

Very basic but it will fetch the Entity your interacting with and if Null will execute the if statement.

Yeah, but he could be attacking something other than a Shifter and would want to switch to a Shifter so a name check would be useful.

if (myPlayer().getInteracting() == null || !myPlayer().getInteracting().getName().equals("Shifter") {
     //Attack a shifter. . .

}
Edited by Eliot
Link to comment
Share on other sites

Thanks so much for the help guys! It worked smile.png It's giving nullpointer exceptions when there arent any shifters but I'm not worried about that :3

 

 

Null check before you attempt to interact with a shifter. Also make sure that you store the shifter in an npc variable, and then always use that same variable when checking/interacting. Otherwise you can get an NPE even if you null check. ^_^

Link to comment
Share on other sites

I would stay away from deciding whether you're in combat or not based on what getInteracting returns. Last I checked it just returned whatever your player is facing, which means unless you have the proper checks you could literally be standing facing a wall for hours on end.

 

 

Yeah, but he could be attacking something other than a Shifter and would want to switch to a Shifter so a name check would be useful.

if (myPlayer().getInteracting() == null || !myPlayer().getInteracting().getName().equals("Shifter") {
     //Attack a shifter. . .

}

Store the interacting in a variable, so you don't have to recalculate twice + whenever else you would need that instance.

 

 

  • Like 1
Link to comment
Share on other sites

I would stay away from deciding whether you're in combat or not based on what getInteracting returns. Last I checked it just returned whatever your player is facing, which means unless you have the proper checks you could literally be standing facing a wall for hours on end.

 

Store the interacting in a variable, so you don't have to recalculate twice + whenever else you would need that instance.

Yeah there you could use a variable for it for sure, but there may be situations where it is not advisible to only get it once during an entire loop, hence why I'd just call it directly nearly every time I need it (it doesn't matter anyways). Or you could set it to a variable and just update it if needed. 

Edited by Eliot
Link to comment
Share on other sites

You could also check for a player animation as a secondary, perhaps a conditional sleep until you're animating

 

 

 

public void sleepUntilAnimatiing(Script script, long timeout) {

Timer t = new Timer();

while(!script.myPlayer().isAnimating() && t.getElapsed() <= timeout) {

script.sleep(600);

}

}

 

 

wrote that real quick in the text box now and should do the job (sorry for typos) but its just a simple double check which you can use once you click a shifter to sleep until you're playing a combat animation for example. This accounts for the delay between clicking the shifter and walking towards it.

 

implementation:

 

if (shifter != null && shifter.exists()) {

if (shifter.interact("Attack")) {

sleepUntilAnimating(this, 5000L);

}

}

 

hope this helped

 

-apaec

Link to comment
Share on other sites

Yeah there you could use a variable for it for sure, but there may be situations where it is not advisible to only get it once during an entire loop, hence why I'd just call it directly nearly every time I need it (it doesn't matter anyways). Or you could set it to a variable and just update it if needed. 

 

Yeah but there are different ID's for shifters which is why I make sure it is a new variable each time it checks haha. I'm still extremely new to scripting so I'm not sure how to do a null check/prevent the NPE's. But the script is running flawlessly atm :)

  • Like 1
Link to comment
Share on other sites

Yeah but there are different ID's for shifters which is why I make sure it is a new variable each time it checks haha. I'm still extremely new to scripting so I'm not sure how to do a null check/prevent the NPE's. But the script is running flawlessly atm :)

An exception isn't scripting knowledge but basic Java 101 :facep:
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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