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
  • Newb, first simple script, any advice appreciated.


    Buddy Nugs

    Recommended Posts

    Hey guys, so after sluething the tutorials and talking to some scripters ive finally gotten what i think is a decent skeleton.\\

    package wcer;
    
    import java.awt.Graphics;
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    
    
    @ScriptManifest(author = "Buddy Nugs", category = Category.WOODCUTTING, description = "Power trains at lumbridge lake!", name = "Willow Buddy", version = 0.1)
    public class Main extends AbstractScript {
    	
    	int speed = Calculations.random(0, 80);
    	int distance = Calculations.random(3, 9);
    	
    	private enum scriptState {
    		START, OPEN_BANK, BANK, CLOSE_BANK, CHOP, DROP
    	}
    	
    	private scriptState state = scriptState.START;
    	
    
    	
    	@Override
    	public int onLoop() {
    		switch(state){
    		case START:
    			return Start();
    		case OPEN_BANK:
    			return OpenBank();
    		case BANK:
    			return Bank();
    		case CLOSE_BANK:
    			return CloseBank();
    			
    	}
    }
    
    

    And now im stuck.

     

    I have my statements made, and i know that i need to define them. but all i want to know is ho to walk a path?

     

    So, that when the script starts the player goes there. I've seen it done with weird bank area tile path movements in Nezz's videos.

     

     

    Thanks.

    Link to comment
    Share on other sites

    Walk a path? Walking to the bank and back? There are a few ways to do that. Easiest is to just use the built in webwalker. Define an area for your bank and where you are cutting and have the client walk to those areas.

    Link to comment
    Share on other sites

    Walk a path? Walking to the bank and back? There are a few ways to do that. Easiest is to just use the built in webwalker. Define an area for your bank and where you are cutting and have the client walk to those areas.

    Another scripter gavve me this code to work with walking:

    Area defendArea = new Area(2650, 2598, 2663, 2586);
    : if(getWalking().shouldWalk()) 
                          getWalking().walk(defendArea.getCenter());
    

    with those co ords being examples.

     

    I just want the scrpt to start, run to my destnation, and power chop willows. after getting some sleep I think i iknow what to do.

     

     

    Im using eclipse, does that have the built in webwalker you speak of?

     

     

    EDIT: Newly written: https://pastebin.com/t42hMJVK    I'm still trying to define chop and drop and cases. Here are my 13 errors:  

     

    Description Resource Path Location Type

    CHOP cannot be resolved or is not a field Main.java /Willow Buddy/src line 42 Java Problem
    CHOP cannot be resolved or is not a field Main.java /Willow Buddy/src line 54 Java Problem
    DROP cannot be resolved or is not a field Main.java /Willow Buddy/src line 40 Java Problem
    DROP cannot be resolved or is not a field Main.java /Willow Buddy/src line 60 Java Problem
    Return type for the method is missing Main.java /Willow Buddy/src line 29 Java Problem
    Syntax error on token ":", { expected Main.java /Willow Buddy/src line 27 Java Problem
    Syntax error on token ".", { expected Main.java /Willow Buddy/src line 29 Java Problem
    Syntax error on token ")", ; expected Main.java /Willow Buddy/src line 29 Java Problem
    Syntax error on token(s), misplaced construct(s) Main.java /Willow Buddy/src line 27 Java Problem
    Syntax error, insert ";" to complete Statement Main.java /Willow Buddy/src line 34 Java Problem
    Syntax error, insert ";" to complete Statement Main.java /Willow Buddy/src line 48 Java Problem
    Syntax error, insert "}" to complete MethodBody Main.java /Willow Buddy/src line 30 Java Problem
    The method shouldWalk() is undefined for the type Main Main.java /Willow Buddy/src line 29 Java Problem
    Link to comment
    Share on other sites

    So don't really know what your script is attempting to do but I did my best to guess. I have hardly used states at all but it should work now. No idea how to use shouldwalk method so I gave you an option that uses something else. As for the original question you were wondering about how to walk a path, you can just use getwalking.walk(Area.getRandomTile). The area in that can be other things too be I find it simplest to just use the area. Eclipse won't inhibit the ability to use dreambots webwalker. 

    import java.awt.Graphics;
    import java.lang.Thread.State;
    
    import org.dreambot.api.methods.Calculations;
    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.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    
    @ScriptManifest(author = "Buddy Nugs", category = Category.WOODCUTTING, description = "Power trains at lumbridge lake!", name = "Willow Buddy", version = 0.1)
    public abstract class Main extends AbstractScript {
    
    private static final State CHOP = null;
    int speed = Calculations.random(0, 80);
    int distance = Calculations.random(3, 9);
    
    private enum State {
    START, CHOP, DROP, WALK, WAIT
    }
    
    public void onStart() {
    log("Welcome to Willow Buddy, a script by Buddy Nugs.");
    log("This script will train Willows, if you have issues please use the forums");
    }
    
    //private scriptState state = scriptState.START;
    
    Area defendArea = new Area(3163, 3269, 3164, 3267);
    
    
    private State getState() {
    GameObject tree = getGameObjects().closest("Willow");
    if (!getInventory().isEmpty()) {
    return State.DROP;
    }
    if (tree != null) {
    return State.CHOP;
    }
    
    if (!defendArea.contains(getLocalPlayer())) {
    return State.WALK;
    }
    return State.WAIT;
    }
    
    @Override
    public int onLoop() {
    State state = getState();
    switch (state) {
    case WALK:
    /*if(getWalking().shouldWalk()) {
    getWalking().walk(defendArea.getRandomTile());*/
    
    /* or */
    
    /*if (getLocalPlayer().distance(defendArea.getCenter()) > Calculations.random(6, 9) && getLocalPlayer() != null) {
    getWalking().walk(defendArea.getRandomTile());
    sleepUntil(() -> !getLocalPlayer().isMoving(), Calculations.random(2000, 3000));
    }*/
    break;
    
    case CHOP:
    // code to chop
    break;
    case DROP:
    // code to drop
    break;
    case WAIT:
    // code to wait
    break;
    }
    return Calculations.random(500, 600);
    }
    
    
    public void onExit() {
    log("Thanks, Chop Chop!");
    log("Please be sure to update thread with glitches!");
    
    }
    }
    
    Link to comment
    Share on other sites

    I rewrote portions of your script to be more understandable. I much prefer the node structure but for a script like this, states are fine.

     

    If you add areas, and implement the chopping/banking, this should work.

    import java.awt.Graphics;
    import java.lang.Thread.State;
     
    import org.dreambot.api.methods.Calculations;
    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.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
     
    @ScriptManifest(author = "Buddy Nugs", category = Category.WOODCUTTING, description = "Power trains at lumbridge lake!", name = "Willow Buddy", version = 0.1)
    
    public class Main extends AbstractScript {
       
        private String state;
        private Area treeArea = new Area(0, 0, 0, 0); //DEFINE THIS FOR BANKING  
        private Area bankArea = new Area(0, 0, 0, 0); //DEFINE THIS FOR BANKING
    
        public void onStart() {
            log("Welcome to Willow Buddy, a script by Buddy Nugs.");
            log("This script will train Willows, if you have issues please use the forums");
        }
        
        //For banking
        private String getState() {
            if (getInventory().isFull()) {
                if (bankArea.contains(getLocalPlayer().getTile())) {
                    return "BANK";        
                } else {
                    return "WALKTOBANK";
                }
            } else {
                if (treeArea.contains(getLocalPlayer().getTile())) {
                    return "CHOP";
                } else {
                    return "WALKTOTREES";
                }
            }
        }
     
        public void onExit() {
            log("Thanks, Chop Chop!");
            log("Please be sure to update thread with glitches!");
        }
     
        @Override
        public int onLoop() {
            switch (getState()) {
                case "BANK":
                    doBank();
                    break;
                case "WALKTOBANK":
                    getWalking().walk(bankArea.getRandomTile());
                    sleep(1500,3000);
                    break;
                case "CHOP":
                    doChop();
                    break;
                case "WALKTOTREES":
                    getWalking().walk(treeArea.getRandomTile());
                    sleep(1500,3000);
                    break;
            }
            return Calculations.random(250, 750);
        }
    
        private void doChop() {
            //Implement your chopping method here, don't chop if you are already chopping, etc
        }
    
        private void doBank() {
            //Implement banking method here
        }
    }
    
    Link to comment
    Share on other sites

     

    I rewrote portions of your script to be more understandable. I much prefer the node structure but for a script like this, states are fine.

     

    If you add areas, and implement the chopping/banking, this should work.

    why did u create a tree object in getState that was never used???

     

    why does state/speed/distance have the private modifier but the area fields don't have any access modifier at all?

     

    I never understood states, why don't people just do ifs xddd

    example: 

    gloqdGs.png

    imo states just make shit clunky for no reason, feel free to try to explain to me why they r cleaner

     

    edit: grammar 

    Link to comment
    Share on other sites

    why did u create a tree object in getState that was never used???

     

    why does state/speed/distance have the private modifier but the area fields don't have any access modifier at all?

     

    I never understood states, why don't people just do ifs xddd

    example: 

    gloqdGs.png

    imo states just make shit clunky for no reason, feel free to try to explain to me why they r cleaner

     

    edit: grammar 

     

    The tree object was already there from his code, I have now removed it. He was using the tree object being valid to determine whether he should chop.

     

    I have moved the Areas to where fields should be and added private access modifiers. I also removed speed/distance since my example doesn't use them.   :)

     

    Also, I don't use states, even in the simplest of scripts. I feel that the node framework is much easier to debug, although it may take more time to code initially. 

     

    States are preferred to a bunch of if statements everywhere because they are generally easier to read/debug. You can also paint your state to assist in debugging if you are running into problems (e.g. the script state is CHOP but your inventory is full).

     

    As scripts get more and more complex, if statements would be impractical with print lines everywhere to debug. Similarly, as far as states go, as scripts get even more complex, nodes become a better option because scripts using this framework are far easier to debug IMO.

    Link to comment
    Share on other sites

     

    States are preferred to a bunch of if statements everywhere because they are generally easier to read/debug. You can also paint your state to assist in debugging if you are running into problems (e.g. the script state is CHOP but your inventory is full).

     

    As scripts get more and more complex, if statements would be impractical with print lines everywhere to debug. Similarly, as far as states go, as scripts get even more complex, nodes become a better option because scripts using this framework are far easier to debug IMO.

    Even for larger scripts it doesn't get messy as long as you don't write spaghetti code. And I agree, a node framework can be powerful, but a simple state system such as this i don't see practical.

     

    58Okxuo.png

     

    I understand that blastfurnace isn't really considered a 'large' script, but nonetheless, it still shows that you can write clean code that does not require states.

     

    But i guess if you really care about status' you can just have a string variable and set it once you know, instead of just relying on said string to be a state.

    Link to comment
    Share on other sites

    Even for larger scripts it doesn't get messy as long as you don't write spaghetti code. And I agree, a node framework can be powerful, but a simple state system such as this i don't see practical.

     

    58Okxuo.png

     

    I understand that blastfurnace isn't really considered a 'large' script, but nonetheless, it still shows that you can write clean code that does not require states.

     

    But i guess if you really care about status' you can just have a string variable and set it once you know, instead of just relying on said string to be a state.

     

    This is very true. I think it just boils down to maintainability - so scripters should use whatever framework they are most comfortable with.  :)

    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.