Ruzi Posted March 19, 2016 Posted March 19, 2016 So basically I have recently started to write scripts (yesterday).I have implemented the Node system and I wonder how I can sleep while something is finished. Let's say that I am chopping down a tree, how can I stop it from clicking while I am chopping? Here is a preview of my code: @ScriptManifest(author = "Ruzi", info = "WoodCutting", name = "WoodCutting", version = 1, logo = "") public class Main extends Script { private final int DELAY = 100; private List<Node> nodes = new ArrayList<>(); @Override public void onStart() { Area treeArea = new Area(3086, 3275, 3074, 3263); WalkToTreeArea walkToTreeArea = new WalkToTreeArea(this, treeArea); nodes.add(walkToTreeArea); ChopDown chopDown = new ChopDown(this, treeArea); nodes.add(chopDown); } @Override public int onLoop() throws InterruptedException { nodes.forEach(node -> { if(node.validate()) node.execute(); }); return DELAY; } @Override public void onExit() { } } public class ChopDown implements Node { private final int TREE_ID = 1276; private Script script; private Area treeArea; private Player player; private RS2Object tree; public ChopDown(Script script, Area treeArea) { this.script = script; this.treeArea = treeArea; this.player = script.myPlayer(); } @Override public void execute() { chopDown(); } private void chopDown() { tree = script.getObjects().closest(TREE_ID); if(tree != null){ tree.interact("Chop down"); } } @Override public boolean validate() { return !inventoryIsFull() && isAtTreeArea(); } private boolean inventoryIsFull() { return script.getInventory().isFull(); } private boolean isAtTreeArea() { return treeArea.contains(player); } } Thanks!
itzDot Posted March 19, 2016 Posted March 19, 2016 add !myplayer.isAnimating to your validate condition
Vilius Posted March 19, 2016 Posted March 19, 2016 (edited) Check if the player is animating or not if(!script.myPlayer().isAnimating()){ //chop } Edited March 19, 2016 by Vilius
Ruzi Posted March 19, 2016 Author Posted March 19, 2016 (edited) add !myplayer.isAnimating to your validate condition Check if the player is animating or not if(!script.myPlayer().isAnimating()){ //chop } Does this work for banking too? Thanks guys! Edited March 19, 2016 by Ruzi
Vilius Posted March 19, 2016 Posted March 19, 2016 Does this work for banking too? Thanks guys! I suppose it does, but I have no idea why would you want to check that, just do: if(!script.getBank().isOpen()){ //if closed open bank script.getBank().open(); }else{ //if open do banking, take stuff, deposit stuff. script.getBank().depositAll("Logs"); }
Ruzi Posted March 19, 2016 Author Posted March 19, 2016 I suppose it does, but I have no idea why would you want to check that, just do: if(!script.getBank().isOpen()){ //if closed open bank script.getBank().open(); }else{ //if open do banking, take stuff, deposit stuff. script.getBank().depositAll("Logs"); } It seems that I have to catch the exception: try { script.getBank().open(); } catch (InterruptedException e) { e.printStackTrace(); }
Acerd Posted March 19, 2016 Posted March 19, 2016 script.sleep(x); script.sleep(script.random(x,x)); MethodProvider.sleep(x); MethodProvider.sleep(MethodProvider.random(x,x));
Vilius Posted March 19, 2016 Posted March 19, 2016 It seems that I have to catch the exception: try { script.getBank().open(); } catch (InterruptedException e) { e.printStackTrace(); } Yep, you do need to do that, or just create your own interaction. 1