-
Posts
687 -
Joined
-
Last visited
-
Days Won
1 -
Feedback
100%
Everything posted by Camaro
-
I actually just submitted a bug describing a similar situation. Are you by chance executing events?
-
Take a look at this. I religiously implement this in every script as if it was part of the API
-
I'm creating a framework for one script with multiple tasks. Is it feasible to instantiate a separate event executor to run events?
-
I did before posting this, so I was asking for confirmation before I did something unnecessary. Thanks
-
Hi, Im trying to set the webwalker to use teleports and check the bank for items. If I set both of these to true and I am next to a bank when the event is executed, the bot should automatically open the bank and withdraw teleport runes, correct? Or is that only for items such as amulets, rings ect? For reference, I am in Falador west bank trying to webwalk to varrock.
-
Am I able to give my own custom args when starting the client for use in my scripts? --mycustomarg "arg"
-
Hey, So I know http://osbot.org/mvc/get will always give you the latest stable release. Is there a static url I can hit for the newest dev release? Thanks.
-
Hi all, I'm going to implement a method in my script to determine the closest position that would act as a safespot from a monster I am attacking. I don't want to simply define a few that would always work as there may be a closer, more optimal spot. Now before I spend hours attacking monsters from different angles, does anyone know/have the NPC pathfinding algorithm when it is trying to interact with a player? Thanks!
-
After the first 'if' statement, put 'else if' instead
-
How come the version on the mainpage is 2.5.41?
-
Is there any lock-type object specific to Osbot that I can use to help asynchronous Events edit shared variables?
-
Well its the same position as the one you are standing on. But is it necessary to use webwalking inside of there?
-
@Override public int onLoop() throws InterruptedException { new ConditionalLoop(bot, 30000) { @Override public int loop() { log("Running"); return 300; } @Override public boolean condition() { return true; } }.start(); return 600; } Just a simple conditional. Goes way past the 30 second timeout It is probably better to use an Event anyway.
-
I was just searching for something like this #blessed
-
So when I stop a script in the middle of a ConditionalLoop, the loop will continue well after the script has stopped. I can tell by text strings continually getting posted to the log that I call from inside the loop. [INFO][Bot #1][01/08 11:19:59 PM]: Here [INFO][Bot #1][01/08 11:19:59 PM]: Here [INFO][Bot #1][01/08 11:19:59 PM]: Here [WARN][Bot #1][01/08 11:20:01 PM]: Event executor is taking too long to suspend; terminating now... [ERROR][Bot #1][01/08 11:20:01 PM]: Caught thread death in EventExecutor [INFO][Bot #1][01/08 11:20:01 PM]: Script Copper miner has exited! [INFO][Bot #1][01/08 11:20:43 PM]: Here [INFO][Bot #1][01/08 11:20:43 PM]: Here [INFO][Bot #1][01/08 11:20:44 PM]: Here Are there certain steps I should take to properly stop a script?
-
Best method to look for grounditems dropped only by monsters you kill
Camaro replied to Camaro's topic in Scripting Help
if ((CURR_KILL = myPlayer().getInteracting()) != null) { if (CURR_KILL.getHealthPercent() == 0) { List<GroundItem> items = getGroundItems().get(CURR_KILL.getX(), CURR_KILL.getY()); items.removeIf(i -> !i.getName().equals("Bones")); if (Timing.waitCondition(() -> { List<GroundItem> items2 = getGroundItems().get(CURR_KILL.getX(), CURR_KILL.getY()); items2.removeIf(i -> !i.getName().equals("Bones")); return items.size() < items2.size(); }, 5000)) { GroundItem item = getGroundItems().closest(g -> g != null && getMap().canReach(g) && (g.getName().equals("Iron arrow") && g.getPosition().equals(CURR_KILL.getPosition()))); if (item != null) { int count = (int) inventory.getAmount(item.getName()); if (item.interact("Take")) Timing.waitCondition(() -> inventory.getAmount(item.getName()) > count, 3000); } } } } Believe I have perfected this... Keep looping until the monster I am interacting with has zero health. Then save it's position and wait for the bones to appear. Then loot any arrows with that monsters position. -
Are there any advantages to using this option instead of multithreading?
-
Best method to look for grounditems dropped only by monsters you kill
Camaro replied to Camaro's topic in Scripting Help
More-so just don't want to run around picking up everyone's arrows -
Best method to look for grounditems dropped only by monsters you kill
Camaro replied to Camaro's topic in Scripting Help
Seem to be having better luck with this if (myPlayer().getInteracting() != null) { CURR_KILL = myPlayer().getInteracting(); List<GroundItem> items = getGroundItems().get(CURR_KILL.getX(), CURR_KILL.getY()); items.removeIf(i -> !i.getName().equals("Bones")); if (Timing.waitCondition(() -> { List<GroundItem> items2 = getGroundItems().get(CURR_KILL.getX(), CURR_KILL.getY()); items2.removeIf(i -> !i.getName().equals("Bones")); return items.size() < items2.size(); }, 10000)) { GroundItem item = getGroundItems().closest(g -> g != null && getMap().canReach(g) && (g.getName().equals("Iron arrow") && g.getAmount() > 4 && g.getPosition().equals(CURR_KILL.getPosition()))); if (item != null) { int count = (int) inventory.getAmount(item.getName()); if (item.interact("Take")) { Timing.waitCondition(() -> inventory.getAmount(item.getName()) > count, 3000); } } } } If the player is interacting (fighting) with something, wait until their bones drop. then scan for items. -
Consider the following scenario: You are killing monsters around other players who are killing the same monsters with iron arrows. You want to loot the iron arrows dropped by your monsters, but not pick up any other iron arrows on the ground. What is the best way to achieve this? I have written some code, but not sure if this is efficient... if (myPlayer().getInteracting() != null && Timing.waitCondition(() -> myPlayer().getInteracting().getHealthPercent() == 0, 5000)) { LAST_KILL = myPlayer().getInteracting().getPosition(); } else if (!getCombat().isFighting()) { GroundItem item = getGroundItems().closest(g -> g != null && getMap().canReach(g) && (g.getName().equals("Iron arrow") && g.getAmount() > 4 && g.getPosition().equals(LAST_KILL))); if (item != null) { int count = (int) inventory.getAmount(item.getName()); if (item.interact("Take")) { Timing.waitCondition(() -> inventory.getAmount(item.getName()) > count, 3000); } } } Once the monster's health percent, I store that monsters position to a variable. Then I make sure that the ground item's position is the same as the stored position.
-
Well, every loop, you are opening the combat tab and then opening the inventory tab, going back and forth between the two. You should set it so only on a level up message (the onMessage function) set a boolean for checking attack style, then setting that variable back to false after everything has been checked
-
This doesnt seem to want to switch to an F2P world... cant seem to figure out why Edit: sorry, realized that my world list was not organized correctly. Ordering it by world number fixed this
-
Already does this in the first conditional in the unsure case of the switch! And yes, setting variables after looking at the page for the first time would be better. Thanks a ton! Didnt even know about configs, thats very useful.
-
Hi, just finished up my first script, looking for feedback on how I can improve. It completes Cooks Assistant and also the baking break achievement diary. Should be able to start from any point in the quest. Big shout-out to @The Viking for his Timing class! Also @Explv for the area map, extremely helpful. 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.MethodProvider; public class Helper { private MethodProvider provider; public Helper(MethodProvider p) { provider = p; } public RS2Widget cooksAssistant() { return provider.getWidgets().get(399, 9, 1); } public RS2Widget progressPage() { return provider.getWidgets().get(119, 3); } public RS2Widget dialogBoxCook() { return provider.getWidgets().get(231, 2); } public RS2Widget dialogBoxMe() { return provider.getWidgets().get(217, 2); } public RS2Widget optionOne() { return provider.getWidgets().get(219, 1, 1); } public RS2Widget lineMilk() { return provider.getWidgets().get(119, 7); } public RS2Widget lineFlour() { return provider.getWidgets().get(119, 8); } public RS2Widget lineEgg() { return provider.getWidgets().get(119, 9); } public RS2Widget lumbyDiary() { return provider.getWidgets().get(259, 10, 83); } public RS2Widget achievementDiary() { return provider.getWidgets().get(399, 3); } public RS2Widget cookBreadAchievement() { return provider.getWidgets().get(119, 18); } public RS2Widget breadOption() { return provider.getWidgets().get(270, 14, 29); } public NPC cook() { return provider.getNpcs().closest(4626); } public RS2Object cow() { return provider.getObjects().closest(8689); } public RS2Object wheat() { return provider.getObjects().closest("Wheat"); } public RS2Object hopper() { return provider.getObjects().closest("Hopper"); } public RS2Object lever() { return provider.getObjects().closest("Hopper controls"); } public RS2Object flourBin() { return provider.getObjects().closest("Flour bin"); } public RS2Object range() { return provider.getObjects().closest("Cooking range"); } public RS2Object sink() { return provider.getObjects().closest("Sink"); } } import org.osbot.rs07.api.Quests; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.ui.*; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(info = "Cooks assistant", version = 1.0, logo = "", name = "Cooks assistant", author = "Matt") public class Main extends Script { enum Progress { unsure, needToStart, needToGetMilk, needToGetFlour, needToGetEgg, needToGiveMilk, needToGiveFlour, needToGiveEgg, needToTalk, doDiary, bakeBread, completed } enum FlourProgress { getGrain, putInHopper, pullLever, getFlour } public Progress progress = null; public FlourProgress flourProgress = null; public GroundItem tempitem = null; public int tempint = 0; public Helper helper = null; public final Area startArea = new Area(3205, 3217, 3212, 3212); public final Area bucketArea = new Area(3211, 9624, 3216, 9620); public final Area eggArea = new Area(3227, 3301, 3233, 3296); public final Area milkArea = new Area( new int[][]{ { 3251, 3278 }, { 3251, 3274 }, { 3254, 3271 }, { 3256, 3271 }, { 3256, 3278 } } ); public final Area flourArea = new Area( new int[][]{ { 3157, 3295 }, { 3162, 3290 }, { 3164, 3292 }, { 3164, 3295 } } ); public final Area hopperArea = new Area( new int[][]{ { 3166, 3311 }, { 3168, 3311 }, { 3171, 3308 }, { 3171, 3306 }, { 3168, 3303 }, { 3166, 3303 }, { 3163, 3306 }, { 3163, 3308 } } ); public boolean isAtStart() { return startArea.contains(myPlayer()); } public boolean isAtBucketArea() { return bucketArea.contains(myPlayer()); } public boolean isAtEggArea() { return eggArea.contains(myPlayer()); } public boolean isAtMilkArea() { return milkArea.contains(myPlayer()); } public boolean isAtFlourArea() { return flourArea.contains(myPlayer()); } public boolean isAtHopperArea(int plane) { return hopperArea.setPlane(plane).contains(myPlayer()); } public boolean isReady(int pots, int buckets, int eggs) { return inventory.getAmount("Pot") >= pots && inventory.getAmount("Bucket") >= buckets && inventory.getAmount("Egg") >= eggs; } public void getPot() { if (!isAtStart()) { walking.webWalk(startArea); } else if ((tempitem = getGroundItems().closest("Pot")) != null) { tempint = getInventory().getEmptySlotCount(); tempitem.interact("Take"); Timing.waitCondition(() -> getInventory().getEmptySlotCount() < tempint, 3000); } } public void getBucket() { if (!isAtBucketArea()) { walking.webWalk(bucketArea); } else if ((tempitem = getGroundItems().closest("Bucket")) != null) { tempint = getInventory().getEmptySlotCount(); tempitem.interact("Take"); Timing.waitCondition(() -> getInventory().getEmptySlotCount() < tempint, 3000); } } public void getEgg() { if (!isAtEggArea()) { walking.webWalk(eggArea); } else if ((tempitem = getGroundItems().closest("Egg")) != null) { tempint = getInventory().getEmptySlotCount(); tempitem.interact("Take"); Timing.waitCondition(() -> getInventory().getEmptySlotCount() < tempint, 3000); } } public void getMilk() { if (!isReady(0, (int)(1 - inventory.getAmount("Bucket of milk")), 0)) { getSupplies(0, (int)(1 - inventory.getAmount("Bucket of milk")), 0); } else if (!isAtMilkArea()) { walking.webWalk(milkArea); } else if (helper.cow() != null) { tempint = (int) inventory.getAmount("Bucket of milk"); helper.cow().interact("Milk"); Timing.waitCondition(() -> inventory.getAmount("Bucket of milk") > tempint, 10000); } } public void getFlour(int count) { if (!isReady((int)(count - inventory.getAmount("Pot of flour")), 0, 0)) { getSupplies((int)(count - inventory.getAmount("Pot of flour")), 0, 0); } else if (flourProgress == null) { flourProgress = FlourProgress.getGrain; } switch (flourProgress) { case getGrain: if (inventory.getAmount("Grain") >= count - inventory.getAmount("Pot of flour")) { flourProgress = FlourProgress.putInHopper; } else if (!isAtFlourArea()) { walking.webWalk(flourArea); } else if (helper.wheat() != null) { tempint = (int) inventory.getAmount("Grain"); helper.wheat().interact("Pick"); Timing.waitCondition(() -> inventory.getAmount("Grain") > tempint, 3000); } break; case putInHopper: if (!isAtHopperArea(2)) { walking.webWalk(hopperArea.setPlane(2)); } else if (helper.hopper() != null && inventory.getItem("Grain").interact("Use")) { tempint = (int) inventory.getAmount("Grain"); helper.hopper().interact("Use"); Timing.waitCondition(() -> inventory.getAmount("Grain") < tempint && !myPlayer().isAnimating(), 5000); Timing.waitCondition(() -> false, 2000); flourProgress = FlourProgress.pullLever; } break; case pullLever: if (!isAtHopperArea(2)) { walking.webWalk(hopperArea.setPlane(2)); } else if (helper.lever() != null && helper.lever().interact("Operate")) { Timing.waitCondition(() -> !myPlayer().isMoving() && myPlayer().isAnimating(), 3000); flourProgress = FlourProgress.getFlour; } break; case getFlour: if (!isAtHopperArea(0)) { walking.webWalk(hopperArea.setPlane(0)); } else if (helper.flourBin() != null) { tempint = (int) inventory.getAmount("Pot of flour"); helper.flourBin().interact("Empty"); Timing.waitCondition(() -> inventory.getAmount("Pot of flour") > tempint, 3000); flourProgress = null; } break; } } public void getSupplies(int pots, int buckets, int eggs) { log("getting supplies"); if (inventory.getAmount("Pot") < pots) { getPot(); } else if (inventory.getAmount("Bucket") < buckets) { getBucket(); } else if (inventory.getAmount("Egg") < eggs) { getEgg(); } } @Override public void onStart() throws InterruptedException { log("Starting"); progress = Progress.unsure; helper = new Helper(this); } @Override public int onLoop() throws InterruptedException { log(progress); switch (progress) { case unsure: if (getQuests().isComplete(Quests.Quest.COOKS_ASSISTANT)) { progress = Progress.doDiary; } else if (!getQuests().isStarted(Quests.Quest.COOKS_ASSISTANT) && !getQuests().isComplete(Quests.Quest.COOKS_ASSISTANT)) { progress = Progress.needToStart; } else if (!getTabs().isOpen(Tab.QUEST) && getTabs().open(Tab.QUEST)) { Timing.waitCondition(() -> getTabs().isOpen(Tab.QUEST), 2000); } else if (helper.progressPage() == null) { helper.cooksAssistant().interact("Read Journal:"); Timing.waitCondition(() -> helper.progressPage() != null, 2000); } else if (helper.lineMilk() != null && helper.lineMilk().getMessage().contains("I need to find")) { progress = Progress.needToGetMilk; } else if (helper.lineMilk() != null && helper.lineMilk().getMessage().contains("give to the cook")) { progress = inventory.getAmount("Bucket of milk") < 2 ? Progress.needToGetMilk : Progress.needToGiveMilk; } else if (helper.lineFlour() != null && helper.lineFlour().getMessage().contains("I need to find")) { progress = Progress.needToGetFlour; } else if (helper.lineFlour() != null && helper.lineFlour().getMessage().contains("give to the cook")) { progress = inventory.getAmount("Pot of flour") < 2 ? Progress.needToGetFlour : Progress.needToGiveFlour; } else if (helper.lineEgg() != null && helper.lineEgg().getMessage().contains("I need to find")) { progress = Progress.needToGetEgg; } else if (helper.lineEgg() != null && helper.lineEgg().getMessage().contains("give to the cook")) { progress = Progress.needToGiveEgg; } else if (helper.lineMilk() != null && helper.lineFlour() != null && helper.lineEgg() != null && helper.lineMilk().getMessage().contains("I have given") && helper.lineFlour().getMessage().contains("I have given") && helper.lineEgg().getMessage().contains("I have given")) { progress = Progress.needToTalk; } break; case needToStart: if (!isAtStart()) { walking.webWalk(startArea); } else if (!getDialogues().inDialogue() && helper.cook() != null) { helper.cook().interact("Talk-to"); Timing.waitCondition(() -> getDialogues().inDialogue(), 3000); } else if ((helper.dialogBoxCook() != null && helper.dialogBoxCook().getMessage().equals("Cook")) || (helper.dialogBoxMe() != null && helper.dialogBoxMe().getMessage().equals(myPlayer().getName()))) { getKeyboard().pressKey(32); } else if (helper.optionOne() != null && helper.optionOne().getMessage().equals("What's wrong?")) { getDialogues().selectOption("What's wrong?"); } else if (helper.optionOne() != null && helper.optionOne().getMessage().equals("I'm always happy to help a cook in distress.")) { getDialogues().selectOption("I'm always happy to help a cook in distress."); Timing.waitCondition(() -> getQuests().isStarted(Quests.Quest.COOKS_ASSISTANT), 2000); progress = Progress.needToGetMilk; } break; case needToGetMilk: if (inventory.getAmount("Bucket of milk") < 2) { getMilk(); } else { progress = Progress.needToGiveMilk; } break; case needToGiveMilk: if (inventory.getAmount("Bucket of milk") < 2) { progress = Progress.unsure; } else if (!isAtStart()) { walking.webWalk(startArea); } else if (!getDialogues().inDialogue() && helper.cook() != null) { helper.cook().interact("Talk-to"); } else if ((helper.dialogBoxCook() != null && helper.dialogBoxCook().getMessage().equals("Cook")) || (helper.dialogBoxMe() != null && helper.dialogBoxMe().getMessage().equals(myPlayer().getName()))) { getKeyboard().pressKey(32); } break; case needToGetFlour: if (inventory.getAmount("Pot of flour") < 2) { getFlour(2); } else { progress = Progress.needToGiveFlour; } break; case needToGiveFlour: if (inventory.getAmount("Pot of flour") < 2) { progress = Progress.unsure; } else if (!isAtStart()) { walking.webWalk(startArea); } else if (!getDialogues().inDialogue() && helper.cook() != null) { helper.cook().interact("Talk-to"); } else if ((helper.dialogBoxCook() != null && helper.dialogBoxCook().getMessage().equals("Cook")) || (helper.dialogBoxMe() != null && helper.dialogBoxMe().getMessage().equals(myPlayer().getName()))) { getKeyboard().pressKey(32); } break; case needToGetEgg: if (!isReady(0, 0, 1)) { getEgg(); } else { progress = Progress.needToGiveEgg; } break; case needToGiveEgg: if (!getInventory().contains("Egg")) { progress = Progress.unsure; } else if (!isAtStart()) { walking.webWalk(startArea); } else if (!getDialogues().inDialogue() && helper.cook() != null) { helper.cook().interact("Talk-to"); } else if ((helper.dialogBoxCook() != null && helper.dialogBoxCook().getMessage().equals("Cook")) || (helper.dialogBoxMe() != null && helper.dialogBoxMe().getMessage().equals(myPlayer().getName()))) { getKeyboard().pressKey(32); } break; case needToTalk: if (getQuests().isComplete(Quests.Quest.COOKS_ASSISTANT)) { progress = Progress.doDiary; } else if (!isAtStart()) { walking.webWalk(startArea); } else if (!getDialogues().inDialogue() && helper.cook() != null) { helper.cook().interact("Talk-to"); } else if ((helper.dialogBoxCook() != null && helper.dialogBoxCook().getMessage().equals("Cook")) || (helper.dialogBoxMe() != null && helper.dialogBoxMe().getMessage().equals(myPlayer().getName()))) { getKeyboard().pressKey(32); } break; case doDiary: if (!getWorlds().isMembersWorld()) { log("Not on members world, cannot complete achievement diary"); progress = Progress.completed; } else if (helper.progressPage() == null && !getTabs().isOpen(Tab.QUEST) && getTabs().open(Tab.QUEST)) { Timing.waitCondition(() -> getTabs().isOpen(Tab.QUEST), 2000); } else if (helper.progressPage() == null && helper.lumbyDiary() == null && helper.achievementDiary() != null) { helper.achievementDiary().interact("View Achievement Diaries"); } else if (helper.progressPage() == null) { helper.lumbyDiary().interact("Open Lumbridge & Draynor Journal"); Timing.waitCondition(() -> helper.progressPage() != null, 2000); } else if (helper.cookBreadAchievement() != null) { progress = helper.cookBreadAchievement().getMessage().contains("<str>") ? Progress.completed : Progress.bakeBread; } break; case bakeBread: if (!getInventory().contains("Bread dough") && !getInventory().contains("Bucket of water") && !getInventory().contains("Bucket")) { getSupplies(0, 1, 0); } else if (!getInventory().contains("Bread dough") && !getInventory().contains("Pot of flour")) { getFlour(1); } else if (!isAtStart()) { walking.webWalk(startArea); } else if (!getInventory().contains("Bread dough") && !getInventory().contains("Bucket of water") && helper.sink() != null) { inventory.getItem("Bucket").interact("Use"); tempint = (int) inventory.getAmount("Bucket"); helper.sink().interact("Use"); Timing.waitCondition(() -> inventory.getAmount("Bucket") < tempint, 5000); } else if (!getInventory().contains("Bread dough") && helper.breadOption() == null) { inventory.getItem("Bucket of water").interact("Use"); tempint = (int) inventory.getAmount("Bread dough"); inventory.getItem("Pot of flour").interact("Use"); Timing.waitCondition(() -> helper.breadOption() != null, 2000); } else if (!getInventory().contains("Bread dough") && helper.breadOption() != null) { helper.breadOption().interact("Make"); } else if (!getInventory().contains("Break") && helper.range() != null && !helper.range().isVisible()) { walking.walk(new Area(3210, 3216, 3211, 3215)); } else if (!getInventory().contains("Break") && helper.range() != null) { inventory.getItem("Bread dough").interact("Use"); tempint = (int) inventory.getAmount("Bread"); helper.range().interact("Use"); if (Timing.waitCondition(() -> inventory.getAmount("Bread") > tempint, 7000)) { progress = Progress.completed; } } break; case completed: log(getWidgets().get(119, 6).getMessage()); log("Completed quest"); stop(false); break; } return 600; } }