Jump to content

Inventory to entity interactions / invokes


Recommended Posts

Posted

Hello, I've been writing a script and while testing an NPC walked over the same tile where the object was. The script tried interacting left click -> left click, but it kept clicking the NPC on the second click, not opening the context menu. I found this class InteractionEvent in the Osbot API, but I am unsure if this would help. Maybe adding an action to the "interact()" would help, but I don't know what the "->" action stands for (indicated in the top left corner in the game). Relevant snippet:

entityHandler.getRS2Object(e2.getEntityIndex()).interact(); 

On another note, I only found one topic on invokes 

I was wondering if anyone could share an example on how to send an action (invoke action) on some kind of entity? Since Gunman's code there is hidden behind his own custom class.

Posted
9 hours ago, DCHILLING said:

Hello, I've been writing a script and while testing an NPC walked over the same tile where the object was. The script tried interacting left click -> left click, but it kept clicking the NPC on the second click, not opening the context menu. I found this class InteractionEvent in the Osbot API, but I am unsure if this would help. Maybe adding an action to the "interact()" would help, but I don't know what the "->" action stands for (indicated in the top left corner in the game). Relevant snippet:

entityHandler.getRS2Object(e2.getEntityIndex()).interact(); 

On another note, I only found one topic on invokes 

I was wondering if anyone could share an example on how to send an action (invoke action) on some kind of entity? Since Gunman's code there is hidden behind his own custom class.

That's probably because you are using npc.interact() instead of npc.interact("yourAction")?
might wanna share some of your code to see what's going on for you and what exactly you are trying to do, as this sounds as a code issue :)

  • Like 1
Posted
4 hours ago, Khaleesi said:

That's probably because you are using npc.interact() instead of npc.interact("yourAction")?
might wanna share some of your code to see what's going on for you and what exactly you are trying to do, as this sounds as a code issue :)

I am trying to use some fish on a fire in order to cook it, and it works if nothing is in the way, but with an NPC over an RS2Object it doesn't and so the functions need to be improved:

public void interactInventoryEntity(EEntities e1, EEntities e2, EAction action, EAnimations sleepingAnimation) {
    if (!widgetHandler.isTabOpen(Tab.INVENTORY)) {
        widgetHandler.openTab(Tab.INVENTORY);
    }
    if (inventoryHandler.containsByIndex(e1)) {
        t1 = inventoryHandler.interactItem(e1, action);
        if (t1) {
            t1 = false;
            t2 = entityHandler.getRS2Object(e2.getEntityIndex()).interact();
        }
        if (t2) {
            t2 = false;
            CSleep.sleepUntil(() -> script.myPlayer().getAnimation() == sleepingAnimation.getAnimationId(), 4000);
            CSleep.sleepUntil(() -> script.myPlayer().getAnimation() == -1, 9000);
            
        }
    }
}

The interact function is from the api, and the entityHandler function is this:

public RS2Object getRS2Object(int id){
    return script.getObjects().closest(id);
}

Then I pass the fire entity to the function

FIRE("Fire", 26185),
interactInventoryEntity(EEntities.FISH, EEntities.FIRE, EAction.INTERACTION_USE, EAnimations.ANIMATION_COOKING_ON_FIRE);

So it selects the fish okay, clicks on the NPC instead of selecting the fire and then sleeps for 4 seconds 😃 Does interact() without parameters always left click?

Posted

you would just need to add "Use" to the interact method. as interact wothout any action will just skip the Menu check and left click

But this might result in nullpointer exception as the fire object might not always be there, so make sure to always null check widgets, objects, npcs, whatever you load from ingame :)

Here is a super simple snippet:

RS2Object fire = script.getObjects().closest("Fire");
                if (fire != null) {
                    if(script.getInventory().isItemSelected()){
                        if(fire.interact("Use")){
                            ConditionalSleep2.sleep(1000, () -> script.myPlayer().isAnimating());
                        }
                    }else{
                        if(script.getInventory().interact("Use", "Raw Salmon")){
                            ConditionalSleep2.sleep(1000, () -> script.getInventory().isItemSelected());
                        }
                    }
                }
  • Like 2
Posted
41 minutes ago, Khaleesi said:

you would just need to add "Use" to the interact method. as interact wothout any action will just skip the Menu check and left click

But this might result in nullpointer exception as the fire object might not always be there, so make sure to always null check widgets, objects, npcs, whatever you load from ingame :)

Here is a super simple snippet:

RS2Object fire = script.getObjects().closest("Fire");
                if (fire != null) {
                    if(script.getInventory().isItemSelected()){
                        if(fire.interact("Use")){
                            ConditionalSleep2.sleep(1000, () -> script.myPlayer().isAnimating());
                        }
                    }else{
                        if(script.getInventory().interact("Use", "Raw Salmon")){
                            ConditionalSleep2.sleep(1000, () -> script.getInventory().isItemSelected());
                        }
                    }
                }

 

39 minutes ago, Czar said:

And once you get that working, you'll wanna know how to handle the interface:

if (getWidgets().isVisible(270)) {

getKeyboard().typeString(" ", false);

}


Of course there's better ways to handle it but this is the quickest/easiest way

Thank you both for the information 😊

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