August 15, 20178 yr I'm learning how to interact with items in the inventory. Also trying to learn how to interact with items on the ground. When I run the code, my OsBot freezes, and I have to task manager to close it. Here's what I have at the moment. import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0) public class Main extends Script { @Override public int onLoop() throws InterruptedException { if (fireCheck()) { log("hello bitch"); } else { makeFire(); } return 50; } public boolean fireCheck() { RS2Object fire = objects.closest("Fire"); if (fire != null) { return true; } else { return false; } } public void makeFire() { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { RS2Object log = objects.closest("Logs"); if (log.interact("Light")) { new ConditionalSleep(random(600, 1200)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } }
August 15, 20178 yr Author 11 minutes ago, Chris said: Not 100% what you meant by this, But I took my guess. This is the change I made. import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0) public class Main extends Script { @Override public int onLoop() throws InterruptedException { makeFire(); return 50; } public void makeFire() { RS2Object fire = objects.closest("Fire"); RS2Object log = objects.closest("Logs"); if (fire != null) { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { if (log.interact("Light")) { new ConditionalSleep(random(600, 1200)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } } } It's not freezing anymore but my code isn't doing anything. So am I using the wrong api to interact with the log that's on the ground? Edited August 15, 20178 yr by kingbutton
August 15, 20178 yr import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0) public class Main extends Script { @Override public int onLoop() throws InterruptedException { if (fireCheck()) { log("hello bitch"); } else { makeFire(); } return 50; } public boolean fireCheck() { RS2Object fire = objects.closest("Fire"); return fire != null; } public void makeFire() { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { GroundItem log = getGroundItems().closest("Logs"); if (log != null && log.interact("Light")) { new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } }
August 15, 20178 yr Author Ight thanks MAN! Can you explain to me why in the fireCheck() method I have to return fire != null. Like why can't i do it in the makeFire() method?
August 15, 20178 yr 3 hours ago, kingbutton said: Ight thanks MAN! Can you explain to me why in the fireCheck() method I have to return fire != null. Like why can't i do it in the makeFire() method? You can do it in the makeFire() method, For example something like this: public void makeFire() { RS2Object fire = objects.closest("Fire"); if (!myPlayer().isAnimating() && !myPlayer().isMoving() && fire != null) { GroundItem log = getGroundItems().closest("Logs"); if (log != null && log.interact("Light")) { new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } It's mostly down to preference, however the way you had it before makes it clearer (to me) when you want the script to light a fire. Also at the moment you're trying to interact with logs on the ground. If you want to interact with logs in your inventory do this: Item log = getInventory().getItem("Logs");
Create an account or sign in to comment