Dismiss random events


  • Script Writer

    This snippet dismisses all random events. It wait's a few seconds before dismissing the NPC so it doesn't dismiss them suspiciously fast.

    Usage: Add this snippet to the onStart() method of your script in the main class.

    ScriptBlockingEvent RANDOMS = new ScriptBlockingEvent(this) {
        @Override
        public boolean validate() {
            return Npcs.getNearest(npc -> npc.containsAction("Dismiss")
                    && npc.getTarget() != null
                    && npc.getTarget().equals(Players.getLocal())) != null;
        }
        @Override
        public void process() {
            Npc random = Npcs.getNearest(npc -> npc.containsAction("Dismiss")
                            && npc.getTarget() != null
                            && npc.getTarget().equals(Players.getLocal()));
            if(random != null){
                Time.sleep(1250, 3000);
                random.interact("Dismiss");
            }
        }
    };
    addBlockingEvent(RANDOMS);
    


  • Very nice, thank you!


  • Director

    A better way to do this would be to assign the npc to a class level field and re-use it in the execute, just so you aren't called Npcs.getNearest twice.

    Or you could always have it return true, and just return early in the execute if the npc does not exist.


  • Script Writer

    @MadDev True, I didn't like that I was calling getNearest twice either but I didn't bother changing it, i'll make some edits, test it then change the snippet

    If the blocking event always returned true, even if it returned early when null would it affect the overall efficiency of the script since a blocking event will be constantly triggered? Or is it negligible?


 

96
Online

11.2k
Users

1.1k
Topics

14.6k
Posts