Nuclear Nezz 1995 Share Posted March 17, 2015 I made a video tutorial of writing a script. I tried to keep it pretty basic and explain everything that I was doing. If I went through something too fast or didn't explain something in enough detail feel free to let me know and I'll expand on it. Video 1/4: Video 2/4: Video 3/4: Video 4/4: source: package nezz.dreambot.cowhider; import java.awt.Graphics; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.bank.BankLocation; import org.dreambot.api.methods.filter.Filter; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.walking.path.impl.LocalPath; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.utilities.impl.Condition; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.items.GroundItem; //so you want to start by creating your script skeleton @ScriptManifest(author = "Nezz", category = Category.MISC, description = "Gathers cow hides", name = "Dreambot Cowhider", version = 0) public class CowHider extends AbstractScript{ //okay so now we establish a few variables that we know we're going to need //since I know there will be two areas, I declare them //okay now we want to work on setting these areas. //to do that we'll use dreambot's debugging tools. //we need to know the tiles of the area so we'll use our player position. //so to create an area you do NW corner x/y, then SE corner x/y //the Z isn't required, if you don't give it a z it defaults to 0 private final Area BANK_AREA = new Area(3207,3220,3210,3216,2); private final Area COW_AREA = new Area(3253,3270,3265,3255);//now to get our cow area. //i'm going to do a smaller area simply for convenience. private final Tile IN_FRONT_OF_GATE = new Tile(3251,3266,0);//found the tile in front of gates private final Tile LUMBY_STAIRS = new Tile(3206,3228,0); private final Tile TOP_STAIRS = new Tile(3206,3228,2);//so the stairs are a bit far away so we'll set a tile private final Tile INSIDE_GATE = new Tile(3254,3267,0); private State state; //okay now that we have some of that settled, we can move on to setting up our states //so the states essentially dictate what piece of the script we're currently in private enum State{ BANK, WALK_TO_BANK, WALK_TO_COWS, PICK_UP; } //now we write our state getter, this essentially checks to see which state of the script you're //currently in private State getState(){ //if your inventory is full, you should either be walking to the bank or banking if(getInventory().isFull()){ if(BANK_AREA.contains(getLocalPlayer())){ return State.BANK; } else{ return State.WALK_TO_BANK; } } else{ //if it isn't full, you'll want to either be picking up hides or walking to the cows if(COW_AREA.contains(getLocalPlayer())){ return State.PICK_UP; } else{ return State.WALK_TO_COWS; } } } //okay now we have our state getter and whatnot, so we're ready to start setting up our loop public void onStart(){ } @Override public int onLoop() { //so if we're moving, check how far away your destination is //if your destination is more than 5 tiles away just sleep a bit. if(getLocalPlayer().isMoving()){ Tile dest = getClient().getDestination(); if(dest != null && getLocalPlayer().getTile().distance(dest) > 5){ return Calculations.random(200,400); } } //we should add a run energy check too! see all the fun things we think of if(!getWalking().isRunEnabled() && getWalking().getRunEnergy() > 70){ getWalking().toggleRun(); } //so you want to start by setting your current state state = getState(); //switch/case is similar to if/else if/else if/else except it's faster and generally looks //neater. switch(state){ //okay time to run it!? case BANK: //so this is our bank state, we know the gist of banking so we can do this no problem if(getBank().isOpen()){ //if the bank is open, just deposit everything. getBank().depositAllItems(); //woo another sleepUntil time sleepUntil(new Condition(){ public boolean verify(){ return getInventory().isEmpty(); } },Calculations.random(900,1200)); //this sleepUntil will sleep until your inventory is empty. } else{ //if it isn't open, open it! getBank().open(); //now we get into our first sleepUntil, this takes a Condition and a timeout as arguments //a Condition is an object that has a verify method, when it returns true the sleepUntil cuts out //or it'll wait until you reach the timeout sleepUntil(new Condition(){ public boolean verify(){ return getBank().isOpen(); } },Calculations.random(900,1200)); //so in that condition we set it to go until the bank is open, or 900-1200 milliseconds has passed } //the reak statement is required after each case otherwise it'll spill over into the next //this says to break out of your switch/case and to not continue on to the others. break; case PICK_UP: //this is where you'll be picking stuff up. //first you'll want to see if there's even a ground item available //good thing I checked :') final GroundItem hide = getGroundItems().closest(new Filter<GroundItem>(){ public boolean match(GroundItem gi){ if(gi == null || gi.getName() == null) return false; if(!gi.getName().equals("Cowhide")) return false; if(COW_AREA.contains(gi)) return true; return false; } });//I don't know if this is what it is //so I"ll have to check that when I actually sign in for data collection //"But what if it isn't in the area?" you may ask. //that's a good point. So we may want to throw a filter onto the ground items. if(hide != null){ //if it isn' tnull, then it exists and we should pick it up. //so coming back to this, we should probably only sleep if the interaction //was successful. So we change this to an if statement if(hide.interact("Take")){ //ezpz //so if the interaction was successful, sleep. //now we need some more sleepUntil stuff sleepUntil(new Condition(){ public boolean verify(){ return !hide.exists();//so we had to change hide to final because //we're using it in an inner class, and you can only access variables //from outside the inner class if it's final. //final essentially just means that once it's set, you can't change it. } },Calculations.random(1800,2400)); } } break; case WALK_TO_BANK: //okay now we also have all the data we need to get to the bank. //here's where we walk to the bank from the cow pen. //I know it'll essentially be separated into 3 parts if(getLocalPlayer().getTile().getZ() == 2){ //walk to the center of lumbridge //BankLocation is an enum inside of dreambot that contains //several banks around runescape. getWalking().walk(BankLocation.LUMBRIDGE.getCenter()); //walk into bank area } else if(getLocalPlayer().getTile().getZ() == 1){ GameObject stairs = getGameObjects().closest("Staircase"); if(stairs != null){ //make sure the stairs aren't null (generally null check everything) stairs.interact("Climb-up");//put the interaction in as specified in rs //more sleepUntils! sleepUntil(new Condition(){ public boolean verify(){ return getLocalPlayer().getTile().getZ() == 2; } },Calculations.random(2400,2800)); //so now we want to sleep utnil we're on floor 2 } //walk up the stairs } else{ if(COW_AREA.contains(getLocalPlayer())){ final GameObject gate = getGameObjects().closest(new Filter<GameObject>(){ public boolean match(GameObject go){ //so we want to check against the obvious things first if(go == null || go.getName() == null) return false; //I mean if it's null we don't want it. and if it's name is null we //sitll don't want it. if(!go.getName().equals("Gate")) return false; //if the name isn't Gate, we don't want it. if(!go.getTile().equals(new Tile(3253,3266,0))) return false; //so if the tile isn't that of the closed gate (notice closed gate //has a different tile than open) then we don't want it. //finally return true; return true; } }); if(gate != null){ //if it isn't null, then the closed gate is in the way and we should open it. if(gate.interact("Open")){ //more sleepUntils sleepUntil(new Condition(){ public boolean verify(){ return !gate.exists(); } },Calculations.random(1800,2400)); } } else{ getWalking().walk(IN_FRONT_OF_GATE); } //check if gate is closed //if it is, open it! } else if(getLocalPlayer().getTile().distance(LUMBY_STAIRS) > 5){ //otherwise walk to the lumby stairs. getWalking().walk(LUMBY_STAIRS); } else{ GameObject stairs = getGameObjects().closest("Staircase"); if(stairs != null){ //make sure the stairs aren't null (generally null check everything) stairs.interact("Climb-up");//put the interaction in as specified in rs //more sleepUntils! sleepUntil(new Condition(){ public boolean verify(){ return getLocalPlayer().getTile().getZ() == 1; } },Calculations.random(2400,2800)); //so now we want to sleep utnil we're on floor 1 } } //okay here if we're still in the cow area we'll have to check for //the gate //i'll wait til I'm in game for that I guess //if gate is open/you're past gate walk to lumby stairs } break; case WALK_TO_COWS: //this is the same thing as walk to bank but backwards, basically. //so we can just copy some of this code... if(getLocalPlayer().getTile().getZ() == 2){ if(getLocalPlayer().getTile().distance(TOP_STAIRS) > 5){ getWalking().walk(TOP_STAIRS); } else{ //now we get our stair object GameObject stairs = getGameObjects().closest("Staircase"); if(stairs != null){ //make sure the stairs aren't null (generally null check everything) stairs.interact("Climb-down");//put the interaction in as specified in rs //more sleepUntils! sleepUntil(new Condition(){ public boolean verify(){ return getLocalPlayer().getTile().getZ() == 1; } },Calculations.random(2400,2800)); //so now we want to sleep utnil we're on floor 1 } } //go down the top flight of stairs } else if(getLocalPlayer().getTile().getZ() == 1){ //okay we're on floor one, we can just copy some of the code up here.. //go down stairs GameObject stairs = getGameObjects().closest("Staircase"); if(stairs != null){ //make sure the stairs aren't null (generally null check everything) stairs.interact("Climb-down");//put the interaction in as specified in rs //more sleepUntils! sleepUntil(new Condition(){ public boolean verify(){ return getLocalPlayer().getTile().getZ() == 0; } },Calculations.random(2400,2800)); //so now we want to sleep utnil we're on floor 0 } } else{ //now time to walk over and get some more data wee if(getLocalPlayer().getTile().distance(IN_FRONT_OF_GATE) > 6){ //if you're not near the gate, just call walk. //walk is a web walker that is implemented into dreambot. //it has some issues with obstacles at the moment, so we have to do that ourselves. getWalking().walk(IN_FRONT_OF_GATE); } else{ //so now we get to use a Filter //this is fun //so a filter is exactly what it sounds like //it filters through the gameobjects until it finds one that passes true in your //match method final GameObject gate = getGameObjects().closest(new Filter<GameObject>(){ public boolean match(GameObject go){ //so we want to check against the obvious things first if(go == null || go.getName() == null) return false; //I mean if it's null we don't want it. and if it's name is null we //sitll don't want it. if(!go.getName().equals("Gate")) return false; //if the name isn't Gate, we don't want it. if(!go.getTile().equals(new Tile(3253,3266,0))) return false; //so if the tile isn't that of the closed gate (notice closed gate //has a different tile than open) then we don't want it. //finally return true; return true; } }); if(gate != null){ //if it isn't null, then the closed gate is in the way and we should open it. if(gate.interact("Open")){ //more sleepUntils sleepUntil(new Condition(){ public boolean verify(){ return !gate.exists(); } },Calculations.random(1800,2400)); } } else{ getWalking().walk(INSIDE_GATE); } //check for the gate //if the gate is there and open, open it. } //we'll need more gate checks here, too. //so if you're not even near the gate, we probably shouldn't have to worry about it //so we can probably get a tile at the gate to check for distances } break; } return Calculations.random(200,400); } public void onPaint(Graphics g){ } } DefCon, Shaqattack118, Fran and 6 others 9 Link to comment Share on other sites More sharing options...
James 256 Share Posted March 17, 2015 thank u now i will make an aio slayer script that does clue scrolls when they drop Fran, Epsilon, Nuclear Nezz and 2 others 5 Link to comment Share on other sites More sharing options...
Vlad 216 Share Posted March 17, 2015 Hacked by wydsquad. Nuclear Nezz 1 Link to comment Share on other sites More sharing options...
Pandemic 2469 Share Posted March 17, 2015 What'd you call me m8? Link to comment Share on other sites More sharing options...
FearJan 5 Share Posted March 21, 2015 can u make a tutorial for tb plz Link to comment Share on other sites More sharing options...
Nuclear Nezz 1995 Author Share Posted March 21, 2015 can u make a tutorial for tb plz no sry Link to comment Share on other sites More sharing options...
FearJan 5 Share Posted March 21, 2015 no sry its ok i forgive u Link to comment Share on other sites More sharing options...
G Ked 0 Share Posted March 26, 2015 Thanks Nezz. ^Rep Link to comment Share on other sites More sharing options...
bzmake 0 Share Posted April 18, 2015 Thanks very helpful, but it's VERY fast... Also, when I add a package to my script like: package BZmake It says it doesn't recognise my package, is it too small? jk No but srs, how do I fix this? Link to comment Share on other sites More sharing options...
Nuclear Nezz 1995 Author Share Posted April 19, 2015 Thanks very helpful, but it's VERY fast... Also, when I add a package to my script like: package BZmake It says it doesn't recognise my package, is it too small? jk No but srs, how do I fix this? could you give me a screen shot? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now