Jump to content

Having some hover problems


GaetanoH

Recommended Posts

So sometimes the scripts actually hovers the tree which is being cut, which I do not want and it's really inefficient. Can't really seem to fix it.

if (getObjects().getAll().stream().filter(o -> o.getName().equals(gui.getTree())).count() >= 2) {
       if (nextTree == null || !nextTree.exists()) {
             nextTree = getObjects().closest(true, o -> o.getName().equals(gui.getTree()) && o != treeObject &&
                     cuttingArea.contains(o) && o.getPosition() != treeObject.getPosition());
       } else if (!getMouse().isOnCursor(nextTree)) {
           nextTree.hover();
  }
}
Link to comment
Share on other sites

Well, if I understand the context right, treeObject is supposed to be the current tree? If the value of nextTree is not assigned anywhere else then the code looks alright but you might be wrongly setting treeObject to the next tree that you want to cut somewhere else in the code and nextTree will be set to the one you are already cutting. Don't forget to treat the exception where your nextTree will be cut by another person before you get to switch trees.

Link to comment
Share on other sites

 

So sometimes the scripts actually hovers the tree which is being cut, which I do not want and it's really inefficient. Can't really seem to fix it.

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "Explv", name = "Example hover", info = "", version = 0.1, logo = "")
public class Example extends Script {

    private enum State { CHOPPING, HOVERING }

    private RS2Object chopTree;

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
            case CHOPPING:
                chop();
                break;
            case HOVERING:
                hover();
                break;         
        }
        return random(200, 300);
    }

    private State getState() {
        if(chopTree == null || !chopTree.exists() || !myPlayer().isAnimating()) return State.CHOPPING;
        return State.HOVERING;
    }

    private void chop() {
        chopTree = getObjects().closest("Tree");
        if(chopTree != null && chopTree.interact("Chop down")) {
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return !chopTree.exists() || myPlayer().isAnimating();
                }
            }.sleep();
        }
    }

    private void hover() {
        RS2Object hoverTree = getObjects().closest(obj -> obj.getName().equals("Tree") && obj != chopTree);
        if(hoverTree != null && !getMouse().isOnCursor(hoverTree)) {         
            hoverTree.hover();
        }
    }
}

The logic is pretty simple:

 

If the player is not woodcutting, find closest tree and chop it

Else find the closest tree, that is not equal to the tree the player is chopping and hover it

Edited by Explv
  • Like 2
Link to comment
Share on other sites

You make it too complicated..

 

  1. Find the tree you are chopping 
  2. Find the next, closest tree which you are not interacting with (myPlayer().getInteracting() != nextTree) 
  3. Hover if cursor is not on it

You should make the hovering randomized, otherwise it will be an ongoing pattern.

Edited by Woody
  • Like 2
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...