edoggydogg Posted October 23, 2014 Share Posted October 23, 2014 (edited) Got the assistance I needed thanks to Czar, really helpful guy. Edited October 24, 2014 by edoggydogg Link to comment Share on other sites More sharing options...
Czar Posted October 23, 2014 Share Posted October 23, 2014 (edited) import java.awt.Graphics2D; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.ui.EquipmentSlot; @ScriptManifest(author = "edoggydogg", info = "Welcome to my very first script!", logo = "", name = "eIron", version = 0.1) public class main extends Script { Position GOODAREA = new Position(random(3683, 3686), random(3478, 3480), 0); Position BANKAREA = new Position(random(3687, 3690), random(3466, 3469), 0); // code used on start public void onStart() { log("Welcome to eIron."); log("Please begin the script in Port P. Bank"); log("If any problems occur, please report them to me."); camera.toTop(); camera.moveYaw(random(1, 5)); } private enum state { BADAREA, GOODAREA, SMELT, WAIT, BANKAREA, BANK }; public state getState() { if (inventory.isEmpty()) return state.BANK; if (inventory.onlyContains(2351)) return state.BANK; if (inventory.onlyContains(440)) return state.SMELT; return state.BANK; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case SMELT: localWalker.walk(GOODAREA); if (inventory.onlyContains(440)) { objects.closest(24009).interact("Smelt"); sleep(random(1000, 2000)); mouse.move(random(130, 170), random(400, 440)); mouse.click(random(130, 170), random(400, 440), true); sleep(random(1000, 2000)); mouse.move(random(130, 170), random(471, 480)); mouse.click(random(130, 170), random(471, 480), false); sleep(random(1000, 2000)); keyboard.typeString("99", true); mouse.moveOutsideScreen(); sleep(random(85000, 88000)); } break; case BANK: localWalker.walk(BANKAREA); if (inventory.isEmpty()) { if (equipment.isWearingItem(EquipmentSlot.RING)) { objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); } else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22 objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.withdraw(2568, 1); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); equipment.equip(EquipmentSlot.RING, 2568); sleep(random(1500, 2000)); } } else { if (equipment.isWearingItem(EquipmentSlot.RING)) { objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.depositAll(); sleep(random(1500, 2000)); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); } else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22 objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.depositAll(); sleep(random(1500, 2000)); bank.withdraw(2568, 1); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); equipment.equip(EquipmentSlot.RING, 2568); sleep(random(1500, 2000)); } } break; case WAIT: sleep(random(200, 300)); break; default: break; } return random(200, 300); } // code used on exit public void onExit() { log("Thank you for using eIron"); } // paint public void onPaint(Graphics2D g) { } } Added code is in green. You forgot to make it only withdraw a ring if it doesn't have one. Your code was saying: if you're wearing ring, bank for ore. Then, bank for ring (without even checking if has ring or not). I made it so it will check if it has ring, then withdraw ore, if not, withdraw ring.Sorry if I didn't explain myself well enough, if you need any more help just ask. EDIT: Make sure to format your code! It was confusing at first, but just hit CTRL + SHIFT + F to automatically format code in Eclipse IDE. Edited October 23, 2014 by Czar Link to comment Share on other sites More sharing options...
Isolate Posted October 23, 2014 Share Posted October 23, 2014 Did osbot loose the ability to interact with widgets?+ the lack of checks is intense Link to comment Share on other sites More sharing options...
edoggydogg Posted October 23, 2014 Author Share Posted October 23, 2014 import java.awt.Graphics2D; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.ui.EquipmentSlot; @ScriptManifest(author = "edoggydogg", info = "Welcome to my very first script!", logo = "", name = "eIron", version = 0.1) public class main extends Script { Position GOODAREA = new Position(random(3683, 3686), random(3478, 3480), 0); Position BANKAREA = new Position(random(3687, 3690), random(3466, 3469), 0); // code used on start public void onStart() { log("Welcome to eIron."); log("Please begin the script in Port P. Bank"); log("If any problems occur, please report them to me."); camera.toTop(); camera.moveYaw(random(1, 5)); } private enum state { BADAREA, GOODAREA, SMELT, WAIT, BANKAREA, BANK }; public state getState() { if (inventory.isEmpty()) return state.BANK; if (inventory.onlyContains(2351)) return state.BANK; if (inventory.onlyContains(440)) return state.SMELT; return state.BANK; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case SMELT: localWalker.walk(GOODAREA); if (inventory.onlyContains(440)) { objects.closest(24009).interact("Smelt"); sleep(random(1000, 2000)); mouse.move(random(130, 170), random(400, 440)); mouse.click(random(130, 170), random(400, 440), true); sleep(random(1000, 2000)); mouse.move(random(130, 170), random(471, 480)); mouse.click(random(130, 170), random(471, 480), false); sleep(random(1000, 2000)); keyboard.typeString("99", true); mouse.moveOutsideScreen(); sleep(random(85000, 88000)); } break; case BANK: localWalker.walk(BANKAREA); if (inventory.isEmpty()) { if (equipment.isWearingItem(EquipmentSlot.RING)) { objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); } else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22 objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.withdraw(2568, 1); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); equipment.equip(EquipmentSlot.RING, 2568); sleep(random(1500, 2000)); } } else { if (equipment.isWearingItem(EquipmentSlot.RING)) { objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.depositAll(); sleep(random(1500, 2000)); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); } else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22 objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.depositAll(); sleep(random(1500, 2000)); bank.withdraw(2568, 1); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); equipment.equip(EquipmentSlot.RING, 2568); sleep(random(1500, 2000)); } } break; case WAIT: sleep(random(200, 300)); break; default: break; } return random(200, 300); } // code used on exit public void onExit() { log("Thank you for using eIron"); } // paint public void onPaint(Graphics2D g) { } } Added code is in green. You forgot to make it only withdraw a ring if it doesn't have one. Your code was saying: if you're wearing ring, bank for ore. Then, bank for ring (without even checking if has ring or not). I made it so it will check if it has ring, then withdraw ore, if not, withdraw ring.Sorry if I didn't explain myself well enough, if you need any more help just ask. EDIT: Make sure to format your code! It was confusing at first, but just hit CTRL + SHIFT + F to automatically format code in Eclipse IDE. Yeah I completely understand, I had the else statement in there before but it caused an error i forgot what exactly and i guess i forgot to put it back in, but thank you! Link to comment Share on other sites More sharing options...
Czar Posted October 23, 2014 Share Posted October 23, 2014 Does it work well, if not just pm me. Link to comment Share on other sites More sharing options...
Joseph Posted October 23, 2014 Share Posted October 23, 2014 (edited) Did osbot loose the ability to interact with widgets? + the lack of checks is intense Naw chill we still can, they innovated it. They created an interaction event class that allows us to interact with almost anything entity, interfaces, and others Edited October 23, 2014 by josedpay Link to comment Share on other sites More sharing options...
blakeblood9 Posted October 24, 2014 Share Posted October 24, 2014 Goodluck writing Link to comment Share on other sites More sharing options...
NotoriousPP Posted October 24, 2014 Share Posted October 24, 2014 } else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22 objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.depositAll(); sleep(random(1500, 2000)); bank.withdraw(2568, 1); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); equipment.equip(EquipmentSlot.RING, 2568); sleep(random(1500, 2000)); Is this real life? Please tell me you didn't go through with using this.... No I will no provide anything helpful because everything you do here should be obvious for ANYONE who spent a small amount of time actually learning Java instead of thinking "Hey I want be popular, so I should start writing scripts.", so please do everyone a favor and start reading. I even took the first step for you: http://www.ibm.com/developerworks/java/tutorials/j-introtojava1/ 1 Link to comment Share on other sites More sharing options...
Czar Posted October 24, 2014 Share Posted October 24, 2014 } else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22 objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.depositAll(); sleep(random(1500, 2000)); bank.withdraw(2568, 1); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); equipment.equip(EquipmentSlot.RING, 2568); sleep(random(1500, 2000)); Is this real life? Please tell me you didn't go through with using this.... No I will no provide anything helpful because everything you do here should be obvious for ANYONE who spent a small amount of time actually learning Java instead of thinking "Hey I want be popular, so I should start writing scripts.", so please do everyone a favor and start reading. I even took the first step for you: http://www.ibm.com/developerworks/java/tutorials/j-introtojava1/ Lool, nah we improved it Link to comment Share on other sites More sharing options...
FrostBug Posted October 24, 2014 Share Posted October 24, 2014 (edited) Oh wow, that is the most unstable code I have ever seen :E. I don't even know where to start 1. NEVER assume that an interaction or any other type of event will complete successfully. Edited October 24, 2014 by FrostBug Link to comment Share on other sites More sharing options...
edoggydogg Posted October 24, 2014 Author Share Posted October 24, 2014 } else { // ADDED THIS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22 objects.closest(16642).interact("Bank"); sleep(random(1500, 2000)); bank.depositAll(); sleep(random(1500, 2000)); bank.withdraw(2568, 1); bank.withdrawAll(440); sleep(random(1500, 2000)); bank.close(); sleep(random(1500, 2000)); equipment.equip(EquipmentSlot.RING, 2568); sleep(random(1500, 2000)); Is this real life? Please tell me you didn't go through with using this.... No I will no provide anything helpful because everything you do here should be obvious for ANYONE who spent a small amount of time actually learning Java instead of thinking "Hey I want be popular, so I should start writing scripts.", so please do everyone a favor and start reading. I even took the first step for you: http://www.ibm.com/developerworks/java/tutorials/j-introtojava1/ Clearly you failed to read the first post where I stated I already am getting assistance. You assume I want to be "popular" on an online forum because I am trying to write my own script. Hmm thats great logic. It was a waste of both your time and my time for you to write a comment like you did. Enjoy your popularity on these forums haha, this was just meant as a side project for myself. Link to comment Share on other sites More sharing options...
FrostBug Posted October 24, 2014 Share Posted October 24, 2014 Seriously though. If you want your script be to be stable, always assume that any action has a chance to fail. As a result of this, doing multiple things successively without checking what the current situation is, is generally a bad idea. Example (pseudo): bank.open(); sleep bank.withdraw(); Assume that even after the call to bank.open(), the bank is still not open. An action can fail as a result of multiple factors. Most often being misclicks (caused by camera movements or whatnot), random event interrupt (Yes, they still interrupt your current action), lag or delays. For this reason, it's common practice to return from the main loop after every action, repeating the same action if it was not completed successfully in the previous loop. Link to comment Share on other sites More sharing options...
edoggydogg Posted October 24, 2014 Author Share Posted October 24, 2014 Seriously though. If you want your script be to be stable, always assume that any action has a chance to fail. As a result of this, doing multiple things successively without checking what the current situation is, is generally a bad idea. Example (pseudo): bank.open(); sleep bank.withdraw(); Assume that even after the call to bank.open(), the bank is still not open. An action can fail as a result of multiple factors. Most often being misclicks (caused by camera movements or whatnot), random event interrupt (Yes, they still interrupt your current action), lag or delays. For this reason, it's common practice to return from the main loop after every action, repeating the same action if it was not completed successfully in the previous loop. Yea I understand I will make sure to go back and include checks for those kinds of things and I will keep working on the script. The code that was posted above was put together after maybe an hour of work, it was my first time scripting so thank you for the suggestion and help! Link to comment Share on other sites More sharing options...