whipz Posted January 17, 2017 Share Posted January 17, 2017 (edited) Hey guys; Sorry to keep posting new threads this will be the last thread; I thought I might as well post it all so everyone can learn as there isnt to many open source scripts; I will keep this one open source but will not be adding anything else to the script as I just wanted to learn a few features for other scripts I want to release to the community; I mainly made this script to test my cooking script which is finished I just have nothing to cook with lol. Its an AIO that supports lumby falador edgeville and alkharid which will also be released on SDN as soon as i can finish testing it; which is why i need this script finished lol Everything works now; So mainly looking for feedback on how to improve this script; I will add a GUI within the day or so ! As i said this script will remain open source and free obviously as its open source ! Going over the script in the next few days to add comments to make it easier for someone to learn off; here is the code so far: import org.osbot.rs07.api.Bank; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "Whipz", info = "Picks up Beef and trades to a Mule", logo = "", name = "BeefMule", version = 0.1) public class main extends Script { Area cowArea = new Area( new int[][]{ { 3253, 3255 }, { 3265, 3255 }, { 3265, 3296 }, { 3263, 3298 }, { 3260, 3299 }, { 3257, 3299 }, { 3256, 3298 }, { 3241, 3298 }, { 3240, 3296 }, { 3241, 3295 }, { 3241, 3294 }, { 3242, 3293 }, { 3242, 3292 }, { 3242, 3290 }, { 3242, 3288 }, { 3241, 3287 }, { 3241, 3286 }, { 3241, 3284 }, { 3242, 3283 }, { 3243, 3282 }, { 3244, 3281 }, { 3245, 3280 }, { 3246, 3278 }, { 3247, 3278 }, { 3248, 3278 }, { 3249, 3278 }, { 3250, 3278 }, { 3251, 3276 }, { 3253, 3272 } } ); Area muleArea = new Area(3265, 3173, 3272, 3161); private enum State { PICKUP, WALKTOMULE, TRADE, WALKTOPICKUP, BANK, STOP, WAIT }; private State getState() { if (!inventory.isFull() && cowArea.contains(myPlayer())) return State.PICKUP; if (inventory.isFull() && !muleArea.contains(myPlayer())) return State.WALKTOMULE; if(inventory.contains(2132, 1739) || bank.contains("Raw beef", "Cowhide") && muleArea.contains(myPlayer())) return State.BANK; if(inventory.contains(2133, 1740) || trade.isCurrentlyTrading() && muleArea.contains(myPlayer())) return State.TRADE; if (!inventory.isFull() && !bank.isOpen() && !bank.contains("Raw beef") && !cowArea.contains(myPlayer())) return State.WALKTOPICKUP; return State.WAIT; } public void onStart() throws InterruptedException { } public void onExit() { log("Thanks for using beefMule"); } @[member=Override] public int onLoop() throws InterruptedException { switch (getState()) { case PICKUP: doPickUp(); break; case WALKTOMULE: getWalking().webWalk(muleArea); break; case BANK: getNotedItems(); break; case TRADE: tradeMule(); offerItems(); acceptTrade1(); acceptTrade2(); break; case WALKTOPICKUP: getWalking().webWalk(cowArea); break; case STOP: this.stop(); break; case WAIT: sleep(random(200, 300)); break; } return random(200, 300); } private void doPickUp() throws InterruptedException { GroundItem loot = getGroundItems().closest("Raw beef", "Cowhide"); if (!inventory.isFull() && cowArea.contains(myPlayer()) && (loot != null) && !myPlayer().isAnimating()) { loot.interact("Take"); log("Picking up Raw Beef"); sleep(random(750, 1500)); new ConditionalSleep(5000) { @[member=Override] public boolean condition() throws InterruptedException { return !myPlayer().isMoving(); } }.sleep(); } } private void tradeMule() throws InterruptedException { @SuppressWarnings("unchecked") Player muleAccount = getPlayers().closest(o -> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase("FlippingGold")); if (muleAccount != null && muleAccount.isVisible() && muleArea.contains(myPlayer()) && inventory.contains("Raw beef")) { log("Trying to trade mule"); if(muleAccount.interact("Trade with")){ log("Waiting for other player to accept trade"); } sleep(random(750, 1500)); new ConditionalSleep(5000) { @[member=Override] public boolean condition() throws InterruptedException { return trade.isFirstInterfaceOpen(); } }.sleep(); } } private void offerItems() throws InterruptedException { if(trade.isFirstInterfaceOpen() && trade.isCurrentlyTrading()) { log("Offering Loot"); getInventory().getItem("Raw beef").interact("Offer-All"); getInventory().getItem("Cowhide").interact("Offer-All"); sleep(random(750, 1500)); new ConditionalSleep(5000) { @[member=Override] public boolean condition() throws InterruptedException { return trade.getOurOffers().toString() == "Raw beef"; } }.sleep(); } } private void acceptTrade1() throws InterruptedException { if(trade.isFirstInterfaceOpen()) { trade.acceptTrade(); new ConditionalSleep(5000) { @[member=Override] public boolean condition() throws InterruptedException { return trade.isSecondInterfaceOpen(); } }.sleep(); } } private void acceptTrade2() { if(trade.isSecondInterfaceOpen()) { trade.acceptTrade(); new ConditionalSleep(5000) { @[member=Override] public boolean condition() throws InterruptedException { return !trade.isCurrentlyTrading(); } }.sleep(); } } private void getNotedItems() throws InterruptedException { NPC closestBanker = getNpcs().closest("Banker"); Entity closestBankBooth = objects.closest("Bank Booth"); if (bank.isOpen()) { if(inventory.isEmpty()) { if (getBank().getWithdrawMode().equals( Bank.BankMode.WITHDRAW_NOTE)) { getBank().withdrawAll("Raw beef"); getBank().withdrawAll("Cowhide"); sleep(random(750, 1500)); bank.close(); log("Withdrawing Noted Beef"); sleep(random(750, 1500)); } else { bank.enableMode(Bank.BankMode.WITHDRAW_NOTE); log("changing to withdraw note mode"); sleep(random(750, 1500)); } } else { bank.depositAll(); } sleep(random(1000, 2500)); } else { int rand = random(3); if (rand == 1) { closestBankBooth.interact("Bank"); log("Using Bank Booth"); sleep(random(750, 1500)); } else { closestBanker.interact("Bank"); log("Using NPC Banker"); sleep(random(750, 1500)); } sleep(random(1000, 2500)); log("Opening Bank"); } } } So any help is appreciated thanks to everyone who has helped so far; Edited January 18, 2017 by whipz 1 Quote Link to comment Share on other sites More sharing options...
Rudie Posted January 17, 2017 Share Posted January 17, 2017 (edited) case TRADE: getNotedItems(); if(inventory.isEmpty()) { if (getBank().getWithdrawMode().equals( Bank.BankMode.WITHDRAW_NOTE)) { getBank().withdrawAll("Raw beef"); sleep(random(750, 1500)); bank.close(); log("Withdrawing Noted Beef"); sleep(random(750, 1500)); } else { bank.enableMode(Bank.BankMode.WITHDRAW_NOTE); log("changing to withdraw note mode"); sleep(random(750, 1500)); } } else { bank.depositAll(); } } else { bank.depositAll(); } Edited January 17, 2017 by Rudie 1 Quote Link to comment Share on other sites More sharing options...
Shit Posted January 17, 2017 Share Posted January 17, 2017 when scripting is life ;;;;;;;;;;;;;;;; Quote Link to comment Share on other sites More sharing options...
whipz Posted January 17, 2017 Author Share Posted January 17, 2017 case TRADE: getNotedItems(); if(inventory.isEmpty()) { if (getBank().getWithdrawMode().equals( Bank.BankMode.WITHDRAW_NOTE)) { getBank().withdrawAll("Raw beef"); sleep(random(750, 1500)); bank.close(); log("Withdrawing Noted Beef"); sleep(random(750, 1500)); } else { bank.enableMode(Bank.BankMode.WITHDRAW_NOTE); log("changing to withdraw note mode"); sleep(random(750, 1500)); } } else { bank.depositAll(); } } else { bank.depositAll(); } Doing what you suggested I will update in the morning misses is angry I have been on computer to much today hahaha night guys keep you updated tomorrow 2 Quote Link to comment Share on other sites More sharing options...
Hayase Posted January 17, 2017 Share Posted January 17, 2017 Something to note about your mule bit is that you are using Entity and grabbing the player as if it were an NPC. If you want to follow the standards you can just use the Player class like so: //The replaceAll method will let you use names with spaces in them. Jagex does not use normal spaces. Player mule = getPlayers().closest(o -> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase(/*Mule Username*/)); //do null checks on mule and other things to see if the mule is in range to trade //Change "Trade" to "Trade with" if (mule.interact("Trade with")) { log("Waiting for other player to accept trade"); new ConditionalSleep(5000) { @[member=Override] public boolean condition() throws InterruptedException { return trade.isFirstInterfaceOpen(); } }.sleep(); } 1 Quote Link to comment Share on other sites More sharing options...
whipz Posted January 17, 2017 Author Share Posted January 17, 2017 Something to note about your mule bit is that you are using Entity and grabbing the player as if it were an NPC. If you want to follow the standards you can just use the Player class like so: //The replaceAll method will let you use names with spaces in them. Jagex does not use normal spaces. Player mule = getPlayers().closest(o -> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase(/*Mule Username*/)); //do null checks on mule and other things to see if the mule is in range to trade //Change "Trade" to "Trade with" if (mule.interact("Trade with")) { log("Waiting for other player to accept trade"); new ConditionalSleep(5000) { @[member='Override'] public boolean condition() throws InterruptedException { return trade.isFirstInterfaceOpen(); } }.sleep(); } OMG thanks mate; I have been looking for something like that for so long ! Thanks so much mate; Ill get on to adding that and ill update my top post; Like i keep saying this script will be permanently so people can learn; I will go threw and add //comments once its fully functional Something to note about your mule bit is that you are using Entity and grabbing the player as if it were an NPC. If you want to follow the standards you can just use the Player class like so: //The replaceAll method will let you use names with spaces in them. Jagex does not use normal spaces. Player mule = getPlayers().closest(o -> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase(/*Mule Username*/)); //do null checks on mule and other things to see if the mule is in range to trade //Change "Trade" to "Trade with" if (mule.interact("Trade with")) { log("Waiting for other player to accept trade"); new ConditionalSleep(5000) { @[member='Override'] public boolean condition() throws InterruptedException { return trade.isFirstInterfaceOpen(); } }.sleep(); } Hey mate; I am now getting this error ? o cannot be resolved to a variable Quote Link to comment Share on other sites More sharing options...
Hayase Posted January 17, 2017 Share Posted January 17, 2017 OMG thanks mate; I have been looking for something like that for so long ! Thanks so much mate; Ill get on to adding that and ill update my top post; Like i keep saying this script will be permanently so people can learn; I will go threw and add //comments once its fully functional Hey mate; I am now getting this error ? o cannot be resolved to a variable You are using Java 8 right? The one liner is just using Java 8 streams. Are you using an IDE? 1 Quote Link to comment Share on other sites More sharing options...
whipz Posted January 17, 2017 Author Share Posted January 17, 2017 You are using Java 8 right? The one liner is just using Java 8 streams. Are you using an IDE? yeah man eclipse; How can i tell what java eclipse is running ? as I need a lower lvl java for another application on my computer and it hasnt been updated; however i have both. EVERYONE QUICK THE MISSES IS COOKING HELP WHILE I HAVE 15 mins HAHAHAHAH *as she reads over my should cooking next to me hahaa Quote Link to comment Share on other sites More sharing options...
Hayase Posted January 17, 2017 Share Posted January 17, 2017 yeah man eclipse; How can i tell what java eclipse is running ? as I need a lower lvl java for another application on my computer and it hasnt been updated; however i have both. Maybe this will help? http://stackoverflow.com/questions/22619262/upgrade-eclipse-to-java-8?noredirect=1&lq=1 If you don't have Java 8, get it here http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 1 Quote Link to comment Share on other sites More sharing options...
whipz Posted January 17, 2017 Author Share Posted January 17, 2017 Maybe this will help? http://stackoverflow.com/questions/22619262/upgrade-eclipse-to-java-8?noredirect=1&lq=1 If you don't have Java 8, get it here http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html I did that but when I did it the way the guy at the top said It said I have 1.5 ? even though i did what was suggested by the guy underneath i still have the error? is it just better to get rid of all old javas ? Quote Link to comment Share on other sites More sharing options...
Explv Posted January 17, 2017 Share Posted January 17, 2017 I did that but when I did it the way the guy at the top said It said I have 1.5 ? even though i did what was suggested by the guy underneath i still have the error? is it just better to get rid of all old javas ? I don't use Eclipse but I believe that you need to set the compliance level to 1.8 under the compiler section in properties 1 Quote Link to comment Share on other sites More sharing options...
whipz Posted January 17, 2017 Author Share Posted January 17, 2017 (edited) I don't use Eclipse but I believe that you need to set the compliance level to 1.8 under the compiler section in properties I have uninstalled all other versions of java and jdk, and yet I still cant get 1.8 to work with my eclipse; is there another way ? if not looks like im going to have format -.- Player muleAccount = getPlayers().closest(o --> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase("Insert your UserName")); On this line still getting this error Multiple markers at this line - o cannot be resolved to a variable - o cannot be resolved - o cannot be resolved to a variable - o cannot be resolved Edited January 17, 2017 by whipz Quote Link to comment Share on other sites More sharing options...
Ayylmao420 Posted January 17, 2017 Share Posted January 17, 2017 I have uninstalled all other versions of java and jdk, and yet I still cant get 1.8 to work with my eclipse; is there another way ? if not looks like im going to have format -.- Player muleAccount = getPlayers().closest(o --> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase("Insert your UserName")); On this line still getting this error Multiple markers at this line - o cannot be resolved to a variable - o cannot be resolved - o cannot be resolved to a variable - o cannot be resolved -> instead of --> 1 Quote Link to comment Share on other sites More sharing options...
whipz Posted January 17, 2017 Author Share Posted January 17, 2017 -> instead of --> Player muleAccount = getPlayers().closest(o -> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase("Insert your UserName")); give this error Multiple markers at this line - o cannot be resolved - Syntax error on token "-", -- expected - o cannot be resolved - o cannot be resolved to a variable - o cannot be resolved to a variable any ideas ? Quote Link to comment Share on other sites More sharing options...
Ayylmao420 Posted January 18, 2017 Share Posted January 18, 2017 Player muleAccount = getPlayers().closest(o -> o.getName().replaceAll("\\u00a0", " ").equalsIgnoreCase("Insert your UserName")); give this error Multiple markers at this line - o cannot be resolved - Syntax error on token "-", -- expected - o cannot be resolved - o cannot be resolved to a variable - o cannot be resolved to a variable any ideas ? Seems like your eclipse doesn't use java 8. Uninstall your eclipse, download it from here; https://www.eclipse.org/downloads/download.php?file=/oomph/epp/neon/R2a/eclipse-inst-win64.exe Quote Link to comment Share on other sites More sharing options...