DCHILLING Posted Monday at 09:09 PM Posted Monday at 09:09 PM 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.
Khaleesi Posted Tuesday at 04:11 AM Posted Tuesday at 04:11 AM 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 1
DCHILLING Posted Tuesday at 08:39 AM Author Posted Tuesday at 08:39 AM 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?
Khaleesi Posted Tuesday at 09:40 AM Posted Tuesday at 09:40 AM 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()); } } } 2
Czar Posted Tuesday at 09:45 AM Posted Tuesday at 09:45 AM 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 2
DCHILLING Posted Tuesday at 10:25 AM Author Posted Tuesday at 10:25 AM 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 1
Khaleesi Posted Tuesday at 11:29 AM Posted Tuesday at 11:29 AM 1 hour ago, DCHILLING said: Thank you both for the information if you have any more question or issues feel free to share and we can take a look at it!