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
  • chicken fighter doesn't run when "start" is pressed


    randalthor

    Recommended Posts

    any advice about the problem or general improvement is appreciated

     

    Script:

     

     

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.filter.Filter;
    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 org.dreambot.api.methods.skills.SkillTracker;
    import org.dreambot.api.methods.skills.Skill;
    
    
    @ScriptManifest(author = "Rand", name = "ChickenFighter", version = 1.0, description = "AttacksChickens", category = Category.COMBAT)
    public class main extends AbstractScript {
    public static int runEnergy = 0;
    public SkillTracker skills = new SkillTracker(getClient());
    
    public void onStart() {
    log("Welcome to ChickenFighter 1.0");
    log("Loots feathers, toggles run, avoids unreachable targets");
    skills.start();
    }
    
    public void onExit() {
    log("Thank you for using ChickenFighter 1.0");
    log("you gained " + skills.getGainedExperience(Skill.ATTACK) + ", " + skills.getGainedExperience(Skill.STRENGTH)
    + ", " + skills.getGainedExperience(Skill.DEFENCE) + ", " + skills.getGainedExperience(Skill.HITPOINTS) +
    " attack, strength, defense, and hitpoints xp");
    }
    
    @Override
    public int onLoop() {
    runAntiban();
    if (!getLocalPlayer().isInCombat()) { //player is not fighting currently
    if (Calculations.random(3) > 2) { //chooses to pickup feather 1/4 of the time
    pickupFeather();
    }
    NPC chicken = getNpcs().closest(new Filter<NPC>() { //finds closest chicken not in combat that is reachable
    @Override
    public boolean match(NPC npc) {
    return npc != null && npc.getName().equals("Chicken") && npc.getActions().length > 0 && !npc.isInCombat() && getMap().canReach(npc);
    }
    });  //closing parentheses for filter object that was created
    chicken.interact("Attack"); //attack closest chicken that matches filter
    }
    return Calculations.random(500, 600);
    }
    
    //enable run randomly based on global variable
    public void runAntiban() {
    if((getWalking().getRunEnergy() > runEnergy) && !getWalking().isRunEnabled()) {
    getWalking().toggleRun();
    runEnergy = Calculations.random(0, 90);
    }
    }
    
    //picks up closest feathers
    public void pickupFeather() {
    GroundItem feather = getGroundItems().closest(new Filter<GroundItem>() {
    @Override
    public boolean match (GroundItem target) {
    return target.getName().equals("Feather") && getMap().canReach(target);
    }
    });
    if (Calculations.random(2) > 0) { //do 2/3 of the time
    feather.interact("Take");
    } else {
    feather.interactForceRight("Take"); //do 1/3 of the time
    }
    }
    }
    
    

     

     

    Link to comment
    Share on other sites

    if (Calculations.random(3) > 2) { //chooses to pickup feather 1/4 of the time
    

    This will never activate, random(3) return 0, 1, or 2.

     

    You should also make sure chicken isn't null before interacting, or you're script will throw an NPE and stop working :)

    Link to comment
    Share on other sites

    if (Calculations.random(3) > 2) { //chooses to pickup feather 1/4 of the time
    

    This will never activate, random(3) return 0, 1, or 2.

     

    You should also make sure chicken isn't null before interacting, or you're script will throw an NPE and stop working :)

     

    http://dreambot.org/javadocs/

    random(int high)

    Returns a number between 0 (inclusive) and high (inclusive)   i know that for random but the method description showed it was inclusive for the random function in the calculations Class. In what case would the chicken be null? Is that when you can't find any chickens that fill the filter requirements?

    Updated still won't run on start does this pastebin link work?

    http://pastebin.com/5E5UL0sG

     

     
     

     

     

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.filter.Filter;
    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 org.dreambot.api.methods.skills.SkillTracker;
    import org.dreambot.api.methods.skills.Skill;
    
    
    
    
    @ScriptManifest(author = "Rand", name = "ChickenFighter", version = 1.0, description = "AttacksChickens", category = Category.COMBAT)
    public class main extends AbstractScript {
    public static int runEnergy = 0;
    public SkillTracker skills = new SkillTracker(getClient());
    
    
    public void onStart() {
    log("Welcome to ChickenFighter 1.0");
    log("Loots feathers, toggles run, avoids unreachable targets");
    skills.start();
    }
    
    
    public void onExit() {
    log("Thank you for using ChickenFighter 1.0");
    log("you gained " + skills.getGainedExperience(Skill.ATTACK) + ", " + skills.getGainedExperience(Skill.STRENGTH)
    + ", " + skills.getGainedExperience(Skill.DEFENCE) + ", " + skills.getGainedExperience(Skill.HITPOINTS) +
    " attack, strength, defense, and hitpoints xp");
    }
    
    
    @Override
    public int onLoop() {
    runAntiban();
    if (!getLocalPlayer().isInCombat()) { //player is not fighting currently
    if (Calculations.random(3) > 2) { //chooses to pickup feather 1/4 of the time
    pickupFeather();
    }
    NPC chicken = getNpcs().closest(new Filter<NPC>() { //finds closest chicken not in combat that is reachable
    @Override
    public boolean match(NPC npc) {
    return npc != null && npc.getName().equals("Chicken") && npc.getActions().length > 0 && !npc.isInCombat() && getMap().canReach(npc);
    }
    });  //closing parentheses for filter object that was created
    if (chicken != null)
    chicken.interact("Attack"); //attack closest chicken that matches filter
    }
    return Calculations.random(500, 600);
    }
    
    
    //enable run randomly based on global variable
    public void runAntiban() {
    if((getWalking().getRunEnergy() > runEnergy) && !getWalking().isRunEnabled()) {
    getWalking().toggleRun();
    runEnergy = Calculations.random(0, 90);
    } 
    }
    
    
    //picks up closest feathers
    public void pickupFeather() {
    GroundItem feather = getGroundItems().closest(new Filter<GroundItem>() {
    @Override
    public boolean match (GroundItem target) {
    return target.getName().equals("Feather") && getMap().canReach(target);
    }
    });
    if(feather != null) {
    if (Calculations.random(2) > 0) { //do 2/3 of the time
    feather.interact("Take");
    } else {
    feather.interactForceRight("Take"); //do 1/3 of the time
    }
    }
    } 
    }

     

     

    Link to comment
    Share on other sites

    • 2 weeks later...

    I did not see an option to delete this thread. Any developer feel free to do so. I believe the information here is not useful to most people. The problem was multiple errors in my script visible in tools> debugging>debug console on the dreambot console. These errors stopped my script running.

    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.