So I'm having issues with world hopping, It seems it still tries to hop to p2p worlds even though I've given it set worlds to hop to and basically at this point it just causes the script to break.
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;
import com.sun.glass.events.KeyEvent;
import java.awt.*;
import java.util.Random;
@ScriptManifest(name = "Rune Pack Buyer", author = "01053", version = 1.0, info = "", logo = "")
public class Shopping extends Script {
public Timer timer;
private long buyDelay;
private State state;
private int npcId = 637;
private int packId = 12732;
private int buying;
private int[] worlds = {
1, 8, 16, 26, 35, 82, 83, 84, 93, 94
};
Random random = new Random();
public enum State {
TRADING, BUYING, OPENING
}
public State getState() {
if (!getStore().isOpen() && buying <= 0) {
return State.TRADING;
}
if (getStore().isOpen()) {
return State.BUYING;
}
if (!getStore().isOpen() && getInventory().contains(packId) && buying > 0) {
return State.OPENING;
}
return State.TRADING;
}
private boolean hop;
public void execute() throws InterruptedException {
state = getState();
switch (state) {
case TRADING:
/*if (getStore().getAmount(packId) <= 57) {
int randomWorld = random.nextInt(worlds.length);
getWorlds().hop(randomWorld);
buying = 0;
hop = false;
}*/
NPC npc = (NPC) getNpcs().closest(npcId);
if (npc != null) {
if (npc.interact(new String[] { "Trade" })) {
log("Trading shopkeeper");
new ConditionalSleep(5500, 6000) {
public boolean condition() throws InterruptedException {
return getStore().isOpen();
}
}.sleep();
}
}
break;
case BUYING:
if (System.currentTimeMillis() - buyDelay < 1000) {
return;
}
if (getStore().getAmount(12732) <= 57 && !getInventory().contains(12732)) {
int randomWorld = random.nextInt(worlds.length);
getWorlds().hop(randomWorld);
buying = 0;
hop = false;
}
if (getInventory().isFull()) {
getKeyboard().pressKey(KeyEvent.VK_ESCAPE);
buying++;
}
Item rune = getStore().getItem(packId);
if ((rune != null) && (getStore().getAmount(packId) > 54)) {
getStore().buy(packId, 10);
log("Buying Rune Packs");
hop = false;
buyDelay = System.currentTimeMillis();
}
break;
case OPENING:
if (hop && getStore().getAmount(12732) <= 57 && !getInventory().contains(12732)) {
int randomWorld = random.nextInt(worlds.length);
getWorlds().hop(randomWorld);
buying = 0;
hop = false;
}
if (getInventory().contains(packId) && !getTabs().open(Tab.INVENTORY)) {
getKeyboard().pressKey(KeyEvent.VK_F1);
}
for (int i = 1; i < 28; i++) {
getMouse().click(getInventory().getMouseDestination(i + 1));
hop = true;
}
break;
}
}
@[member='Override']
public void onStart() {
timer = new Timer(0L);
log("Rune Pack BUYING Script Initiating.");
}
@[member='Override']
public int onLoop() throws InterruptedException {
execute();
return 100;
}
Color color = new Color(0, 0, 0, 85);
@[member='Override']
public void onPaint(Graphics2D gr) {
gr.setColor(this.color);
gr.fillRect(56, 355, 198, 100);
gr.setColor(Color.GREEN);
gr.setFont(new Font("Ariel", 0, 20));
gr.drawString("Script by: 01053", 75, 436);
gr.setFont(new Font("Ariel", 0, 14));
gr.drawString("Time Elapsed: " + Timer.format(timer.getElapsed()), 61, 372);
gr.drawString("State: " + getState(), 62, 397);
gr.setColor(Color.BLACK);
}
}