Fanny Posted May 23 Share Posted May 23 I have no way to test or find without waiting for a genie to spawn, so thought I'd ask here Does anyone know the widget code or have any existing scripts for handling the genie lamp? private void randomHandler() throws InterruptedException { randomGenie(); // Additional randoms } private void randomGenie() throws InterruptedException { final NPC genie = getNpcs().closest(npc -> npc != null && npc.getName().equals("Genie") && npc.getPosition().distance(myPosition()) <= 1); if (genie == null || !genie.exists()) { return; } log("Genie found. Attempting to talk..."); genie.interact("Talk-to"); if(Sleep.sleep(this,3000,() -> getInventory().contains("Lamp"))){ getInventory().getItem("Lamp").interact("Rub"); // Widget code } return; } Just decided to put this here for anyone else looking for the same - just call randomHandler() at the start of the onloop Feels like the Genie is definitely one people would actually click on, couple of others potentially depending on if the script is banking etc Quote Link to comment Share on other sites More sharing options...
Wacky Jacky Posted July 7 Share Posted July 7 Fun piece of code! You’re right; having the genie , I would also click it, just like most real players would. I’m not sure if you already have all the necessary widgets, but if not, let me know, and I can post them here if you respond to this post. However, the code doesn’t consider who the genie is targeting. You’ll end up in an endless loop, trying to interact with the genie until it dissolves into thin air when the timer runs out. Add some code to check if the genie is interacting with the player. You could maybe check the text, extract the name from the genie’s message, and see if it matches the current player. I’ll take a look at my code to see how I handled it. Great snippet, keep it up! 2 Quote Link to comment Share on other sites More sharing options...
yfoo Posted July 8 Share Posted July 8 9 hours ago, Wacky Jacky said: Fun piece of code! You’re right; having the genie , I would also click it, just like most real players would. I’m not sure if you already have all the necessary widgets, but if not, let me know, and I can post them here if you respond to this post. However, the code doesn’t consider who the genie is targeting. You’ll end up in an endless loop, trying to interact with the genie until it dissolves into thin air when the timer runs out. Add some code to check if the genie is interacting with the player. You could maybe check the text, extract the name from the genie’s message, and see if it matches the current player. I’ll take a look at my code to see how I handled it. Great snippet, keep it up! > Add some code to check if the genie is interacting with the player. I think this is the best way to do it. Character has IsInteracting So you can use ``` genieInstance.IsInteracting(myPlayer()) ``` https://osbot.org/api/org/osbot/rs07/api/model/Character.html#isInteracting-org.osbot.rs07.api.model.Character- 1 Quote Link to comment Share on other sites More sharing options...
Fanny Posted July 9 Author Share Posted July 9 (edited) On 7/7/2024 at 6:10 PM, Wacky Jacky said: I’m not sure if you already have all the necessary widgets, but if not, let me know, and I can post them here if you respond to this post. Thanks, that would be awesome! On 7/8/2024 at 3:45 AM, yfoo said: Add some code to check if the genie is interacting with the player. I didn't realise isInteracting() is so broad in scope! It is only following the player, but this is good to know, thanks! I have updated my code: public final class myScript extends Script { private String playerName; ... @Override public final int onLoop() throws InterruptedException { if(playerName == null){ if(getClient().isLoggedIn()) { playerName = myPlayer().getName(); } } else{ randomHandler(); } ... } private void randomHandler() throws InterruptedException { randomGenie(); // Additional randoms later } private void randomGenie() throws InterruptedException { final NPC genie = getNpcs().closest(npc -> npc != null && npc.getName().equals("Genie") && npc.getPosition().distance(myPosition()) <= 1); if (genie == null || !genie.exists()) { return; } if (!genie.isInteracting(myPlayer()) || (genie.getHeadMessage() != null && !genie.getHeadMessage().contains(playerName))) { return; } log("Genie found. Attempting to talk..."); genie.interact("Talk-to"); if(Sleep.sleep(this,3000,() -> getInventory().contains("Lamp"))){ getInventory().getItem("Lamp").interact("Rub"); // Widget code } return; } Edited July 9 by Fanny Quote Link to comment Share on other sites More sharing options...
Wacky Jacky Posted July 9 Share Posted July 9 3 hours ago, Fanny said: Thanks, that would be awesome! I didn't realise isInteracting() is so broad in scope! It is only following the player, but this is good to know, thanks! I have updated my code: public final class myScript extends Script { private String playerName; ... @Override public final int onLoop() throws InterruptedException { if(playerName == null){ if(getClient().isLoggedIn()) { playerName = myPlayer().getName(); } } else{ randomHandler(); } ... } private void randomHandler() throws InterruptedException { randomGenie(); // Additional randoms later } private void randomGenie() throws InterruptedException { final NPC genie = getNpcs().closest(npc -> npc != null && npc.getName().equals("Genie") && npc.getPosition().distance(myPosition()) <= 1); if (genie == null || !genie.exists()) { return; } if (!genie.isInteracting(myPlayer()) || (genie.getHeadMessage() != null && !genie.getHeadMessage().contains(playerName))) { return; } log("Genie found. Attempting to talk..."); genie.interact("Talk-to"); if(Sleep.sleep(this,3000,() -> getInventory().contains("Lamp"))){ getInventory().getItem("Lamp").interact("Rub"); // Widget code } return; } There you go: https://pastebin.com/raw/GiQtZFJs 2 Quote Link to comment Share on other sites More sharing options...
Wacky Jacky Posted July 10 Share Posted July 10 (edited) On 7/9/2024 at 10:48 AM, Fanny said: Thanks, that would be awesome! I didn't realise isInteracting() is so broad in scope! It is only following the player, but this is good to know, thanks! I have updated my code: public final class myScript extends Script { private String playerName; ... @Override public final int onLoop() throws InterruptedException { if(playerName == null){ if(getClient().isLoggedIn()) { playerName = myPlayer().getName(); } } else{ randomHandler(); } ... } private void randomHandler() throws InterruptedException { randomGenie(); // Additional randoms later } private void randomGenie() throws InterruptedException { final NPC genie = getNpcs().closest(npc -> npc != null && npc.getName().equals("Genie") && npc.getPosition().distance(myPosition()) <= 1); if (genie == null || !genie.exists()) { return; } if (!genie.isInteracting(myPlayer()) || (genie.getHeadMessage() != null && !genie.getHeadMessage().contains(playerName))) { return; } log("Genie found. Attempting to talk..."); genie.interact("Talk-to"); if(Sleep.sleep(this,3000,() -> getInventory().contains("Lamp"))){ getInventory().getItem("Lamp").interact("Rub"); // Widget code } return; } I just came to tell you, your code works nicely done fam. I ran it over night, I added the code to my with my dive training script (store) for testing, I woke up to 6 lamps in my inventory. I did however remove the part about the head message, and I made the range two, [npc.getPosition().distance(myPosition()) <= 2] because the diver runs a lot and the distance might become bigger than 1. But the code as is, should also do just fine. Edited July 10 by Wacky Jacky Quote Link to comment Share on other sites More sharing options...
Fanny Posted July 10 Author Share Posted July 10 (edited) 5 hours ago, Wacky Jacky said: I just came to tell you, your code works nicely done fam. Sweet, good to know it actually works! Not had chance to test it since writing Thanks for the widget numbers! I get the distance part, depends if you are doing static vs dynamic skills Out of curiousity - why not head message? Edited July 10 by Fanny Quote Link to comment Share on other sites More sharing options...
Wacky Jacky Posted July 11 Share Posted July 11 2 hours ago, Fanny said: Sweet, good to know it actually works! Not had chance to test it since writing Thanks for the widget numbers! I get the distance part, depends if you are doing static vs dynamic skills Out of curiousity - why not head message? No real reason, I have had false positives in the past, but probably a skill issue on my side Quote Link to comment Share on other sites More sharing options...