Jump to content

Question: getting most recent message in chatbox


damufinmkan

Recommended Posts

Hello, not sure if I'm posting this in the right spot so please move if necessary. 

 

 

So, I'm making a script to assist my Nightmare Zone AFK training. Right now, I have it set up so that an alarm goes off when I need to drink an overload or prayer potion.

 

Now, I want to scan the chatbox to see when a Power Surge powerup spawns. I'm trying to figure out the best way to do this. My first thought, given the API limitations, was to grab all messages in the chat of MessageType.GAME and evaluate just the most recent one, see if it's a power surge notificaiton, and if so, set the alarm. BUT, since I'm grabbing all the chat messages in a loop once every second, I think it's causing the client to crash. 

 

Is there a better way to get the most recent chatbox message without getting the whole list of messages? Or is there a way to put that part in an onLoop separate from my other code, to only scans the chatbox every 30 seconds or so?

 

Keep in mind, I want to make sure that the alarm only beeps once, when the powerup is first available to use.

 

Please share your thoughts.

 

-Damufin

Link to comment
Share on other sites

chatbox.getMessages().get(chatbox.getMessages().size()-1); 

should get the last item in the list of messages. is that what you want...?

 

 

 

or if you just want to check every 30 seconds:

private long timeStarted;

@ Override
public void onStart() {
    timeStarted = System.currentTimeMillis();
}

@ Override
public int onLoop() throws InterruptedException {
      if((System.currentTimeMillis() - timeStarted) % 30000 == 0) {
            //check for surge
      }
}

Edited by Imateamcape
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...