TheKillerAurial Posted April 2, 2020 Share Posted April 2, 2020 Hi Scripting Community, I would like to get some feedback on my first script TSRunner (Trout Salmon Runner). I have some background in software development and testing but would not consider myself a developer. I have written the below script to run to the fishing spot in barb village and collect fish on the ground , then head to the GE to bank and repeat (I chose not to go to edge bank)- I have tested it for 2hrs+ and seems to be working (20-25k per hour)- albeit it seems to be competing with many looting bots in the area. One problem I have been experiencing is if there is a large loot pile on the floor, it always seems to try and "take" the first one. I'm guessing it is trying to "take" index 0. Can you specify the index in anyway so say if there is a pile on the floor it will take the 6th or 7th item if it exists? Code: import java.awt.Graphics2D; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.event.WebWalkEvent; import org.osbot.rs07.event.webwalk.PathPreferenceProfile; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "Aurial", info = "Trout - Salmon Runner", logo = "", name = "TSRunner", version = 1) public class TSRunnerScript extends Script { private Area fishLocation = new Area(3104, 3435, 3109, 3431); private Area bankLocation = new Area(3161, 3492, 3168, 3486); enum State { RUNNING2BANK, RUNNING2FISH, LOOTING; } private State currentState; private Boolean checkInventoryIsEmpty(){ if(inventory.isEmpty()){ log("TSRunner || Inventory IS empty."); return true; } else { log("TSRunner || Inventory IS NOT empty!"); log("TSRunner || Will attempt to Bank items"); return false; } } private void goToFishSpot() throws InterruptedException { if(!inventory.isEmpty()){ currentState = State.RUNNING2BANK; } else { log("TSRunner || Heading to fishing location..."); WebWalkEvent webEvent = new WebWalkEvent(fishLocation); webEvent.useSimplePath(); PathPreferenceProfile ppp = new PathPreferenceProfile(); ppp.setAllowTeleports(false); webEvent.setPathPreferenceProfile(ppp); execute(webEvent); log("TSRunner || Arrived at fishing location..."); sleep(random(300,500)); } } private void lootFish() throws InterruptedException { log("TSRunner || Looting fish..."); while (!inventory.isFull()){ if(!myPlayer().isAnimating() || !myPlayer().isMoving() || !myPlayer().isUnderAttack()){ GroundItem fishies = getGroundItems().closest("Salmon", "Trout", "Raw salmon", "Raw trout"); if(fishies != null){ if(inventory.isEmpty()){ fishies.interact("Walk here"); } sleep(random(20, 333)); fishies.interact("Take"); sleep(random(20, 333)); } } } if(inventory.isFull()){ log("TSRunner || Inventory is full."); currentState = State.RUNNING2BANK; } } private void goToBankAndDepositFish() throws InterruptedException { log("TSRunner || Heading to bank location..."); WebWalkEvent webEvent = new WebWalkEvent(bankLocation); webEvent.useSimplePath(); PathPreferenceProfile ppp = new PathPreferenceProfile(); ppp.setAllowTeleports(false); webEvent.setPathPreferenceProfile(ppp); execute(webEvent); log("TSRunner || Arrived at bank location..."); sleep(random(300,500)); if (!myPlayer().isAnimating() || !myPlayer().isMoving() || !myPlayer().isUnderAttack()) { log("TSRunner || Attempting to deposit all..."); sleep(random(300,500)); if (inventory.isFull()) { if (getBank().isOpen()) { sleep(random(200,300)); getBank().depositAll(); sleep(random(50, 100)); log("TSRunner || Banking finished..."); currentState = State.RUNNING2FISH; } else { sleep(random(300,500)); getBank().open(); sleep(random(200,300)); getBank().depositAll(); sleep(random(50, 100)); log("TSRunner || Banking finished..."); currentState = State.RUNNING2FISH; } } } } @Override public void onStart(){ log("-----------------------"); log("TSRunner || Starting..."); log("-----------------------"); if (checkInventoryIsEmpty()){ currentState = State.RUNNING2FISH; } else { currentState = State.RUNNING2BANK; } } @Override public int onLoop() throws InterruptedException{ switch (currentState){ case RUNNING2FISH: return first(); case LOOTING: return second(); case RUNNING2BANK: return third(); } return random(200, 300); } private int first() throws InterruptedException { goToFishSpot(); currentState = State.LOOTING; return random(200, 300); } private int second() throws InterruptedException{ lootFish(); return random(200,300); } private int third() throws InterruptedException{ goToBankAndDepositFish(); return random(200,300); } @Override public void onExit(){ log("---------------------"); log("TSRunner || Ending..."); log("---------------------"); } @Override public void onPaint(Graphics2D g){ } } Quote Link to comment Share on other sites More sharing options...
botelias Posted April 2, 2020 Share Posted April 2, 2020 Made a script that does the same exact thing, just had it spam the hell out of the loot pile. Seems to work well. Maybe you can just have it click the ground-tile with loot on it if it keeps insisting on rightclicking and doing index 0? Another option would be to add all grounditems to a list, then have it do a different index from that list when looting. Quote Link to comment Share on other sites More sharing options...
TheKillerAurial Posted April 2, 2020 Author Share Posted April 2, 2020 34 minutes ago, botelias said: Made a script that does the same exact thing, just had it spam the hell out of the loot pile. Seems to work well. Maybe you can just have it click the ground-tile with loot on it if it keeps insisting on rightclicking and doing index 0? Another option would be to add all grounditems to a list, then have it do a different index from that list when looting. Thanks for the advice - really appreciate it. Could you show me an example for the grounditems -> list option? Quote Link to comment Share on other sites More sharing options...
botelias Posted April 2, 2020 Share Posted April 2, 2020 38 minutes ago, TheKillerAurial said: Thanks for the advice - really appreciate it. Could you show me an example for the grounditems -> list option? Few options available here: https://osbot.org/forum/topic/84132-ground-items-to-list/ Quote Link to comment Share on other sites More sharing options...
TheKillerAurial Posted April 3, 2020 Author Share Posted April 3, 2020 19 hours ago, botelias said: Few options available here: https://osbot.org/forum/topic/84132-ground-items-to-list/ Thanks! I'll give it a go. Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted April 3, 2020 Share Posted April 3, 2020 You can do something like this: Stream<GroundItem> fishItems = getGroundItems().getAll().stream().filter((e) -> e.getName().contains("Raw")); You can than manipulate that data to do as you wish. Quote Link to comment Share on other sites More sharing options...