Jump to content

Random Event Detector


Iwin

Recommended Posts

52 minutes ago, Iwin said:

I was wondering if anyone had a snippet of a random event solver/dismisser, I searched the forums and googled it, with no success.

I know OSBot has a built in dismisser, but I want to solve the no-brainer ones such as Rick and Genie.

I just need a snippet to check if a random event is mine.


I think you can check that the NPC is interacting with you, and that it has mentioned your player's name in the last x seconds, and has a certain action, like Dismiss.
 

Maybe something like this (note completely untested):
 

Optional<NPC> randomNPCOpt = getNpcs().getAll().stream().filter(npc ->
        npc.getActions() != null &&
        Arrays.asList(npc.getActions()).contains("Dismiss") && // NOT SURE WHAT THE ACTION IS HERE
        npc.isInteracting(myPlayer()) &&
        npc.hasMentionedPhrase(myPlayer().getName(), 30000) && // check the NPC is saying our name
        npc.getModel() != null
).findAny();

if (randomNPCOpt.isPresent()) {
    NPC randomNPC = randomNPCOpt.get();
    switch (randomNPC.getName()) {
        case "Genie":
            handleGenie();
            break;
        default:
            randomNPC.interact("Dismiss"); // NOT SURE WHAT THE ACTION IS HERE
            break;
    }
}

 

Edited by Explv
  • Like 3
Link to comment
Share on other sites

28 minutes ago, Iwin said:

@Patrick are you able to help a little more? How does OSBot know if you have a random event?


.......using the exact method I just showed you.

There is a class called DismissRandom which is an extension of RandomSolver. The RandomExecutor runs it every few seconds, and each time it runs it checks if an NPC exists with the criteria I just showed you. If the NPC exists, it dismisses it.


Here's the decompiled class if for some strange reason you still don't believe me:

 

@ScriptManifest(
    name = "Dismiss Random",
    author = "OSBot",
    version = 1.2D,
    info = "Dismisses random events",
    logo = ""
)
public class DismissRandom extends RandomSolver {
    private NPC IiIiIiiiiIiI = null;

    private NPC iIIiIiiiiiii() {
        Optional var1;
        return (var1 = IiIiIiiiiIiI.getNpcs().getAll().stream().filter((IiIiIiiiiIiIx) -> {
            String[] var2;
            return (var2 = IiIiIiiiiIiIx.getActions()) != null && Arrays.asList(var2).contains(Utilities.iIIiIiiiiiii("\u0005N2J(T2")) && (IiIiIiiiiIiIx.hasMentionedPhrase(IiIiIiiiiIiI.myPlayer().getName(), 30000L) || IiIiIiiiiIiIx.isInteracting(IiIiIiiiiIiI.myPlayer()) && IiIiIiiiiIiIx.getModel() != null);
        }).findFirst()).isPresent() ? (NPC)var1.get() : null;
    }

    public int onLoop() throws InterruptedException {
        if (!IiIiIiiiiIiI.getWidgets().closeOpenInterface()) {
            return 2000;
        } else {
            if (IiIiIiiiiIiI.IiIiIiiiiIiI != null && IiIiIiiiiIiI.IiIiIiiiiIiI.exists()) {
                boolean var10001 = IiIiIiiiiIiI.inventory.deselectItem();
                IiIiIiiiiIiI.magic.deselectSpell();
                if (var10001.IiIiIiiiiIiI.interact(new String[]{LPT6.iIIiIiiiiiii("#\u0010\u0014\u0014\u000e\n\u0014")})) {
                    (new ConditionalSleep(7000, 500) {
                        public boolean condition() throws InterruptedException {
                            return IiIiIiiiiIiI.getMap().getDestination() == null;
                        }
                    }).sleep();
                }
            }

            return 2000;
        }
    }

    public boolean shouldActivate() {
        NPC var1;
        if (IiIiIiiiiIiI.client.isLoggedIn() && (var1 = IiIiIiiiiIiI.iIIiIiiiiiii()) != null && IiIiIiiiiIiI.getMap().canReach(var1)) {
            IiIiIiiiiIiI.IiIiIiiiiIiI = var1;
            return true;
        } else {
            return false;
        }
    }

