Jump to content

kingbutton

Members
  • Posts

    27
  • Joined

  • Last visited

  • Feedback

    0%

Profile Information

  • Gender
    Male

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

kingbutton's Achievements

Bronze Poster

Bronze Poster (2/10)

1

Reputation

  1. You seem to understand the situation, does this look good to you? I'm trying to use enums in my codes now to make them look cleaner. public State getState() { RS2Object fire = objects.closest("Fire"); if (!inventory.contains("Tinderbox") // NO TINDERBOX? || inventory.onlyContains("Tinderbox") // ONLY TINDERBOX? || !inventory.contains("Filler")) { // YOU'RE DONE COOKING? return State.BANK; } else if (myPlayer().isAnimating()) { // YOU'RE DOING STUFF??? return State.WAIT; } else if (fire != null) { // OH LOOKIEE HERE, A FIREEE? return State.COOK; } else { return State.LIGHT; // NO FIREE?? Simple. JUST MAKE ONE! } } Sorry I'm dumb. The only answer I saw was the response from superuser, and it was giving me a dead code. The other thing was Frostbug explaining something but I didn't understand it.
  2. Um, of course I read the api. exists boolean exists() Checks whether this Entity still exists or not. Returns: Whether this Entity still exists or not. Still don't see how's that different from != null . Seems exactly the same to me? Plus that isn't really the main question. Main question is why is my code unreachable and how do I fix it? Because the response earlier is giving me a Dead Code.
  3. So I'm confused what I'm supposed to get out of this. public State getState() { RS2Object fire = objects.closest("Fire"); if (!inventory.contains("Tinderbox") // NO TINDERBOX? || inventory.onlyContains("Tinderbox") // ONLY TINDERBOX? || !inventory.contains("Filler")) { // YOU'RE DONE COOKING? return State.BANK; } else if (fire.exists() && fire != null) { // HAHAAHAAAA WE DISCOVVEREEEDDD FIREEEE return State.COOK; } else if (!fire.exists() && fire == null) { return State.LIGHT; } else { return State.WAIT; } } Did what you said, and it says Dead Code. Also I've never used exists() before. What's the difference in exists() and != null ?
  4. public enum State { LIGHT, COOK, BANK, WAIT; } public State getState() { RS2Object fire = objects.closest("Fire"); if (!inventory.contains("Tinderbox") // NO TINDERBOX? || inventory.onlyContains("Tinderbox") // ONLY TINDERBOX? || !inventory.contains("Filler")) { // YOU'RE DONE COOKING? return State.BANK; } else if (fire != null) { // HAHAAHAAAA WE DISCOVVEREEEDDD FIREEEE return State.COOK; } else { return State.LIGHT; // aww we have no fire :( BUT WEEEE SHALL MAKEEE ITT } return State.WAIT; }
  5. Okay so I got it to chill after it does "Cook all", and technically my code is working smoothly, but there's one thing that is unhuman like and needs to be address. When it tries to interact with the fire, it tries to click several times, kind of like the thing issue I had before. It doesn't bug out or anything, but it bothers me that does it, any solutions? I tried working with the sleep, but it's not working. public class Main extends Script { long lastAnimation = 0; @Override public int onLoop() throws InterruptedException { if (invCheck()) { if (fireCheck()) { log("Go cook"); if (myPlayer().isAnimating()) { lastAnimation = System.currentTimeMillis(); } else if (System.currentTimeMillis() > (lastAnimation + 12000)) { goCook(); } } else { log("Make fire"); makeFire(); } } else { } return 50; } public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { if (fire.interact("Use")) { Sleep.sleepUntil(() -> !getInventory().contains("raw"), 12000); } } } } }
  6. How do you use filters? Never had to use them before for my other scripts
  7. Okay so I tried this also. I'm probably implementing it wrong in the code, cause they way I have it set up. Seems a bit confusing and I feel like I have some things that are in the wrong spots. Can you see what's wrong with it then, cause it's still doing the same thing. public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { long lastAnimation = 0; if (myPlayer().isAnimating()) { lastAnimation = System.currentTimeMillis(); } else if (System.currentTimeMillis() > (lastAnimation + 4500)) { if (fire.interact("Use")) { Sleep.sleepUntil(() -> !getInventory().contains("raw"), 5000); } } } } } }
  8. I figured out how to make the code work without the error, but I'm still having the same issue where it's trying to click on a fish in my inventory, clicks on a cooked fish, and then it doesn't sleep until the inventory is finished. Sleep.sleepUntil(() -> !getInventory().contains("raw"), 5000); Even when I change the 5000 to something insane, still does the same thing.
  9. public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { if (fire.interact("Use")) { Sleep.sleepUntil(() -> !getInventory().contains("rawFoodName", 120000)); } } } import org.osbot.rs07.utility.ConditionalSleep; import java.util.function.BooleanSupplier; public final class Sleep extends ConditionalSleep { private final BooleanSupplier condition; public Sleep(final BooleanSupplier condition, final int timeout) { super(timeout); this.condition = condition; } @Override public final boolean condition() throws InterruptedException { return condition.getAsBoolean(); } public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) { return new Sleep(condition, timeout).sleep(); } } Okay so even when I paste exactly what you have, btw you for a parenthesis, It's still giving me an error.
  10. I'm not too familiar with BooleanSuppliers... Sleep.sleepUntil(!inventory.contains("raw"), 5000); So I can't use a boolean, I need to use a booleansupplier. Can you explain how to properly use this snippet? I did add it under my MainClass, so that isn't the issue.
  11. When I run the code. It would cook the fish, and then click on the fish besides it in the inventory. Cook another fish, then it would stop, and repeat itself. Cooks 3 fishes at a time before it loops back up. How do i make it so it just chills after cooks all and goes through the full inventory? public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { if (fire.interact("Use")) { new ConditionalSleep(random(4000, 5000)) { @Override public boolean condition() throws InterruptedException { return optionMenu != null; } }.sleep(); } } } } }
  12. 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?
  13. 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?
  14. 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(); } } } }
  15. Well to anybody interested! I figured out how to use methods, not sure if they're used efficiently though or if i can clean anything up, do more checks, iono. But I GOT IT WORKING AND THAT'S WHAT MATTERS, also decided to change it to a barb fisher. https://paste.ofcode.org/W8ezZaeTJckFcUx5MzYAVr If anybody has some constructive criticism, besides my really simple question. Toss em here!
×
×
  • Create New...