I'm writing my first script which is for fishing and I'm wondering if there are any classes/methods in the api that can provide blocking events? If you have no clue what I'm talking about take for example this code
@Override
public void forceState(Script script) throws Exception {
/** Move toward wherever the bank is. */
script.setRunning(true);
FishingScript.getBankLocation().getPosition().walkMinimap(script.myPlayer().getBot());
/** Get the nearest bank and open it. */
RS2Object object = script.closestObject(FishingScript.getBankLocation().getObjectId());
object.interact("Bank");
/** Deposit all items except for the fishing tools. */
script.myPlayer().getClient().getBank().depositAllExcept(FishingScript.getFishingType().getBankException());
}
if I tried to execute that all at once the script would try and click the bank before I was even at the position, deposit the items before the bank was even opened, etc. etc.
so I was wondering if there are any functions that serve a purpose like this, where the thread would block until the operation was completed?
@Override
public void forceState(Script script) throws Exception {
/** Move toward wherever the bank is. */
new BlockingEvent() {
@Override
public boolean blockUntil() {
return !script.myPlayer().isMoving();
}
@Override
public void run() {
script.setRunning(true);
FishingScript.getBankLocation().getPosition().walkMinimap(script.myPlayer().getBot());
}
}.start();
/** Get the nearest bank and open it. */
new BlockingEvent() {
@Override
public boolean blockUntil() {
return !script.myPlayer().getClient().getBank().isOpen();
}
@Override
public void run() {
script.setRunning(true);
FishingScript.getBankLocation().getPosition().walkMinimap(script.myPlayer().getBot());
}
}.start();
/** Deposit all items except for the fishing tools. */
new BlockingEvent() {
@Override
public boolean blockUntil() {
return !script.myPlayer().getClient().getInventory().isFull();
}
@Override
public void run() {
script.myPlayer().getClient().getBank().depositAllExcept(FishingScript.getFishingType().getBankException());
}
}.start();
}
I have no problem designing something myself if needed, this is my first script so I have no clue if that's even how its supossed to be done. If anyone more experienced can point me in the right direction that would be cool.
thanks