jonis5s 0 Posted July 30, 2018 So I just started scripting for fun, and I got a problem with my script. I am trying to make a cowhide looter just to learn the api. When the script is trying to pick up a cowhide, sometimes it doesn't seem to realise that the cowhide isn't there anymore, so it just right clicks where the cowhide was before and then loops like this like 3-5 times. This happens probably about one in three times, and it bothers me. This is the code that I made for looting: case loot: log("looting cowhide"); GroundItem cowhide = getGroundItems().closest("Cowhide"); if (cowhide != null){ cowhide.interact("Take"); } sleepWhile(() -> getLocalPlayer().isMoving(), 30000); break; What am I doing wrong? Because it's around midnight for me, and I got work tomorrow, I'll hit the bed and check in for answers tomorrow
Eclipseop 194 Posted July 31, 2018 49 minutes ago, Volta said: if (cowhide != null && cowhide.exists()){ cowhide.interact("Take"); } y the double null check. that is all exists does xd
jonis5s 0 Author Posted July 31, 2018 5 hours ago, Volta said: if (cowhide != null && cowhide.exists()){ cowhide.interact("Take"); } I tried that, but found that it did the same thing.
Articron 746 Posted July 31, 2018 Interact is a boolean in itself too, try this: if (cowhide != null && cowhide.interact("Take") { MethodProvider.sleepUntil(() -> !cowhide.exists(), 2000); }
Pengu 23 Posted July 31, 2018 I would suggest rather using a sleepUntil. Your timeout on ur sleep is also 30 seconds which is unnecessary in this case. Try this: GroundItem cowhide = getGroundItems().closest("Cowhide"); if (cowhide != null) { cowhide.interact("Take"); sleepUntil(() -> !cowhide.exists(), 3000); }
jonis5s 0 Author Posted July 31, 2018 13 hours ago, Articron said: Interact is a boolean in itself too, try this: if (cowhide != null && cowhide.interact("Take") { MethodProvider.sleepUntil(() -> !cowhide.exists(), 2000); } That really did the trick, thank you!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.