HastyLife Posted November 13, 2016 Posted November 13, 2016 Heya I just wanted to ask how I could make it that my Player does stop if he interact with the Rock (mining) I could put sleeping on like 10 secs but I want to that he not waits 10 sec even he mined the rock after 2 secs. import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Someone", info = "Testing", name = "Mining Test", logo = "", version = 0) public class main extends Script { @@Override public void onStart() { log("Shitty test"); } private enum State { MINE, DROP, WAIT }; private State getState() throws InterruptedException { Entity stall = objects.closest("Rocks"); inventory.dropAllExcept(1265); sleep(random(1000)); if (stall != null) return State.MINE; return State.WAIT; } @@Override public int onLoop() throws InterruptedException { switch (getState()) { case MINE: Entity stall = objects.closest("Rocks"); if (stall != null) { stall.interact("Mine"); } break; case DROP: inventory.dropAll(); break; case WAIT: sleep(random(500, 700)); break; } return random(200, 300); } @@Override public void onExit() { log("Test more"); } @@Override public void onPaint(Graphics2D g) { } } Thanks for any help. ~Life
Vilius Posted November 13, 2016 Posted November 13, 2016 case MINE: Entity stall = objects.closest("Rocks"); if (stall != null && !myPlayer().isAnimating()) { stall.interact("Mine"); } break; Replace your current mine state with my version. 1
HastyLife Posted November 13, 2016 Author Posted November 13, 2016 case MINE: Entity stall = objects.closest("Rocks"); if (stall != null && !myPlayer().isAnimating()) { stall.interact("Mine"); } break; Replace your current mine state with my version. Tyvm saved my day
PlagueDoctor Posted November 13, 2016 Posted November 13, 2016 Vilius answered your question really well, but as a side note, you might want to have a look into condition sleeping. It can be very useful. For instance, say you want to drop everything except for a certain ore, you could write: if(inventory.isFull()) { inventory.dropAllExcept(2958); new ConditionalSleep(10000) { @[member=Override] public boolean condition() throws InterruptedException { return inventory.onlyContains(2958); } }.sleep(); } This would, if your inventory is full, drop everything except for item ID 2958, and sleep until your inventory only contains item ID 2958. If after 10000 ms your inventory still does not only contain 2958 (if the script failed to drop something for some reason), it will repeat, trying to drop everything and sleeping until the condition of "inventory.onlyContains(2958)" is met. 1
HastyLife Posted November 13, 2016 Author Posted November 13, 2016 Vilius answered your question really well, but as a side note, you might want to have a look into condition sleeping. It can be very useful. For instance, say you want to drop everything except for a certain ore, you could write: if(inventory.isFull()) { inventory.dropAllExcept(2958); new ConditionalSleep(10000) { @[member='Override'] public boolean condition() throws InterruptedException { return inventory.onlyContains(2958); } }.sleep(); } This would, if your inventory is full, drop everything except for item ID 2958, and sleep until your inventory only contains item ID 2958. If after 10000 ms your inventory still does not only contain 2958 (if the script failed to drop something for some reason), it will repeat, trying to drop everything and sleeping until the condition of "inventory.onlyContains(2958)" is met. Okay cool I understand thanks!