Jump to content

Random Event Detection


SoupyOfficial

Recommended Posts

I haven't been able to test this, nor have I looked into handling randomevents until now. but this would be my first stab at it:
 

private boolean handleRandomEvent() {
        LocatableEntityQueryResult<NPC> results = getAPIContext().npcs().query().actions("Dismiss").results();
        if(results.isEmpty())
            return false;
        try {
            results.nearest().interact("Dismiss");
        } catch (Exception e) {
            // print message for debugging purposes
            getLogger().debug("Caught error: " + e.getMessage());
        }
        return true;
    }
}

lmk if you make any progress

Edited by xkalibur13
Link to comment
Share on other sites

I've tested this and it works

private void dealWithRandomEvent() {
        NPC npc = npcs().query().results().nearest();
        if (npc == null)
            return;
        if (!npc.hasAction("Dismiss"))
            return;
        mouse().moveRandomly(random(500,4000));
        npc.interact("Dismiss");
        System.out.println(npc.getName() + " dismissed");
        mouse().moveOffScreen();
    }

 

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...
  • 7 months later...
On 12/24/2022 at 4:27 AM, xkalibur13 said:

I've tested this and it works

private void dealWithRandomEvent() {
        NPC npc = npcs().query().results().nearest();
        if (npc == null)
            return;
        if (!npc.hasAction("Dismiss"))
            return;
        mouse().moveRandomly(random(500,4000));
        npc.interact("Dismiss");
        System.out.println(npc.getName() + " dismissed");
        mouse().moveOffScreen();
    }

 

After some testing I found a small bug in this code. When a random event NPC appears for another player it tries to dismiss that NPC indefinitely. Here's some untested attempts to fix the issue

private void handleRandomNPC() {
        NPC npc = ctx.npcs().query().results().nearest();
        if (npc == null)
            return;
        if (!npc.hasAction("Dismiss") || !npc.getMessage().contains("SoupyOficial") || !npc.isInteractingWithMe())
            return;
        ctx.mouse().moveRandomly(Random.nextInt(500,4000));
        npc.interact("Dismiss");
        System.out.println(npc.getName() + " dismissed");
        randomsHandled++;
        ctx.mouse().moveOffScreen();
    }

 

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.

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.

×
×
  • Create New...