    public void onExit() {
        IiIiIiiiiIiI.logger.info((new StringBuilder()).insert(0, LPT6.iIIiIiiiiiii("*\b\u0015\u0011\u001c\u0003YG")).append(IiIiIiiiiIiI.IiIiIiiiiIiI.getName()).append(Utilities.iIIiIiiiiiii("\u0007%N2J(T2F-\u00073F/C.Jo")).toString());
    }

    public DismissRandom() {
        super(RandomEvent.DISMISS_RANDOM);
    }
}



 

Edited by Explv
  • Like 1
Link to comment
Share on other sites

1 hour ago, Explv said:


.......using the exact method I just showed you.

There is a class called DismissRandom which is an extension of RandomSolver. The RandomExecutor runs it every few seconds, and each time it runs it checks if an NPC exists with the criteria I just showed you. If the NPC exists, it dismisses it.


Here's the decompiled class if for some strange reason you still don't believe me:

 

 

  Hide contents

 



@ScriptManifest(
    name = "Dismiss Random",
    author = "OSBot",
    version = 1.2D,
    info = "Dismisses random events",
    logo = ""
)
public class DismissRandom extends RandomSolver {
    private NPC IiIiIiiiiIiI = null;

    private NPC iIIiIiiiiiii() {
        Optional var1;
        return (var1 = IiIiIiiiiIiI.getNpcs().getAll().stream().filter((IiIiIiiiiIiIx) -> {
            String[] var2;
            return (var2 = IiIiIiiiiIiIx.getActions()) != null && Arrays.asList(var2).contains(Utilities.iIIiIiiiiiii("\u0005N2J(T2")) && (IiIiIiiiiIiIx.hasMentionedPhrase(IiIiIiiiiIiI.myPlayer().getName(), 30000L) || IiIiIiiiiIiIx.isInteracting(IiIiIiiiiIiI.myPlayer()) && IiIiIiiiiIiIx.getModel() != null);
        }).findFirst()).isPresent() ? (NPC)var1.get() : null;
    }

    public int onLoop() throws InterruptedException {
        if (!IiIiIiiiiIiI.getWidgets().closeOpenInterface()) {
            return 2000;
        } else {
            if (IiIiIiiiiIiI.IiIiIiiiiIiI != null && IiIiIiiiiIiI.IiIiIiiiiIiI.exists()) {
                boolean var10001 = IiIiIiiiiIiI.inventory.deselectItem();
                IiIiIiiiiIiI.magic.deselectSpell();
                if (var10001.IiIiIiiiiIiI.interact(new String[]{LPT6.iIIiIiiiiiii("#\u0010\u0014\u0014\u000e\n\u0014")})) {
                    (new ConditionalSleep(7000, 500) {
                        public boolean condition() throws InterruptedException {
                            return IiIiIiiiiIiI.getMap().getDestination() == null;
                        }
                    }).sleep();
                }
            }

            return 2000;
        }
    }

    public boolean shouldActivate() {
        NPC var1;
        if (IiIiIiiiiIiI.client.isLoggedIn() && (var1 = IiIiIiiiiIiI.iIIiIiiiiiii()) != null && IiIiIiiiiIiI.getMap().canReach(var1)) {
            IiIiIiiiiIiI.IiIiIiiiiIiI = var1;
            return true;
        } else {
            return false;
        }
    }

    public void onExit() {
        IiIiIiiiiIiI.logger.info((new StringBuilder()).insert(0, LPT6.iIIiIiiiiiii("*\b\u0015\u0011\u001c\u0003YG")).append(IiIiIiiiiIiI.IiIiIiiiiIiI.getName()).append(Utilities.iIIiIiiiiiii("\u0007%N2J(T2F-\u00073F/C.Jo")).toString());
    }

    public DismissRandom() {
        super(RandomEvent.DISMISS_RANDOM);
    }
}

 



 

Oooh, thank you. It wasn't that I didn't believe you, I just figured maybe there was some config I wasn't aware of or some other flag.
This helps a ton.

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