jrock1000 Posted September 27, 2015 Share Posted September 27, 2015 Hey guys, I am working on my first woodcutting bot and it seems work but my problem is that if it clicks a tree, it also click another tree. So sometimes it walks between two trees but idk what the problem is. import org.osbot.rs07.api.Inventory; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Jrock", info = "My first script", name = "JWoodcutter", version = 0.01, logo = "") public class main extends Script { String tree = "Tree"; @Override public void onStart() { log("Let's get started with JWoodcutter"); } @Override public int onLoop() throws InterruptedException { Inventory invent = inventory.getInventory(); if(!invent.isFull() && !myPlayer().isAnimating()) chopping { Entity treeEntity = objects.closest(tree); if(treeEntity != null) { treeEntity.interact("Chop down"); } } return random(200, 300); } @Override public void onExit() { log("Thanks for running my Woodcutter!"); } @Override public void onPaint(Graphics2D g) { } } Kind Regards, Jrock1000 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted September 27, 2015 Share Posted September 27, 2015 To understand why this fully works, you need to (somewhat) understand how OSRS works as well as how the OSBot API works. I'll explain both the theory and the solution, but I'll put the theory in a spoiler so you don't have to read it. Theory: In RS, actions work on a tick-based system. Each tick lasts approximately 2/3 of a second (let's just call it 0.6 seconds), which means that if you click, it wont actually run until the next game tick (anywhere between 0.001 and 0.6 seconds if you think about it). In the perspective of a game tick, you'd be clicking this tree 2-3 times per game tick. Lastly, as far as OSBot goes, the #closest() method works by counting the amount of tiles between you and the object, not the actual distance. This means that an object that is technically further away from you (diagonal vs pure horizontal; our main man Pythagoras proves this) is counted as the same distance. Your solution would be to tag your tree in a variable, like so: //Global var Entity tree; //onLoop if (tree == null || !tree.exists()) { tree = getObjects().closest("Tree"); if (!tree.isVisible()) getCamera().toEntity(tree); tree.interact("Chop down"); } 1 Quote Link to comment Share on other sites More sharing options...
jrock1000 Posted September 27, 2015 Author Share Posted September 27, 2015 Aaaaaah yeah forgot about that Thanks! Quote Link to comment Share on other sites More sharing options...