futurepasts Posted August 3, 2015 Share Posted August 3, 2015 (edited) So i try and try to make my scripts working but i always fail I tried to make simple bronze bar smelter but it doesnt really works maybe sombody can point me to right direction what im doing wrong? What my script does is just simply spam click Furnace and doesn't move to other CASE: For example if i put all my CASES: to onstart it works like a charm and when im put it back to onLoop it just spam clicks. Script is not finished since i want to test if it smelt My tutorial sources:https://www.youtube.com/watch?v=Mdil7v1J5es (Helped to understand basics even if its old) https://www.youtube.com/watch?v=0mIWSUHXB9c (Helped to understand widgets tutorials is old too) Also i readed Apeac and Pandemic tutorials to understand even better And 2nd Question(So i dont need to create another thread) Example: I have case Click(it clicks continue after im leveled up) But after that how do i check if im still have left something to smelt I was thinking something like this: if(inventory.getAmount("Bronze bar") > 14 ) return State.SMELT package main; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(name = "SmelterBronze", author = "Futurepasts", version = 1.0, info = "", logo = "") public class main extends Script { private enum State { USE, BANK, WALK_TO_BANK, WALK_TO_FURNACE, OPEN_FURNACE, SMELT, CLICK; }; Area SMELT_AREA = new Area( new Position(3279,3187,0), new Position(3273,3184,0)); Area BANK_AREA = new Area( new Position(3270,3161,0), new Position(3271,3170,0)); Position[] pathtofurnace = new Position[] { new Position(3269,3169,0), new Position(3277,3175,0), new Position(3280,3184,0),}; Position[] pathtobank = new Position[] { new Position(3274,3186,0), new Position(3280,3183,0), new Position(3280,3175,0), new Position(3278,3173,0), new Position(3272,3166,0), new Position(3269,3166,0),}; private State getState() { Entity furnace = objects.closest("Furnace"); if(furnace != null && SMELT_AREA.contains(myPlayer())) return State.USE; if (widgets.get(311,4) != null) return State.SMELT; if (!inventory.contains("Tin ore") && SMELT_AREA.contains(myPlayer())) return State.WALK_TO_BANK; if (inventory.contains("Tin ore") && inventory.contains("Copper ore") && BANK_AREA.contains(myPlayer())) return State.WALK_TO_FURNACE; if (!inventory.contains("Tin ore") && inventory.contains("Copper ore") && BANK_AREA.contains(myPlayer())) return State.BANK; if (widgets.get(193,3) != null) return State.CLICK; return State.OPEN_FURNACE; } @Override public void onStart() { } @Override public void onExit() { //Code here will execute after the script ends } @Override public int onLoop() throws InterruptedException { switch (getState()) { case USE: if (!myPlayer().isAnimating()) { Entity furnace = objects.closest("Furnace"); if(furnace != null){ if(furnace.isVisible()){ furnace.interact("Smelt"); } } } break; case SMELT: RS2Widget options = widgets.get(311,4); if (options != null) { options.interact("Smelt X Bronze"); log("Typing number"); sleep(gRandom(1200, 500)); RS2Widget smelter = widgets.get(162,33); keyboard.typeString("" + random(29,99), true); } sleep(100); break; case CLICK: if(dialogues.isPendingContinuation()) { dialogues.clickContinue(); } break; } return 100; //The amount of time in milliseconds before the loop starts over } @Override public void onPaint(Graphics2D g) { //This is where you will put your code for paint(s) } } Edited August 3, 2015 by futurepasts Quote Link to comment Share on other sites More sharing options...
Apaec Posted August 3, 2015 Share Posted August 3, 2015 a script reads like a book - from start to finish. the reason it's always spamming the furnace is because it's getting the use state returned every time because the criteria are always matched. Either try to be more precise with how you define the case, or move the definition of the case a bit further down the list. apa also, press ctrl+shift+f frequently (if you're using eclipse IDE) - this formats the code making it easier to read. Quote Link to comment Share on other sites More sharing options...
futurepasts Posted August 3, 2015 Author Share Posted August 3, 2015 Well i cant be even more precise because i dont know what to write else even if i add if invenotry contains tin and copper it still do same shit 1 Quote Link to comment Share on other sites More sharing options...
Chris Posted August 3, 2015 Share Posted August 3, 2015 (edited) try to keep it somewhat clean. for example (Credit to Isolate) State getState() { if (skills.getStatic(Skill.THIEVING) >= 5) { if (TEA_STALL_AREA.contains(myPlayer())) { if (inventory.contains("Cup of tea")) { return State.DROP; } else { return State.STEAL; } }else{ return State.WALK_STALL; } }else{ return State.POCKET; } and have functions private void Pick() throws InterruptedException { NPC npc = npcs.closest("Man"); if (npc != null){ if (npc.exists() && (!myPlayer().isAnimating()) && npc.isOnScreen()){ Status = "Interacting: Pickpocket"; npc.interact("Pickpocket"); sleep(random(300,600)); }else{ camera.toEntity(npc); } } } case POCKET: Status = "IDLE"; Pick(); break; Edited August 3, 2015 by Sinatra Quote Link to comment Share on other sites More sharing options...