Warpclaw Posted August 4, 2014 Share Posted August 4, 2014 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 More sharing options...
Mysteryy Posted August 4, 2014 Share Posted August 4, 2014 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 More sharing options...
Warpclaw Posted August 4, 2014 Author Share Posted August 4, 2014 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. myPlayer().isInteracting(Shifter) I used that, but since there are more than one shifters, its going to return that it isnt theres a shifter that isnt being intereacted with. Link to comment Share on other sites More sharing options...
Alek Posted August 4, 2014 Share Posted August 4, 2014 I've added a method to the api under the combat class called isFighting(). You would do something like if(combat.isFighting()). It should be released in the next version of OSBot. The method itself was written a while ago... 1 Link to comment Share on other sites More sharing options...
Eliot Posted August 4, 2014 Share Posted August 4, 2014 (edited) if (myPlayer().getInteracting() != null && myPlayer().getInteracting().getName().equals("Shifter") { //This means you're attacking a shifter, woot! } Edited August 4, 2014 by Eliot Link to comment Share on other sites More sharing options...
Extreme Scripts Posted August 4, 2014 Share Posted August 4, 2014 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. Link to comment Share on other sites More sharing options...
Eliot Posted August 4, 2014 Share Posted August 4, 2014 (edited) 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 August 4, 2014 by Eliot Link to comment Share on other sites More sharing options...
Extreme Scripts Posted August 4, 2014 Share Posted August 4, 2014 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. Couldn't agree more, posted this same time as yours nearly, was in editor when you posted yours 1 Link to comment Share on other sites More sharing options...
Warpclaw Posted August 5, 2014 Author Share Posted August 5, 2014 Thanks so much for the help guys! It worked It's giving nullpointer exceptions when there arent any shifters but I'm not worried about that :3 Link to comment Share on other sites More sharing options...
Mysteryy Posted August 5, 2014 Share Posted August 5, 2014 Thanks so much for the help guys! It worked 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 More sharing options...
Swizzbeat Posted August 5, 2014 Share Posted August 5, 2014 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. 1 Link to comment Share on other sites More sharing options...
Eliot Posted August 5, 2014 Share Posted August 5, 2014 (edited) 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 August 5, 2014 by Eliot Link to comment Share on other sites More sharing options...
Apaec Posted August 5, 2014 Share Posted August 5, 2014 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 More sharing options...
Warpclaw Posted August 5, 2014 Author Share Posted August 5, 2014 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 1 Link to comment Share on other sites More sharing options...
Swizzbeat Posted August 5, 2014 Share Posted August 5, 2014 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 Link to comment Share on other sites More sharing options...