Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Issues with first script, thoughts?


    trtl

    Recommended Posts

    I'm working through building my first script (chicken killer) and while it mostly works, it is very bot-like and has a few glaring issues.

    What I want this script to be eventually:

    • Kills chickens
    • Loots all drops (feathers, bones, raw chicken)
    • When inventory is full, buries bones
    • When inventory is almost full of raw chicken, chop down nearby tree & light fire
    • Cook all raw chicken
    • Bank feathers & cooked chicken
    • Repeat

    My general goal is to use this script as a way of familiarizing myself with many aspects of the script development process, and I'm in the initial stages currently. Right now it kills and loots, although I need help with making the looting/combat decision making process more human-like. As it is, the script will click to loot something & attack a chicken at the same time repeatedly.

    Here is my code so far (just the node related to killing/looting chickens):

    package tasks;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.filter.Filter;
    import org.dreambot.api.methods.interactive.GameObjects;
    import org.dreambot.api.methods.interactive.NPCs;
    import org.dreambot.api.methods.item.GroundItems;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.walking.impl.Walking;
    import org.dreambot.api.script.TaskNode;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    
    public class Chickens extends TaskNode {
    
        final Area KILLBOX = new Area(3225, 3292, 3236, 3301);
        int bool = 0;
    
        public static final String CHICKEN = "Chicken";
        public static final Filter<NPC> CHICKEN_FILTER = new Filter<NPC>() {
            @Override
            public boolean match(NPC npc) {
                if (npc == null){
                    return false;
                }
    
                return npc.getName().equals(CHICKEN) && !npc.isHealthBarVisible();
            }
        };
    
        @Override
        public boolean accept() {
            // If our inventory is not full, and we're in the right area
            return !Inventory.isFull() && (KILLBOX.contains(getLocalPlayer()));
        }
    
        @Override
        public int execute() {
            log("In Chickens task");
    
            GroundItem drops = GroundItems.closest("Feather", "Bones", "Raw chicken");
    
            if (getLocalPlayer().isInCombat()){
                // Do nothing
            } else if (KILLBOX.contains(getLocalPlayer())) { // If player is in the box
                NPC chicken = NPCs.closest(CHICKEN_FILTER);
    
                    if (chicken != null && bool == 0) { // If chickens are present, & bool var is set to 0
                        log("In Chickens task, attacking");
                        chicken.interact("Attack");
                    }
    
                    if (drops != null) { // If chicken drops are present
                        log("In Chickens task, drops found, picking up");
                        drops.interact("Take");
                        int bool = 1;
                    }
    
                } else {
                    Walking.walk(KILLBOX.getRandomTile());
                }
    
            return Calculations.random(300, 600);
        }
    
    }

    As I said this is my first script, and I'm sure there are plenty of obvious issues to any scripters who have more experience than me, and I really just want to know what you feel I'm doing wrong, how I can fix my looting/combat issue, and any other suggestions you may have.

    My goal is to make little resource scripts like this to compliment my IMG when groups is released, but I want to ensure they are high quality and not easily detectable. I haven't been banned yet, but all I've been doing is a little chicken killing here and there as I build the script, but I have a feeling if I ran this for any extended length of time I'd be banned in no time. It's very obvious as a bot with some of it's current behavior. Eventually I would like to integrate my own classes and methods to place between the dreambot API code to make things a little more human-like, but that will be down the road once I feel comfortable I have an idea how to code scripts for dreambot relatively decently. (and have more experience with Java)

    Looking forward to any insight you can provide, thanks!

     

    Edit: Just wanted to clarify a bit of the code as I was attempting to fix the looting/combat at the same time issue: I was trying to set a variable (bool) so it would avoid attacking if there was loot nearby to pick up. I'm sure it may not be 100% clear just from looking at my code that was my goal lol

     

    Edit2: I've modified the combat/loot process by removing the bool var and instead just adding a check if drops are present in the combat if statement. This definitely simplifies things although I would like the looting process to be a little more human-like by, instead of waiting a set amount of time, wait specifically until a new item has entered the inventory. It would also be human-like to make it spam click piles, but I'd imagine that would be something I'd need to build down the road. Here's the updated bit of code:

    if (chicken != null && drops == null) { // If chickens are present and drops are not
                        log("In Chickens task, attacking");
                        chicken.interact("Attack");
                    }
    
                    if (drops != null) { // If chicken drops are present
                        log("In Chickens task, drops found, picking up");
                        drops.interact("Take");
                        sleep(2000, 3000);
                    }

     

    Link to comment
    Share on other sites

    Figured I should update with my progress. Here is the script currently... Right now working through issues with the cooking portion, I think I'll need to rework it as it's very buggy, but just wanted to leave the script code here in case anyone wanted to drop a few tips.

    Main file

    package src;
    
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.methods.skills.SkillTracker;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.impl.TaskScript;
    import tasks.Chickens;
    import tasks.BuryBones;
    import tasks.CookMeat;
    
    import java.awt.*;
    
    @ScriptManifest(name = "Chicken Chaser", description = "This Cheekin Chaysa hunts down chickens, picks up all their drops, buries bones, cooks chicken, banks, and returns to do it all over again.", author = "trtl",
            version = 1.0, category = Category.COMBAT, image = "VVeN1Lv.png")
    public class ChickenChaser extends TaskScript {
    
        @Override
        public void onStart() {
            // Start DreamBot's skill tracker for the hitpoints skill, so we can later see how much experience we've gained
            SkillTracker.start(Skill.HITPOINTS);
    
            log("Starting script");
    
            // Now add our three tasks so the client knows what to do
            addNodes(new Chickens(), new BuryBones(), new CookMeat());
        }
    
        @Override
        public void onPaint(Graphics g) {
            String experienceGainedText = String.format(
                    "HP Exp: %d (%d per hour)", // The paint's text format. '%d' will be replaced with the next two arguments.
                    SkillTracker.getGainedExperience(Skill.HITPOINTS),
                    SkillTracker.getGainedExperiencePerHour(Skill.HITPOINTS)
            );
    
            // Now we'll draw the text on the canvas at (5, 35). (0, 0) is the top left of the canvas.
            g.drawString(experienceGainedText, 5, 35);
        }
    
    }

     

    Chickens subtask

    package tasks;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.filter.Filter;
    import org.dreambot.api.methods.interactive.GameObjects;
    import org.dreambot.api.methods.interactive.NPCs;
    import org.dreambot.api.methods.item.GroundItems;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.walking.impl.Walking;
    import org.dreambot.api.script.TaskNode;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    
    public class Chickens extends TaskNode {
    
        final Area KILLBOX = new Area(3225, 3287, 3236, 3301);
    
        public static final String CHICKEN = "Chicken";
        public static final Filter<NPC> CHICKEN_FILTER = new Filter<NPC>() {
            @Override
            public boolean match(NPC npc) {
                if (npc == null){
                    return false;
                }
    
                return npc.getName().equals(CHICKEN) && !npc.isHealthBarVisible();
            }
        };
    
        @Override
        public boolean accept() {
            // If our inventory is not full, and we're in the right area
            return !Inventory.isFull() && (KILLBOX.contains(getLocalPlayer()));
        }
    
        @Override
        public int execute() {
            log("In Chickens task");
    
            GroundItem drops = GroundItems.closest("Feather", "Bones", "Raw chicken");
    
            if (getLocalPlayer().isInCombat()) {
                // Do nothing
            } else if (KILLBOX.contains(getLocalPlayer())) { // If player is in the box
                NPC chicken = NPCs.closest(CHICKEN_FILTER);
    
                    if (chicken != null && drops == null) { // If chickens are present and drops are not
                        log("In Chickens task, attacking");
                        chicken.interact("Attack");
                    }
    
                    if (drops != null) { // If chicken drops are present
                        log("In Chickens task, drops found, picking up");
                        drops.interact("Take");
                        sleep(640, 1650);
                    }
    
                } else {
                    Walking.walk(KILLBOX.getRandomTile());
                }
    
            return Calculations.random(300, 600);
        }
    
    }

     

    BuryBones subtask

    package tasks;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.interactive.GameObjects;
    import org.dreambot.api.script.TaskNode;
    import org.dreambot.api.wrappers.interactive.GameObject;
    
    public class BuryBones extends TaskNode {
    
        @Override
        public boolean accept() {
            // If our inventory is full we should bury the bones
            return Inventory.isFull() && Inventory.contains(526);
        }
    
        @Override
        public int execute() {
            log("In BuryBones task");
            // Bury bones
            while (Inventory.contains(526)) {
                Inventory.interact("Bones", "Bury");
                sleep(960, 1250);
            }
    
            return Calculations.random(300, 600);
        }
    
    }

     

    CookMeat subtask

    package tasks;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.dialogues.Dialogues;
    import org.dreambot.api.methods.interactive.GameObjects;
    import org.dreambot.api.methods.interactive.NPCs;
    import org.dreambot.api.methods.item.GroundItems;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.walking.impl.Walking;
    import org.dreambot.api.methods.widget.Widget;
    import org.dreambot.api.methods.widget.Widgets;
    import org.dreambot.api.script.TaskNode;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.Item;
    import org.dreambot.api.wrappers.widgets.WidgetChild;
    
    public class CookMeat extends TaskNode {
    
        final Area NEARSTAIRS = new Area(3207, 3227, 3213, 3228); // Area to move to access staircase in Lumbridge castle
    
        @Override
        public boolean accept() {
            // If our inventory is full and contains 26 raw chicken
            return Inventory.isFull() && Inventory.count("Raw chicken") == 26;
        }
    
        @Override
        public int execute() {
            log("In CookMeat task");
    
            // go to Lumbridge bank area, make fire with logs outside, cook raw chicken, drop burnt chicken
    
    //        if (getLocalPlayer().isAnimating(COOKING_ANIMATION)){
    //            // Do nothing
    //        } else {
            if (NEARSTAIRS.contains(getLocalPlayer())) { // If player is near the first set of stairs
                log("In CookMeat task, climbing first set of stairs");
                GameObjects.closest("Staircase").interact("Climb-up");
            } else if (getLocalPlayer().getTile().getZ() == 0) {
                log("In CookMeat task, walking toward stairs");
                if (Walking.getDestinationDistance() > Calculations.random(2, 5)) {
                    sleep(Calculations.random(900, 2750));
                } else {
                    Walking.walk(NEARSTAIRS.getRandomTile());
                }
    
            } else if (getLocalPlayer().getTile().getZ() == 1) {
                log("In CookMeat task, climbing second set of stairs");
                GameObjects.closest("Staircase").interact("Climb-up");
            } else if (getLocalPlayer().getTile().getZ() == 2) {
                log("In CookMeat task, should have climbed stairs by now");
                // time to light fire, cook, and bank
                if (GameObjects.closest("Fire") == null) {
                    log("In CookMeat task, lighting fire");
                    while (!getLocalPlayer().isAnimating()) {
                        GroundItems.closest("Logs").interact("Light");
                        sleep(2000, 3000);
                    }
                    if (getLocalPlayer().isAnimating()) {
                        sleep(2000, 10000);
                    }
                } else if (GameObjects.closest("Fire") != null) {
                    GameObject fire = GameObjects.closest("Fire");
                    log("In CookMeat task, cooking");
                    while (Inventory.contains("Raw chicken")) {
                        Inventory.get("Raw chicken").useOn(fire);
                        WidgetChild cookall = Widgets.getWidget(270).getChild(14).getChild(38);
                        if (cookall != null) {
                            cookall.interact("Cook");
                            sleepUntil(() -> !Inventory.contains("Raw chicken"), 30000);
                        }
                    }
                    if (!Inventory.contains("Raw chicken")) {
                        log("In CookMeat task, finished cooking");
                    }
                }
            }
    
            return Calculations.random(300, 600);
        }
    
    }

     

    I've made more progress than I was expecting overall, just have to work out the cooking kinks, setup the banking and walkback and then do a few runs to work out any other issues that are lingering. I know there are a few other issues, like sometimes it gets stuck at the chickens (probably from some poor checks) but that's what I have so far.

    Link to comment
    Share on other sites

    So I ended up scrapping my existing script so I could rebuild it as a state script. Hoping that will simplify things considering I generally only want to make simple scripts right now.

    Now I'm having a new issue where it doesn't leave the kill or loot state when it's in there. I've tried a few different things (code is probably a bit bloated/redundant now) and can't seem to figure out why it's not getting out of the loops. Any suggestions?

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.container.impl.bank.Bank;
    import org.dreambot.api.methods.filter.Filter;
    import org.dreambot.api.methods.interactive.NPCs;
    import org.dreambot.api.methods.item.GroundItems;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.walking.impl.Walking;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    
    import javax.swing.*;
    
    @ScriptManifest(author = "trtl", name = "Chicken Slayer", version = 1.0, description = "kill & loot chickens, bury bones, cook & bank", category = Category.COMBAT)
    public class main extends AbstractScript {
    
        public static final String CHICKEN = "Chicken";
        public static final Filter<NPC> CHICKEN_FILTER = new Filter<NPC>() {
            @Override
            public boolean match(NPC npc) {
                if (npc == null){
                    return false;
                }
    
                return npc.getName().equals(CHICKEN) && !npc.isHealthBarVisible();
            }
        };
    
        final Area KILLBOX = new Area(3225, 3287, 3236, 3301);
        final Area COOKINGPOT = new Area(3225,3289,3226,3291);
        final Area BANKBOX = new Area(3207,3219,3210,3220,2);
    
        boolean lootVisible = KILLBOX.contains(GroundItems.closest("Feather", "Bones", "Raw chicken"));
        boolean playerInBox = KILLBOX.contains(getLocalPlayer());
    
        public void onStart() {
            log("Welcome to Chicken Slayer by trtl");
        }
    
        private enum State {
            KILL, LOOT, BURY, COOK, BANK, RETURN, ERROR
        };
    
        private State getState() {
            if (!Inventory.isFull() && playerInBox && !lootVisible) {
                return State.KILL;
            }
            if (!Inventory.isFull() && playerInBox && lootVisible) {
                return State.LOOT;
            }
            if (Inventory.isFull() && Inventory.contains("Bones")) {
                return State.BURY;
            }
            if (Inventory.isFull() && Inventory.contains("Raw chicken") && !Inventory.contains("Bones")) {
                return State.COOK;
            }
            if (Inventory.isFull() && !Inventory.contains("Raw chicken")) {
                return State.BANK;
            }
            if (Inventory.isEmpty() && !playerInBox) {
                return State.RETURN;
            } else {
                return State.ERROR;
            }
        }
    
        public void onExit() {
            log("Collected x feathers and gained x experience!");
        }
    
        @Override
        public int onLoop() {
            switch (getState()) {
                case KILL:
                    log("in kill state");
                    while (!lootVisible) {
                        NPC chicken = NPCs.closest(CHICKEN_FILTER);
                        boolean lootVisible = KILLBOX.contains(GroundItems.closest("Feather", "Bones", "Raw chicken"));
                        log(lootVisible);
                        if (getLocalPlayer().isInCombat()) {
                            log("in combat, doing nothing");
                            sleep(1000);
                        } else if (chicken != null) {
                            log("attacking chicken");
                            sleep(1000);
                            chicken.interact("Attack");
                            sleep(2500);
                        }
                    }
                    break;
                case LOOT:
                    log("in loot state");
                    while (!Inventory.isFull() && lootVisible) {
                        log("looting items");
                        boolean lootVisible = KILLBOX.contains(GroundItems.closest("Feather", "Bones", "Raw chicken"));
                        log(lootVisible);
                        sleep(1000);
                        GroundItem drops = GroundItems.closest("Feather", "Bones", "Raw chicken");
                        if (drops != null) {
                            drops.interact("Take");
                            sleep(640, 1650);
                        }
                    }
                    break;
                case BURY:
                    log("in bury state");
                    while (Inventory.contains("Bones")) {
                        log("burying bones");
                        sleep(1000);
                        Inventory.interact("Bones", "Bury");
                        sleep(960, 1250);
                    }
                    break;
                case COOK:
                    log("in cook state");
                    if (Walking.getDestinationDistance() > Calculations.random(4, 6)) {
                        sleep(Calculations.random(900, 1500));
                    } else {
                        Walking.walk(COOKINGPOT.getRandomTile());
                    }
                    // need to code out cooking portion, dropping burnt chicken
                    break;
                case BANK:
                    log("in bank state");
                    if (Walking.getDestinationDistance() > Calculations.random(4, 6)) {
                        sleep(Calculations.random(900, 1500));
                    } else {
                        Walking.walk(BANKBOX.getRandomTile());
                    }
                    if (Bank.openClosest()) {
                        Bank.depositAllItems();
                    } else {
                        Bank.openClosest();
                        sleep(960, 1250);
                    }
                case RETURN:
                    log("in return state");
                    if (Walking.getDestinationDistance() > Calculations.random(4, 6)) {
                        sleep(Calculations.random(900, 1500));
                    } else {
                        Walking.walk(KILLBOX.getRandomTile());
                    }
                case ERROR:
                    log("in error state");
            }
            return Calculations.random(360, 640);
        }
    }

     

    Link to comment
    Share on other sites

    38 minutes ago, trtl said:

    So I ended up scrapping my existing script so I could rebuild it as a state script. Hoping that will simplify things considering I generally only want to make simple scripts right now.

    Now I'm having a new issue where it doesn't leave the kill or loot state when it's in there. I've tried a few different things (code is probably a bit bloated/redundant now) and can't seem to figure out why it's not getting out of the loops. Any suggestions?

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.container.impl.bank.Bank;
    import org.dreambot.api.methods.filter.Filter;
    import org.dreambot.api.methods.interactive.NPCs;
    import org.dreambot.api.methods.item.GroundItems;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.walking.impl.Walking;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    
    import javax.swing.*;
    
    @ScriptManifest(author = "trtl", name = "Chicken Slayer", version = 1.0, description = "kill & loot chickens, bury bones, cook & bank", category = Category.COMBAT)
    public class main extends AbstractScript {
    
        public static final String CHICKEN = "Chicken";
        public static final Filter<NPC> CHICKEN_FILTER = new Filter<NPC>() {
            @Override
            public boolean match(NPC npc) {
                if (npc == null){
                    return false;
                }
    
                return npc.getName().equals(CHICKEN) && !npc.isHealthBarVisible();
            }
        };
    
        final Area KILLBOX = new Area(3225, 3287, 3236, 3301);
        final Area COOKINGPOT = new Area(3225,3289,3226,3291);
        final Area BANKBOX = new Area(3207,3219,3210,3220,2);
    
        boolean lootVisible = KILLBOX.contains(GroundItems.closest("Feather", "Bones", "Raw chicken"));
        boolean playerInBox = KILLBOX.contains(getLocalPlayer());
    
        public void onStart() {
            log("Welcome to Chicken Slayer by trtl");
        }
    
        private enum State {
            KILL, LOOT, BURY, COOK, BANK, RETURN, ERROR
        };
    
        private State getState() {
            if (!Inventory.isFull() && playerInBox && !lootVisible) {
                return State.KILL;
            }
            if (!Inventory.isFull() && playerInBox && lootVisible) {
                return State.LOOT;
            }
            if (Inventory.isFull() && Inventory.contains("Bones")) {
                return State.BURY;
            }
            if (Inventory.isFull() && Inventory.contains("Raw chicken") && !Inventory.contains("Bones")) {
                return State.COOK;
            }
            if (Inventory.isFull() && !Inventory.contains("Raw chicken")) {
                return State.BANK;
            }
            if (Inventory.isEmpty() && !playerInBox) {
                return State.RETURN;
            } else {
                return State.ERROR;
            }
        }
    
        public void onExit() {
            log("Collected x feathers and gained x experience!");
        }
    
        @Override
        public int onLoop() {
            switch (getState()) {
                case KILL:
                    log("in kill state");
                    while (!lootVisible) {
                        NPC chicken = NPCs.closest(CHICKEN_FILTER);
                        boolean lootVisible = KILLBOX.contains(GroundItems.closest("Feather", "Bones", "Raw chicken"));
                        log(lootVisible);
                        if (getLocalPlayer().isInCombat()) {
                            log("in combat, doing nothing");
                            sleep(1000);
                        } else if (chicken != null) {
                            log("attacking chicken");
                            sleep(1000);
                            chicken.interact("Attack");
                            sleep(2500);
                        }
                    }
                    break;
                case LOOT:
                    log("in loot state");
                    while (!Inventory.isFull() && lootVisible) {
                        log("looting items");
                        boolean lootVisible = KILLBOX.contains(GroundItems.closest("Feather", "Bones", "Raw chicken"));
                        log(lootVisible);
                        sleep(1000);
                        GroundItem drops = GroundItems.closest("Feather", "Bones", "Raw chicken");
                        if (drops != null) {
                            drops.interact("Take");
                            sleep(640, 1650);
                        }
                    }
                    break;
                case BURY:
                    log("in bury state");
                    while (Inventory.contains("Bones")) {
                        log("burying bones");
                        sleep(1000);
                        Inventory.interact("Bones", "Bury");
                        sleep(960, 1250);
                    }
                    break;
                case COOK:
                    log("in cook state");
                    if (Walking.getDestinationDistance() > Calculations.random(4, 6)) {
                        sleep(Calculations.random(900, 1500));
                    } else {
                        Walking.walk(COOKINGPOT.getRandomTile());
                    }
                    // need to code out cooking portion, dropping burnt chicken
                    break;
                case BANK:
                    log("in bank state");
                    if (Walking.getDestinationDistance() > Calculations.random(4, 6)) {
                        sleep(Calculations.random(900, 1500));
                    } else {
                        Walking.walk(BANKBOX.getRandomTile());
                    }
                    if (Bank.openClosest()) {
                        Bank.depositAllItems();
                    } else {
                        Bank.openClosest();
                        sleep(960, 1250);
                    }
                case RETURN:
                    log("in return state");
                    if (Walking.getDestinationDistance() > Calculations.random(4, 6)) {
                        sleep(Calculations.random(900, 1500));
                    } else {
                        Walking.walk(KILLBOX.getRandomTile());
                    }
                case ERROR:
                    log("in error state");
            }
            return Calculations.random(360, 640);
        }
    }

     

    Generally speaking with scripts you'll want to avoid using loops (especially while) as you don't have full control of the full system (if you disconnect during a while loop, the script will be stuck forever). It's best to return from onLoop as often as possible and be able to pick up from the start of the onLoop at any possible starting state :)

    Link to comment
    Share on other sites

    1 hour ago, Pandemic said:

    Generally speaking with scripts you'll want to avoid using loops (especially while) as you don't have full control of the full system (if you disconnect during a while loop, the script will be stuck forever). It's best to return from onLoop as often as possible and be able to pick up from the start of the onLoop at any possible starting state :)

    Thank you for the suggestion. That makes a lot of sense. I've reworked it with that in mind (the goal of starting from the top of onLoop) and it's working much better now. I can make it a cycle or two before it messes something up so it's getting there.

    I was hoping you could elaborate on why the script might get stuck in something like the following:

    // Loot any lingering feathers
                if (Inventory.isFull() && featherLoot && !inCookingBox) {
                    log("Looting feathers");
                    while (featherLoot) {
                        GroundItem feathers = GroundItems.closest("Feather");
                        if (feathers != null) {
                            feathers.interact("Take");
                            sleep(640, 1650);
                        }
                    }
                }

     

    This is one of the hang-ups currently, and I know you said to try to avoid them, but I don't know if I can sometimes, and it would be helpful to understand the issue at hand a little better. Do I just need to handle the feathers declaration in a specific way? To me it seems like it should loop again and null out the variable, breaking the loop, but that doesn't seem to be happening right now.

    Link to comment
    Share on other sites

    Just now, trtl said:

    Thank you for the suggestion. That makes a lot of sense. I've reworked it with that in mind (the goal of starting from the top of onLoop) and it's working much better now. I can make it a cycle or two before it messes something up so it's getting there.

    I was hoping you could elaborate on why the script might get stuck in something like the following:

    // Loot any lingering feathers
                if (Inventory.isFull() && featherLoot && !inCookingBox) {
                    log("Looting feathers");
                    while (featherLoot) {
                        GroundItem feathers = GroundItems.closest("Feather");
                        if (feathers != null) {
                            feathers.interact("Take");
                            sleep(640, 1650);
                        }
                    }
                }

     

    This is one of the hang-ups currently, and I know you said to try to avoid them, but I don't know if I can sometimes, and it would be helpful to understand the issue at hand a little better. Do I just need to handle the feathers declaration in a specific way? To me it seems like it should loop again and null out the variable, breaking the loop, but that doesn't seem to be happening right now.

    Sure thing, but I'd advise against while loops specifically for scripting if it's touching the game at all as there are many things outside of your (and our) control.

    The reason that loop gets stuck forever is your featherLoot variable is never changing, you'd have to update it yourself at the end of the while loop so the next time it runs it can see it's no longer necessary :)

    Link to comment
    Share on other sites

    2 minutes ago, Pandemic said:

    Sure thing, but I'd advise against while loops specifically for scripting if it's touching the game at all as there are many things outside of your (and our) control.

    The reason that loop gets stuck forever is your featherLoot variable is never changing, you'd have to update it yourself at the end of the while loop so the next time it runs it can see it's no longer necessary :)

    AHHH of course haha I completely missed that. Thank you! Hopefully will have the kinks worked out soon enough.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.