Custom Events

Basic Event Usage

The Custom Event system allows you to trigger Subroutines off of any text that reaches the EQ client. Basically any text that is displayed in an EQ chat window, or in the MQ2 chat window can be used. You are able to use parts of the text as parameters for your event subroutine. An example of an #event is below:
1
#event Invite "BillyBob invites you to join a group."
Copied!
This means that when the text "BillyBob invites you to join a group." appears on screen, the event will queue up. It's important to remember that the event will not trigger it's subroutine until you allow it to in your macro. You do so by adding "/doevents" or "/doevents Invite" at an appropriate point in your macro.
When your macro hits the /doevents line, it will trigger any events that are queued up. At this point, the macro will look for the appropriately named subroutine, which in the above case is "Sub Event_Invite". So to flesh out the example above, we should have the following macro:
1
#event Invite "BillyBob invites you to join a group."
2
Sub Main
3
:mainloop
4
/doevents
5
/delay 0
6
/goto :mainloop
7
/return
8
9
Sub Event_Invite
10
/echo BillyBob invited me!
11
/return
Copied!
This will keep running /doevents and when it senses the #event trigger text, it will /echo the text in the Event Sub.

Using part of the #event text as a variable

Now while the above example is pretty useful (eg. you can accept the invite in the Sub Event_Invite), what if we want to accept invites from more than one person? We could create two separate events and have them each echo a different piece of text. Or we could use part of the event text as a variable and manipulate it in the subroutine. You can do this by marking out the part of text you want to use as a variable. In the above example, we'll use the inviter's name:
1
#event Invite "#1# invites you to join a group."
2
Sub Main
3
:mainloop
4
/doevents
5
/goto :mainloop
6
/return
7
8
Sub Event_Invite(Line,Inviter)
9
/echo ${Inviter} invited me!
10
/return
Copied!
A few things to note about the above example:
  1. 1.
    Firstly, we use #1# to mark the first variable that we'd like passed to our Sub. If you want more than one variable
    to be passed, you can use #2# and greater to indicate other variables.
  2. 2.
    Secondly, the above Sub has two variables passed to it - ${Line} and ${Inviter}. 1. The #event system will always pass the entire line of matched text to the subroutine as the first variable. Even
    if you don't wish to use the entire line of text, you need to define the variable. Using "Line" as the first
    variable is very common. However the first variable can be called whatever you'd like, especially if you'd like
    to use the line in your Sub!
    1. 1.
      The next variable, Inviter, is the one we're interested in, and will match whatever's between the first set of #
      symbols in the #event line.
So when the text "PeggySue invites you to a group." appears in a chat window, the same event will trigger, and it will echo
1
"PeggySue invited me!"
Copied!
in the MQ2 chat window.

Ignoring parts of the #event text

You can also ignore certain parts of the trigger text by using #*#. So the example:
1
#event Invite "#1# invites you to join #*#"
Copied!
Would trigger when someone invited you to a group or a raid.

Using variables in the #event text

You can also have the #event system parse variables at the time of the match too. In the following example:
1
#event Follow "#*#follow |${Me.CleanName}|'"
Copied!
When the text, apart from what is between the | symbols, is matched, it then evaluates what's between the | symbols and the event is triggered if the variable matches the text.
So if ${Me.CleanName} was "PeggySue", the following text would not be matched:
BillyBob tells the raid, 'follow me'
While the following text would be:
BillyBob tells the raid, 'follow PeggySue'

#chat Special event

The #chat command is a special custom event. It will always pass the channel, sender and text to the Sub Event_Chat subroutine. So your Sub Event_Chat should look something like this:
Sub Event_Chat(ChatChannel,ChatSender,ChatText) /echo ${ChatSender} told me ${ChatText} in ${ChatChannel} /return
Variable names can be anything you choose.

Timer Events

This is another special custom event. The name of the Timer and the Original Value it was set to, are passed to the subroutine as soon as the timer reaches 0. For example:
Sub Event_Timer(Timer,OriginalValue) /echo ${Timer} reached 0, original value was ${OriginalValue} /return

Notes and Tips

  1. 1.
    Because the system lets you pick the parameter number of any portion of the message, some parameters may not get
    defined. It's up to you to make sure you define all the needed parameters, and to make sure they're defined as the
    correct type (string, int, bool, etc).
  2. 2.
    Pay particular attention to the syntax of your #event line. It will only trigger if the text is identical, so best
    to check it against text in game or in your log file.

If your death event no longer works

Note: This should be fixed as of the 20060628 MQ2 release.
A common use for #event in a lot of macros was for use when you died, something like this:
#event Died "#*#You have entered#*#"
Due to a few small bugs, this event did not always work. To work around this, you can do the following:
  1. 1.
    Declare an outer variable with the ID of your zone in the Main sub.
  2. 2.
    Somewhere in your main loop, add a check that calls the #event if the zone is not the same.
  3. 3.
    Reset the outer variable within your event.
For example
1
#event Died "#*#You have entered#*#"
2
3
sub Main
4
/declare zonecheck int outer ${Zone.ID}
5
6
:main_loop
7
/if (${zonecheck} != ${Zone.ID}) /call Event_Died
8
/delay 0
9
/goto :main_loop
10
/return
11
12
sub Event_Died
13
/varset zonecheck ${Zone.ID}
14
/sit
15
/delay 10s
16
/afk
17
/endmacro
18
/return
Copied!
Last modified 6mo ago