longarm 0 Posted April 14, 2024 (edited) This is my first script - it simply kills chickens in Lumbridge and collects the feathers. I've ran it myself and it seems to work very well but I'm looking for some feedback from more experienced scripters. I use the ZenAntiBan code which seems to be from 2018 and might be cringe to use - I'm unsure. Let me know if this package is even worth including or if antiban as a whole is a worthless endeavor. Also, any feedback on my own code is greatly appreciated of course. https://github.com/erikisrad/chicken-bot Chickens.java Spoiler import org.dreambot.api.methods.interactive.Players; 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.utilities.Logger; import org.dreambot.api.utilities.Sleep; import org.dreambot.api.methods.dialogues.Dialogues; @ScriptManifest(name = "chicken-bot", description = "kills them birds", author = "longarm", version = 1.0, category = Category.MISC, image = "") public class Chickens extends AbstractScript { ZenAntiBan z; Utilities u; private final String creep_name = "Chicken"; private State state; private Target target_type; Area pen_area_small = new Area(3171, 3301, 3184, 3291, 0); Area pen_area_large = new Area(3169, 3307, 3185, 3288, 0); public void retreat(){ Area safety = new Area(3208, 3249, 3214,3244, 0); if(u.run_to_location(1, safety, -1)){ Logger.info("successfully retreated"); }else{ //if we hit this something is really fucked Logger.error("failed to retreat!"); } } @Override public void onStart() { z = new ZenAntiBan(this); u= new Utilities(); Logger.log("booting script..."); if(!Walking.isRunEnabled()){ Walking.toggleRun(); } } @Override public int onLoop(){ switch (getState()) { case CLOSING_DIALOGUE: Sleep.sleep(200, 400); Dialogues.spaceToContinue(); break; case RETREATING: retreat(); break; case IN_COMBAT: switch(u.check_target(creep_name)){ case DESIRED: case NO_TARGET: break; case UNDESIRED: Logger.warn("wtf is attacking us?"); retreat(); break; case UNREACHABLE: u.run_to_location(33, pen_area_small, 10000); u.attack_creep_in_area(creep_name, pen_area_large); break; } break; case WALKING_TO_PEN: if(u.run_to_location(33, pen_area_small, 10000)){ Logger.info("inside pen"); }else{ Logger.warn("still not in pen"); } break; case COLLECTING_AND_TARGETING: Sleep.sleep(z.antiBan()); if (!u.collect_item_if_near("Feather", 4, pen_area_large)){ if(u.attack_creep_in_area(creep_name, pen_area_large)){ Sleep.sleep(50, 120); } } break; case UNKNOWN: break; } return 100; } private State getState(){ if(Dialogues.canContinue() || Dialogues.inDialogue()){ Logger.log("closing dialogue"); state = State.CLOSING_DIALOGUE; }else if(Players.getLocal().getHealthPercent() < 33){ Logger.log("retreating"); state = State.RETREATING; }else if (Players.getLocal().isInCombat() && (Players.getLocal().getCharacterInteractingWithMe() != null)){ if(state != State.IN_COMBAT) { Logger.log("in combat"); } state = State.IN_COMBAT; }else if(!pen_area_large.contains(Players.getLocal().getTile())){ Logger.log("walking to pen"); state = State.WALKING_TO_PEN; }else if (!Players.getLocal().isInCombat() && !Players.getLocal().isMoving()){ Logger.log("collecting & targeting"); state = State.COLLECTING_AND_TARGETING; }else{ if(state != State.UNKNOWN) { Logger.info("waiting..."); } state = State.UNKNOWN; } return state; } } Utilities.java Spoiler import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.interactive.NPCs; import org.dreambot.api.methods.interactive.Players; 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.utilities.Logger; import org.dreambot.api.utilities.Sleep; import org.dreambot.api.wrappers.interactive.Character; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.items.GroundItem; import java.util.Objects; public class Utilities { //run to selected area, sprinting when above min_stamina //will return true if at desired area within timeout, false if timeout elapses //if timeout < 0, no timeout is used public boolean run_to_location(int min_stamina, Area location, int timeout_ms){ long run_start = System.currentTimeMillis(); long current_time; long last_move = 0; int move_interval; while(!location.contains(Players.getLocal().getTile())) { current_time = System.currentTimeMillis(); move_interval = check_stamina_and_run(min_stamina); //if method has run longer than timeout if (timeout_ms > 0 && (current_time - run_start) > timeout_ms){ Logger.warn("run method timed out"); return false; //else if has been longer than move interval or player isn't moving }else if ((current_time - last_move) > (move_interval + Calculations.random(100, 300)) || !Players.getLocal().isMoving()) { last_move = current_time; Walking.walk(location.getRandomTile()); Logger.debug("clicked to move"); } else { Logger.debug("too early to move"); Sleep.sleep(50); } } //double check, probably unneeded if(location.contains(Players.getLocal().getTile())){ Logger.info("arrived at location"); return true; }else{ Logger.warn("not in desired location"); return false; } } //attacks specified creep in specified area, returns true if engaged public boolean attack_creep_in_area(String creep_name, Area area){ NPC creep = NPCs.closest(c -> creep_name.equals(c.getName()) && !c.isInCombat() && c.canReach() && area.contains(c.getTile())); if (creep != null && creep.hasAction("Attack")) { Logger.info("starting attack on " + creep_name); creep.interact("Attack"); if (Sleep.sleepUntil(() -> (Players.getLocal().isInCombat()), 4000)){ Logger.info("fighting " + creep_name); return true; }else{ Logger.warn("timed out before fighting " + creep_name); return false; } }else{ Logger.warn("failed to find " + creep_name + "in area"); return false; } } public Target check_target(String creep_name){ Character aggressor = Players.getLocal().getCharacterInteractingWithMe(); if(aggressor != null && Players.getLocal().isInCombat() && aggressor.isInCombat()) { String aggressor_name = aggressor.getName(); if (Objects.equals(aggressor_name, creep_name)) { Logger.debug("in combat with " + creep_name); if (aggressor.canReach()){ return Target.DESIRED; }else{ Logger.warn(creep_name + " is unreachable"); return Target.UNREACHABLE; } } else { Logger.warn("in combat with an undesired " + aggressor_name); return Target.UNDESIRED; } }else{ Logger.warn("can't define aggressor"); return Target.NO_TARGET; } } public boolean collect_item_if_near(String item_name, int radius, Area area){ GroundItem near_item = GroundItems.closest( item -> item.isOnScreen() && item.getName().equals(item_name) && item.distance(Players.getLocal().getTile()) <= radius && item.canReach() && area.contains(item.getTile())); if (near_item != null && near_item.hasAction("Take")) { near_item.interact("Take"); if(Sleep.sleepUntil(() -> (!near_item.exists()), 4000)){ Logger.info("grabbed " + item_name); }else{ Logger.warn("couldn't grab " + item_name); } return true; }else{ Logger.info("didn't find any " + item_name + " within " + radius + " tiles"); return false; } } //turns sprint on if its off and youre above stamina minimum //returns a good click interval for movement methods based on if were sprinting private int check_stamina_and_run(int min_stamina){ boolean is_sprinting = Walking.isRunEnabled(); if ((Walking.getRunEnergy() > min_stamina) && !is_sprinting) { is_sprinting = Walking.toggleRun(); } if(is_sprinting){ return 2000; }else{ return 3000; } } } Edited April 14, 2024 by longarm
Dexter Bots 38 Posted April 18, 2024 looks good, when it run and have no bug its okay^^ because zen.. need a little api udatets, but works well i have, clone some thing, but not all, i override the ideas.
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