Jump to content

First attempt Woodcutting bot


jrock1000

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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