hellcatz Posted September 14, 2020 Share Posted September 14, 2020 (edited) hello everyone im trying to write my first script basicly a sandcrab training script. now is my problem this: NPC SC = npcs.closest("Sand Crab"); RS2Object BC = getObjects().closest("Bank chest"); Position MP = myPosition(); if (!CT.contains(MP) && getInventory().contains("Salmon")) { log("Combat Area is empty walking to there now"); getWalking().webWalk(CT); } else if (myPlayer().getHealthPercent() < 35) { log("Health below 35% eating Salmon"); getInventory().interact("Eat", "Salmon"); } else if (CT.contains(SC) && SC != null && !myPlayer().isAnimating()) { log("Attacking Sand Crab"); SC.interact("Attack"); sleep(50); } else if (!myPlayer().isAnimating() && SC == null) { log("resetting Agro"); getWalking().webWalk(RSA); } else if (!getInventory().contains("Salmon")) { log("No food found in inventory checking bank"); getWalking().webWalk(BT); if (BT.contains(MP)) { BC.interact("Use"); sleep(2000); } if (getBank().contains("Salmon")) { getBank().withdrawAll("Salmon"); } else if (!getBank().contains("Salmon")) { log("No food to be found please restock"); stop(); } } return random(3000, 60000); } it takes ages to get the log the attack even so long that it will log me out it also wont move to RSA when he supposed to (if we dont have agro or !myPlayer().isAnimating()) this is all in onLoop() am i missing something or .... this is what comes from the logger [INFO][Bot #1][09/14 09:37:23 PM]: Attacking Sand Crab [INFO][Bot #1][09/14 09:41:16 PM]: Attacking Sand Crab clearly its more then 1 minute thanks in advance:D Edited September 14, 2020 by lucune Logger log 1 Quote Link to comment Share on other sites More sharing options...
Team Cape Posted September 14, 2020 Share Posted September 14, 2020 (edited) So, a few problems. I'll go in order of least important to most important: (1) Your code is prone to null pointer exceptions: CT.contains(SC) && SC != null Switch this to check if the object is null first. You should do this for all of your code. (2) (a) The sand crab is quite possibly also not in range. If you're not currently fighting the sand crab, somebody else probably is. How far away are the sand crabs you're trying to interact with? My guess is that they're reasonably far, or not easily visible. (b) Similarly, Sand crabs aren't actually NPCs until you turn them agro by standing beside them. You'll only attack a sand crab if it's already up and around. (3) You sleep for up to an entire minute in between even checking the actions, totally tossing aside actually doing them. return random(3000, 60000); Make this wayyyy less. There are very few scenarios where it would actually make sense to have a gap this big, and this is not one of them. (4) Please look into a state-based system. There are quite a few tutorials on it in the tutorials section. It'll make the code a lot easier to follow when you/others debug. Similarly, revise your variable names if you want others to be able to read your code. I don't know what CT, RSA, or BT are. Side note: This should reset agro anytime there isn't an active sand crab around you, given you have >= 35% HP, and have Salmon/are in some area CT. Edited September 14, 2020 by Team Cape 1 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted September 15, 2020 Share Posted September 15, 2020 return random(3000, 60000); This let you wait between 3 to 60 sec every loop. Might wanna lower that ^^ Quote Link to comment Share on other sites More sharing options...
hellcatz Posted September 15, 2020 Author Share Posted September 15, 2020 thanks for the reply`s i scrapt it and restarted it with state`s 1 Quote Link to comment Share on other sites More sharing options...