Elixar Posted March 14, 2019 Share Posted March 14, 2019 (edited) I'm learning the different types of script making. With this task based script I'm wondering why the <SlapCrabs> task only fights 1 npc then does nothing? ( testing on Highwayman, but the script will eventually be for crabs ) I know that you can use NPC filters and Lambda's ect. But for now I'm just trying to get this task to loop, It's supposed to fight highwaymen, But it only attacks 1 and then doesn't attack anymore after that? here is the SlapCrabs ( Not looping ) Task Main Why does it only kill 1 npc then stop? The canProcess() is true so it should attack as long as it's true?SlapCrabs package core; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.MethodProvider; public class SlapCrabs extends Task { public SlapCrabs(MethodProvider api) { super(api); } public static Area crabZone = new Area(3013, 3288, 2999, 3270); NPC npc = api.getNpcs().closest("Highwayman"); @Override public boolean canProcess() { return crabZone.contains(api.myPlayer()) && npc.isAttackable(); } @Override public void process() { npc.interact("Attack"); api.log("Slappin Crabz'"); } } Task package core; import org.osbot.rs07.script.MethodProvider; public abstract class Task { protected MethodProvider api; public Task(MethodProvider api) { this.api = api; } public abstract boolean canProcess(); public abstract void process(); public void run() { if (canProcess()) process(); } } Edited March 14, 2019 by Elixar Quote Link to comment Share on other sites More sharing options...
Hel Posted March 14, 2019 Share Posted March 14, 2019 (edited) 1 hour ago, Elixar said: I'm learning the different types of script making. With this task based script I'm wondering why the <SlapCrabs> task only fights 1 npc then does nothing? ( testing on Highwayman, but the script will eventually be for crabs ) I know that you can use NPC filters and Lambda's ect. But for now I'm just trying to get this task to loop, It's supposed to fight highwaymen, But it only attacks 1 and then doesn't attack anymore after that? here is the SlapCrabs ( Not looping ) Task Main Why does it only kill 1 npc then stop? The canProcess() is true so it should attack as long as it's true?SlapCrabs package core; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.MethodProvider; public class SlapCrabs extends Task { public SlapCrabs(MethodProvider api) { super(api); } public static Area crabZone = new Area(3013, 3288, 2999, 3270); NPC npc = api.getNpcs().closest("Highwayman"); @Override public boolean canProcess() { return crabZone.contains(api.myPlayer()) && npc.isAttackable(); } @Override public void process() { npc.interact("Attack"); api.log("Slappin Crabz'"); } } Task package core; import org.osbot.rs07.script.MethodProvider; public abstract class Task { protected MethodProvider api; public Task(MethodProvider api) { this.api = api; } public abstract boolean canProcess(); public abstract void process(); public void run() { if (canProcess()) process(); } } Main package core; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; import java.util.ArrayList; @ScriptManifest(author = "Elixar", info = "Fossil Island Crabs", logo = "https://i.imgur.com/tcvs0Wx.png", name = "Fossil Island Crabs", version = 0) public class Main extends Script { ArrayList<Task> tasks = new ArrayList<Task>(); private int slapped = 42; public String state = "Status: Idle"; @Override public void onStart() { tasks.add(new WalkToCrabs(this)); tasks.add(new SlapCrabs(this)); log("Task System:Loading Tasks..."); log("Task System:( ACTIVE )"); } @Override public void onExit() { log("ree"); } @Override public int onLoop() throws InterruptedException { tasks.forEach(tasks -> tasks.run()); return 700; } @Override public void onPaint(Graphics2D g) { super.onPaint(g); g.setColor(Color.CYAN); g.setFont(new Font("Trebuchet MS", Font.BOLD, 14)); g.drawString("Island Crabs 0.4", 8, 300);//X: 450 (left and right), Y: 345 (up and down) g.drawString("by Elixar", 8, 320); g.drawString("o", (int)getMouse().getPosition().getX() - 4, (int)getMouse().getPosition().getY() + 5); g.drawString(state, 8, 50); g.drawString("XP Gained: " + getExperienceTracker().getGainedXP(Skill.ATTACK) + " [lvl " + getExperienceTracker().getGainedLevels(Skill.ATTACK) + " ]", 8, 80); g.drawString("Slapped Crabs: " + slapped, 400, 320); } } ? ? It's because you're declaring the Highwayman outside of the run loop, so it essentially only searches once for an available highwayman, move the NPC npc = api.getNpcs().closest("Highwayman"); into the process method. edit: to summarize, the task actually is actually being checked,, but it's only searching for a highwayman when the class is initially loaded, so Npc#isAttackable returns false Edited March 14, 2019 by Slut 1 Quote Link to comment Share on other sites More sharing options...
Elixar Posted March 14, 2019 Author Share Posted March 14, 2019 (edited) Thank You! Edited March 16, 2019 by Elixar Quote Link to comment Share on other sites More sharing options...
HunterRS Posted March 14, 2019 Share Posted March 14, 2019 32 minutes ago, Elixar said: Oh my god you're 100% right. You literally just took so much stress off my mind Thank You! In the future, try placing some simple logs in your verify function (canProcess). For example, in this case simply adding: If (crabZone.contains(api.myPlayer()) log("contains") If (npc.isAttackable()) log("attackable") Would have greatly limit your bug searching to a specific area of the code and helped you figure out everything faster. Just some advice 1 Quote Link to comment Share on other sites More sharing options...