Jump to content

Widgets & Genie Lamp


Fanny

Recommended Posts

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

Link to comment
Share on other sites

  • 1 month later...

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! 👍🏻
 

  • Like 2
Link to comment
Share on other sites

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-

  • Heart 1
Link to comment
Share on other sites

Posted (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 by Fanny
Link to comment
Share on other sites

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

  • Heart 2
Link to comment
Share on other sites

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 by Wacky Jacky
Link to comment
Share on other sites

Posted (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 by Fanny
Link to comment
Share on other sites

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 😂

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