Jump to content

First attempt Woodcutting bot


Recommended Posts

Posted

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

Posted

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");
}
  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...