randalthor 6 Share Posted August 15, 2015 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 More sharing options...
Pandemic 2675 Share Posted August 16, 2015 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 More sharing options...
randalthor 6 Author Share Posted August 16, 2015 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 More sharing options...
randalthor 6 Author Share Posted August 25, 2015 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 More sharing options...
Pug 130 Share Posted August 25, 2015 Glad you found the error of your problems. locking Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.