dreamwiver 12 Share Posted December 26, 2022 Hello, I'm trying to learn the fundamentals of the TaskScript, but I'm failing at creating a very simple script, which kills a hill giant and loots his bones. So far I don't care what would happen when the inventory gets full. These are the files: MainClass package Slayer; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.script.TaskNode; import org.dreambot.api.script.impl.TaskScript; import org.dreambot.core.Instance; import java.awt.*; @ScriptManifest(version = 1.0, author="tpm", category = Category.SLAYER, name="Giant slayer") public class MainClass extends TaskScript { @Override public void onStart() { addNodes(new AttackNode(), new LootNode()); } public void onPaint(Graphics2D g) { TaskNode previousNode = getLastTaskNode(); g.drawString("State: " + previousNode.getClass().getName() ,12,77); } } Attack node package Slayer; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Shop; 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.script.TaskNode; import org.dreambot.api.wrappers.interactive.NPC; public class AttackNode extends TaskNode { @Override public int priority() { return 1; } @Override public boolean accept() { return true; } @Override public int execute() { if (NPCs.closest("Hill Giant") != null) { NPC giant = NPCs.closest("Hill Giant"); if (!giant.isInCombat()) { giant.interact("Attack"); sleepUntil(() -> !giant.isMinimapDot() && Players.getLocal().getSurroundingArea(1).contains(GroundItems.closest("Big bones")), 5000, 5000); } } return Calculations.random(500, 2000); } } LootNode package Slayer; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.methods.item.GroundItems; import org.dreambot.api.script.TaskNode; import org.dreambot.api.wrappers.items.GroundItem; public class LootNode extends TaskNode { @Override public int priority(){ return 2; } @Override public boolean accept() { if (Players.getLocal().isInCombat()) return false; return (GroundItems.closest("Big bones") != null && (Players.getLocal().distance(GroundItems.closest("Big bones")) < 3)); } @Override public int execute() { GroundItem bones = GroundItems.closest("Big bones"); if(bones != null) bones.interact("Take"); return Calculations.random(500, 2000); } } I would like the script to kill the giant, pick his bone, and seek another giant and so on, but so far I just managed to only killing, not picking up any bones. I imagine I'm failing to understand the concept of the sleepUntil. Any suggestions will be pretty much appreciated Thank you Link to comment Share on other sites More sharing options...
Genius 49 Share Posted December 27, 2022 (edited) package Slayer; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Shop; 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.script.TaskNode; import org.dreambot.api.wrappers.interactive.NPC; public class AttackNode extends TaskNode { @Override public int priority() { return 1; } @Override public boolean accept() { return !Players.Local.isInCombat(); //don't always return true here } @Override public int execute() { //check out filters. Make sure the "G" in giant is supposed to be capitalized NPC giant = NPCs.closest(g -> g != null && g.getName().equals("Hill Giant") && !g.isInCombat()); if (giant != null) { //giant isn't null, all conditions in filter are met if (giant.interact("Attack")) { //attack the giant sleep(1500,3500); //prevent spam clicking sleepUntil(() -> !Players.getLocal().isInCombat() && GroundItems.closest(b -> b.distance(Players.getLocal().getTile()) < 2 && b.getName().equals("Big bones")) != null, 30000, 50); //sleep until we are not in combat, big bones are less than distance 2 from us (should be 1 if we are meleeing), OR a maximum of 30 seconds. Sleepuntil will check the boolean conditions every 50ms. } } return Calculations.random(500, 2000); } } LootNode package Slayer; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.methods.item.GroundItems; import org.dreambot.api.script.TaskNode; import org.dreambot.api.wrappers.items.GroundItem; public class LootNode extends TaskNode { @Override public int priority(){ return 2; } @Override public boolean accept() { //consolidated into one line return (!Players.getLocal().isInCombat && GroundItems.closest(b -> b.distance(Players.getLocal().getTile()) < 2 && b.getName().equals("Big bones")) != null); } @Override public int execute() { GroundItem bones = GroundItems.closest(b -> b != null && b.distance(Players.getLocal().getTile()) < 2 && b.getName().equals("Big bones")); if(bones != null) { //if bones arent null, all filter conditions above must be true int temp = Inventory.count(b -> b != null && b.getName().equals("Big bones")); //get current count of inventory bones if (bones.interact("Take")) { //if we successfully interact with bones sleepUntil(() -> Inventory.count(b -> b != null && b.getName().equals("Big bones")) > temp, 5000, 50); //sleep until we have more bones than we did when we interacted with the bones on the ground, or 5 seconds max. } } return Calculations.random(500, 2000); } } I believe it is never being called because the sleepuntil needs a little work. The loot is never getting a chance to execute. It would also help to add an actual condition to the attack accept(). I have changed the code around a bit and added comments. Please let me know if you still are having trouble with this. I typed this here, so my apologies for the formatting. Let me know if this doesn't compile for some reason. Edited December 27, 2022 by Genius Link to comment Share on other sites More sharing options...
dreamwiver 12 Author Share Posted December 27, 2022 Hello @Genius, Indeed my problem was the sleepUntil. Thank you! Genius 1 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