Jump to content

Strange interaction issue with farming patch


sobot

Recommended Posts

Hi, I'm trying to make a farming script and it works pretty well so far aside from the fact that sometimes the bot just doesn't interact with the flower patch in Hosidius. When the bot gets there it initialises the patches and gives them a state, it clears it, selects the seed and then just doesn't interact with the patch, it just gets stuck standing there with the seed selected and adjusting the camera angle every so often. 

It doesn't seem to be any issue with the state or the initialisation of the object and other patches seem to work fine, even the patch I mentioned seems to work 50% of the time, so it's very strange and I cannot seem to debug this issue. I was wondering if anyone has had any similar experiences or might know why this happens?

Thanks

Edited by sobot
Link to comment
Share on other sites

10 hours ago, abc3 said:

Can you post the code?

There isn't really much going on here, but here are the relevant bits.

This bit is for getting the patches state.

    public State getState() {

        if (patch == null) {
            state = State.NOT_INITIALISED;
        } else if (patch.hasAction("Harvest") || patch.hasAction("Pick")) {
            state = State.READY_TO_HARVEST;
            isFertilised = false;
        } else if (patch.hasAction("Clear")) {
            state = State.DEAD;
        } else if (patch.hasAction("Rake")) {
            state = State.OVERGROWN;
        } else if (Arrays.stream(patchNames).anyMatch(p -> p.equals(patch.getName()))) {
            state = State.EMPTY;
        } else {
            state = State.GROWING;
        }

        return state;
    }

This bit is responsible for planting the seed, I realise that I could store the state in a variable and not call the function unnecessarily, which I did before and then changed it to this while trying to find this issue, thought maybe that would help.

        if (getState() == State.EMPTY) {

            inventory.interact("Use", seed);
            Sleep.until(() -> inventory.isItemSelected() && inventory.getSelectedItemName().equals(seed), 3000);

            patch.interact("Use"); // <----- hos flower patch issue is somewhere here
            Sleep.until(() -> getState() == State.GROWING, 10000);

        }

Function that initialises the patches from an area.

    public void initPatch() {

        if (getState() == State.NOT_INITIALISED) {
            Filter<RS2Object> filter = new Filter<RS2Object>() {
                @Override
                public boolean match(RS2Object obj) {
                    return location.contains(obj) && Arrays.stream(patchIDs).anyMatch(id -> id == obj.getId());
                }
            };

            patch = api.getObjects().closest(filter);
            
        }
    }

I am pretty certain that it is not an issue with the initialisation of the patches or getting the wrong state. I logged the patch data in the seed function and its definitely there, not to mention that the bot clears, rakes and picks the limpwurts too, just doesn't plant or use compost.

Any insight would be appreciated!

Edited by sobot
Link to comment
Share on other sites

3 hours ago, sobot said:

There isn't really much going on here, but here are the relevant bits.

This bit is for getting the patches state.

    public State getState() {

        if (patch == null) {
            state = State.NOT_INITIALISED;
        } else if (patch.hasAction("Harvest") || patch.hasAction("Pick")) {
            state = State.READY_TO_HARVEST;
            isFertilised = false;
        } else if (patch.hasAction("Clear")) {
            state = State.DEAD;
        } else if (patch.hasAction("Rake")) {
            state = State.OVERGROWN;
        } else if (Arrays.stream(patchNames).anyMatch(p -> p.equals(patch.getName()))) {
            state = State.EMPTY;
        } else {
            state = State.GROWING;
        }

        return state;
    }

This bit is responsible for planting the seed, I realise that I could store the state in a variable and not call the function unnecessarily, which I did before and then changed it to this while trying to find this issue, thought maybe that would help.

        if (getState() == State.EMPTY) {

            inventory.interact("Use", seed);
            Sleep.until(() -> inventory.isItemSelected() && inventory.getSelectedItemName().equals(seed), 3000);

            patch.interact("Use"); // <----- hos flower patch issue is somewhere here
            Sleep.until(() -> getState() == State.GROWING, 10000);

        }

Function that initialises the patches from an area.

    public void initPatch() {

        if (getState() == State.NOT_INITIALISED) {
            Filter<RS2Object> filter = new Filter<RS2Object>() {
                @Override
                public boolean match(RS2Object obj) {
                    return location.contains(obj) && Arrays.stream(patchIDs).anyMatch(id -> id == obj.getId());
                }
            };

            patch = api.getObjects().closest(filter);
            
        }
    }

I am pretty certain that it is not an issue with the initialisation of the patches or getting the wrong state. I logged the patch data in the seed function and its definitely there, not to mention that the bot clears, rakes and picks the limpwurts too, just doesn't plant or use compost.

Any insight would be appreciated!

You can try to interatc without an action and see how that works.

Or write your own interactionevent.
if mouse is not hovering the obbjects model -> move mouse
if it is hovering, just left click or check the Menu what the first action is and depoending ont hat left click or right click to open the menu 😉

Link to comment
Share on other sites

1 hour ago, abc3 said:

The api functions return a boolean, you can check the result

If patch.interact("Use") fails it returns false, probably because it doesn't recognize the action

try patch.interact() it will just use the default interaction

 

32 minutes ago, Khaleesi said:

You can try to interatc without an action and see how that works.

Or write your own interactionevent.
if mouse is not hovering the obbjects model -> move mouse
if it is hovering, just left click or check the Menu what the first action is and depoending ont hat left click or right click to open the menu 😉

It seems just using the default interaction worked, I've only tested it once at the moment though. Thanks for your help guys! Really appreciate it! I didn't realise there was a default action, that's what I get for not reading the docs fully :D 

Link to comment
Share on other sites

2 hours ago, sobot said:

 

It seems just using the default interaction worked, I've only tested it once at the moment though. Thanks for your help guys! Really appreciate it! I didn't realise there was a default action, that's what I get for not reading the docs fully :D 

After further testing it still doesn't seem to work so I'll just have to create my own interaction event like Khaleesi suggested :)

Edited by sobot
Link to comment
Share on other sites

9 minutes ago, sobot said:

After further testing it still doesn't seem to work so I'll just have to create my own interaction event like Khaleesi suggested :)

very odd, you could try to debug the objects model, maybe it's null or somehting and if you find the reason why it does not work you could do:
Another solution what you can try it to interact with the Position itself. Position has an interact method with an action aswell :)
 

Link to comment
Share on other sites

4 hours ago, Khaleesi said:

very odd, you could try to debug the objects model, maybe it's null or somehting and if you find the reason why it does not work you could do:
Another solution what you can try it to interact with the Position itself. Position has an interact method with an action aswell :)
 

It seems that the issue with was with the initialisation of the patches in some way, still not sure how, but I simply made it so the patch gets initialised every  iteration of the interaction loop and you can see it get stuck after picking the patch, but then its initialised again and it works. Since its not a heavy function I guess I'm fine with that. Thanks for the help :)

  • 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...