JS3 Posted April 26, 2018 Share Posted April 26, 2018 Hi Guys, I am new to scripting and have been learning through videos, threads and the OSbot scripting discord. Below is a script I have made for Barbarian Fishing, cooking and banking. import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(logo ="" , name ="Barbarian Fishing! xD" , version =1.0 , info ="Fish and Cook, Trout and Salmon. + Banking!" , author ="J$" ) public class Main extends Script { public final Area barbarianFish = new Area(3109, 3434, 3102, 3423); public final Area bankArea = new Area(3094, 3489, 3093, 3491); private final org.osbot.rs07.api.map.Position bankTeller = new org.osbot.rs07.api.map.Position(3094, 3491, 0); enum State { WALK_TO_FISH, WALK_TO_BANK, COOK_FISH, DEPOSIT, IDLE, FISH_FISH } @Override public void onStart() throws InterruptedException { } @Override public int onLoop() throws InterruptedException { switch (getState()){ case FISH_FISH: log("FISHING THE FISH"); NPC salmon = getNpcs().closest("Rod Fishing spot"); if (barbarianFish.contains(myPlayer())) { if (!myPlayer().isAnimating()) { if (salmon != null) { if (getMap().canReach(salmon)) { if (salmon.interact("Lure")) { log("Starting to fish."); getCamera().movePitch(67); getCamera().moveYaw(3); getMouse().moveOutsideScreen(); } } else { Sleep.sleepUntil(() -> myPlayer().isAnimating(), 3000); } } } } break; case COOK_FISH: log("COOKING FISH"); if (getInventory().contains("Raw trout", "Raw salmon") && getInventory().isFull()) { RS2Widget cookOpt = getWidgets().get(270, 14, 38); RS2Object fire = getObjects().closest("Fire"); if (fire != null) { if (!myPlayer().isAnimating()) { if (cookOpt != null) { cookOpt.interact("Cook"); getMouse().moveOutsideScreen(); } else { sleep(1000); if (!myPlayer().isAnimating()) { getInventory().interactWithNameThatContains("Use", "Raw salmon", "Raw trout"); fire.interact("Use"); } } } } } break; case WALK_TO_FISH: log("WALKING TO FISH"); getWalking().webWalk(barbarianFish); break; case WALK_TO_BANK: log("WALKING TO BANK"); getWalking().webWalk(bankArea); break; case DEPOSIT: log("DEPOSITING IN BANK"); if (bank.isOpen()){ bank.depositAllExcept("Fly fishing rod", "Feather"); } else { NPC bankBooth = getNpcs().closest("Banker"); if (bankBooth != null && bankBooth.interact("Bank")){ new ConditionalSleep(1000){ @Override public boolean condition(){ return bank.isOpen(); } }.sleep(); } } break; case IDLE: log("IDLING"); } return 700; } private State getState() { if (getInventory().isEmptyExcept("Fly fishing rod", "Feather", "Raw salmon", "Raw trout") && barbarianFish.contains(myPlayer())) { log("FISH_FISH"); return State.FISH_FISH; } else if (!barbarianFish.contains(myPlayer()) && getInventory().isEmptyExcept("Fly fishing rod", "Feather")) { log("WALK_TO_FISH"); return State.WALK_TO_FISH; } else if (getInventory().contains("Raw trout", "Raw salmon") && getInventory().isFull()) { log("COOK_FISH"); return State.COOK_FISH; } else if (getInventory().contains("Salmon", "Trout") && bankArea.contains(myPlayer())) { log("DEPOSIT"); return State.DEPOSIT; } else if (!bankArea.contains(myPlayer())) { log("WALK_TO_BANK"); return State.WALK_TO_BANK; } log("IDLE"); return State.IDLE; } @Override public void onExit() throws InterruptedException { } } The problem I am running into is, I can get the bot to perform 4/5 functions, but not all 5. For example, as the scripts sits now, It will bank if full of Cooked Fish, Deposit, Walk to Fish, Fish the fish, but now gets stuck when fishing because it wont recognize the inv.isFull(). I feel like I am in the right direction, but missing something small or misunderstanding something small rather. Any help and or feedback on the script would be appreciated as well. Thanks! Quote Link to comment Share on other sites More sharing options...
GPSwap Posted April 26, 2018 Share Posted April 26, 2018 if your invent is full of raw fish, if (getInventory().isEmptyExcept("Fly fishing rod", "Feather", "Raw salmon", "Raw trout") && barbarianFish.contains(myPlayer())) { log("FISH_FISH"); return State.FISH_FISH; will still return FISH_FISH, as technically inventory is still empty except for those items, add in a check for if inventory is not full and you should be good. Quote Link to comment Share on other sites More sharing options...
JS3 Posted April 26, 2018 Author Share Posted April 26, 2018 (edited) On 4/26/2018 at 9:39 PM, GPSwap said: if your invent is full of raw fish, if (getInventory().isEmptyExcept("Fly fishing rod", "Feather", "Raw salmon", "Raw trout") && barbarianFish.contains(myPlayer())) { log("FISH_FISH"); return State.FISH_FISH; will still return FISH_FISH, as technically inventory is still empty except for those items, add in a check for if inventory is not full and you should be good. Expand I do that here. Do I need to have it check before? - if (!getInventory().isFull() && barbarian.Fish.contains(myPlayer))) { } else if (getInventory().contains("Raw trout", "Raw salmon") && getInventory().isFull()) { log("COOK_FISH"); Edit: private State getState() { if (!getInventory().isFull() && barbarianFish.contains(myPlayer())) { log("FISH_FISH"); return State.FISH_FISH; } else if (!barbarianFish.contains(myPlayer()) && getInventory().isEmptyExcept("Fly fishing rod", "Feather")) { log("WALK_TO_FISH"); return State.WALK_TO_FISH; } else if (getInventory().contains("Raw trout", "Raw salmon") && getInventory().isFull()) { log("COOK_FISH"); return State.COOK_FISH; } else if (getInventory().contains("Salmon", "Trout") && bankArea.contains(myPlayer())) { log("DEPOSIT"); return State.DEPOSIT; } else if (!bankArea.contains(myPlayer())) { log("WALK_TO_BANK"); return State.WALK_TO_BANK; } log("IDLE"); return State.IDLE; } and is now working. Thank you @GPSwap Edited April 26, 2018 by m3JS Quote Link to comment Share on other sites More sharing options...
GPSwap Posted April 26, 2018 Share Posted April 26, 2018 On 4/26/2018 at 10:00 PM, m3JS said: I do that here. Do I need to have it check before? - if (!getInventory().isFull() && barbarian.Fish.contains(myPlayer))) { } else if (getInventory().contains("Raw trout", "Raw salmon") && getInventory().isFull()) { log("COOK_FISH"); Expand you check for your fish_fish state first, so if that is true it wont move past it, do something like and it should work if (getInventory().isEmptyExcept("Fly fishing rod", "Feather", "Raw salmon", "Raw trout") && barbarianFish.contains(myPlayer()) && !getInventory.isFull()) { log("FISH_FISH"); return State.FISH_FISH; Quote Link to comment Share on other sites More sharing options...