01053 Posted December 6, 2016 Share Posted December 6, 2016 (edited) 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); } } Edited December 7, 2016 by 01053 1 Quote Link to comment Share on other sites More sharing options...
Butters Posted December 6, 2016 Share Posted December 6, 2016 95% that you ripped this code Look here if (System.currentTimeMillis() - openDelay < 1000) { return; } Item pack = getInventory().getItem(12732); if ((pack != null)) { openDelay = System.currentTimeMillis(); pack.interact("Open"); opened++; log("" + opened); Quote Link to comment Share on other sites More sharing options...
01053 Posted December 6, 2016 Author Share Posted December 6, 2016 95% that you ripped this code Look here if (System.currentTimeMillis() - openDelay < 1000) { return; } Item pack = getInventory().getItem(12732); if ((pack != null)) { openDelay = System.currentTimeMillis(); pack.interact("Open"); opened++; log("" + opened); Lol if your talking about the openDelay I added that because it was spam clicking boxes and I didn't like it. so no that has nothing to do with it thank you though. Quote Link to comment Share on other sites More sharing options...
Acerd Posted December 6, 2016 Share Posted December 6, 2016 use #interactWithSlot or whatever it was called Quote Link to comment Share on other sites More sharing options...
01053 Posted December 6, 2016 Author Share Posted December 6, 2016 (edited) use #interactWithSlot or whatever it was called Thank you I'll look into it. If anyone needs to do this also: for (int i = 1; i < 28; i++) { getMouse().click(getInventory().getMouseDestination(i + 1)); } works probably a better way of doing it though but yeah. Edit: Edited op with a new question. Edited December 6, 2016 by 01053 Quote Link to comment Share on other sites More sharing options...
01053 Posted December 7, 2016 Author Share Posted December 7, 2016 Anyone? Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 7, 2016 Share Posted December 7, 2016 int randomWorld = random.nextInt(worlds.length); ???? 1 Quote Link to comment Share on other sites More sharing options...
01053 Posted December 7, 2016 Author Share Posted December 7, 2016 int randomWorld = random.nextInt(worlds.length); ???? It chooses a random index# from private int[] worlds = { 1, 8, 16, 26, 35, 82, 83, 84, 93, 94 }; And hops to whatever world it chooses I've also tried using the getWorlds().HopToF2PWorld(); function and that too sometimes goofs like as if it 'clicks' the world but doesn't hop and then it just sits there. Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 7, 2016 Share Posted December 7, 2016 (edited) It chooses a random index# from private int[] worlds = { 1, 8, 16, 26, 35, 82, 83, 84, 93, 94 }; And hops to whatever world it chooses I've also tried using the getWorlds().HopToF2PWorld(); function and that too sometimes goofs like as if it 'clicks' the world but doesn't hop and then it just sits there. you should probably take another look at the code m8. that wasnt me asking what the line does. that was me telling you theres a problem in that line lol. Edited December 7, 2016 by Imateamcape Quote Link to comment Share on other sites More sharing options...
01053 Posted December 7, 2016 Author Share Posted December 7, 2016 you should probably take another look at the code m8. that wasnt me asking what the line does. that was me telling you theres a problem in that line lol. After looking over it I found one issue not relevant to that code but care to explain? thanks int randomWorld = random.nextInt(worlds.length); getWorlds().hop(randomWorld); Should have been int randomWorld = random.nextInt(worlds.length); getWorlds().hop(worlds[randomWorld]); Was tired when I did this last night 1 Quote Link to comment Share on other sites More sharing options...