ItemRack-Event Creation
Version 1.7 of ItemRack introduces event-driven scripts to swap gear. 1.9 changes several essential parts of event creation, which this page will cover.

The intent is to have users scripting the events. They are just like macros, they use the exact language for everything that comes after a /script in a macro, except they run in response to game events. (Note: Language applies both to the scripting language and the human language. While this mod tries to be locale-independent in the bar and sets, it can't hope to ever be locale-independent for events and won't even try.)

Using Events

In the options window when you right-click the minimap button are three tabs. All event setup is done in the Events tab.

Events are disabled initially. To begin using events you need to enable it with the "Enable Events" checkbox at the top of the Events tab. This is the "master switch". You can set up a key binding to toggle all events on or off as well.

In that tab you'll see a list of events with a red question mark beside it. Click the question mark to choose what set to equip for the event. When you've chosen a set it will be enabled. You won't be able to enable an event until you've associated a set for it. (even if the event script doesn't rely on a defined script)

To disable/enable a set with an associated event, uncheck the event. Alternately, you can click Delete to remove the set association and have it drop down to the bottom of the list.

Deleting an event not associated with a set will completely remove it if no other characters use that event.

Editing or Creating Events

If you hit Edit or New at the bottom of the events tab you'll be brought to the event script editor. Here you define when the event runs and what it does. You can copy-paste into/out of these boxes. The four boxes are:

Name: This is the name you'll see in the event list, ie Mount, Warrior:Berserker, Swimming, etc.
Trigger: This is the WoW-generated event you want the event to trigger from. ie PLAYER_AURAS_CHANGED, CHAT_MSG_COMBAT_SELF_HITS, etc
Delay: This is the time, in seconds, after the last occurance of the Trigger before the script runs.
Script: This is the actual script that runs. You can use any lua construct or make it as complicated as you want. The code is directly run without any parsing.

Some knowledge of WoW Lua and scripting will help a great deal in editing and creating events. An excellent resource is the wiki: http://www.wowwiki.com/Interface_Customization

In the lower left is a Test button. You can use this to run the script once to make sure there are no syntax or other obvious errors. But it can't test if the trigger works or anything beyond stuff that would prompt a red error box.

If at any time you've messed up your default events and want them back: /itemrack reset events. This will not touch your custom events. It will just recreate the default events.

Event Specifics

Event Name
  • If you format a name like Class:Event, then you can restrict the list to the class unless "Show All" is checked in the Events tab. For instance "Mage:Evocation" will make the event only list on mages.
  • The class is the localized name of the class. Other clients will probably want to keep "Show All" checked.
  • If you change the name of an existing event and save it, a COPY is made. This is to make it easy to set up multi-event scripts that can fire on many different triggers. (crits for spells, melee, vs hostile players, creatures, etc)
Event Trigger
  • The list of all usable events are listed here: http://www.wowwiki.com/Events
  • You can use ITEMRACK_NOTIFY as a trigger for the mod's notify. arg1 will be the item you received notification for.
  • Events enabled on a character are registered after the first PLAYER_ENTERING_WORLD when you log in/reload, not including that PLAYER_ENTERING_WORLD.
Event Delay
  • If the delay is 0, then the script will immediately run on every occurance of the event.
  • If the delay is greater than 0, then the script will be run only *once* after the last occurange of the event.
  • Many events are fired in game hundreds of times in a flurry. BAG_UPDATE for instance can fire 300 times when you zone. In those cases, putting a small delay here will ensure your script only runs once instead of 300 times. 0.5 seconds is sufficient in most cases. For events that are frequent but not spastic (like UNIT_AURA or PLAYER_AURAS_CHANGED), I prefer 1 to defer processing while heavy stuff is going on (combat, loading, etc) but you can usually choose 0.
  • You can use the delay to wait before running a script also. For instance the "Overpower Begin" has a delay of 0 when an opponent dodges melee, and "Overpower End" has a delay of 5 when an opponent dodges melee. With this pair it can swap in gear at the dodge and swap gear out 5 seconds later. If the opponent dodges again in that 5 seconds, "Overpower Begin" will immediately run again and the "Overpower End" will wait until 5 seconds after tht second dodge.
Event Script
  • You can use the entire Lua environment. In the default events I make heavy use of globals to carry a state over from one event to the next. You could check the gear currently equipped to determine its new state instead if you want.
  • Scripts can be up to 4096 characters long.
  • You can add bracketed comments and they will appear in an event's tooltip: --[[Add notes anywhere in your script]]
  • Scripts are run with RunScript(). This is not as fast as pre-compiled Lua. If you have some massive function you want to do many times, it's always better to embed it into an existing .lua that loads with the game.
  • There are some helper functions to help simplify scripts:
    EquipSet() : Equips the set associated with the event
    LoadSet() : Equips the gear saved when EquipSet() was used with the associated set
    ToggleSet() : Toggles between "EquipSet()" and "LoadSet()".
  • You can pass names of sets in the above functions also:
    EquipSet("setname") : Equips a set named "setname"
    LoadSet("setname") : Equips the gear saved with SaveSet() in the slots of "setname"
    ToggleSet("setname") : Toggles between "EquipSet("setname")" and "LoadSet("setname")"
  • If either EquipSet, LoadSet or ToggleSet is used by another part of the UI, then use ItemRack_EquipSet, ItemRack_SaveSet, ItemRack_LoadSet, ItemRack_ToggleSet instead.
  • Two other helper functions:
    ItemRack_PlayerMounted() : Returns true if the player is mounted. This method is made for speed primarily. If you have problems with this method, I highly recommend the IsMounted mod. ItemRack will defer to IsMounted to be sure if you're mounted or not.
    ItemRack_GetForm() : Returns the name of the form you are in. ie "Battle Stance" "Moonkin Form" etc
  • Finally, remember the script is run without parsing. You don't need to equip a set in reaction to an event. You can make an event to watch chat and flash the chat window if someone says your name. Mostly, remember that ItemRack makes no effort to make sure the script will do what it's supposed to do.

Example of creating an event

Let's make an event to equip a shield when we're targeting a mana user. This would only be useful for warriors under 30 but the principles will apply to almost event event you make.

First, make a set called 'Shield' that contains just a shield in the offhand slot and a weapon in mainhand slot. We'll equip this set when we target a mana user and unequip it when our target drops or changes to someone without mana.

The first step is to identify when you want to check the event. In this case, PLAYER_TARGET_CHANGED is a likely one. (Some may remember UNIT_AURA firing when changing targets, this is no longer true)

PLAYER_TARGET_CHANGED often fires in pairs, once to untarget and again to target. These pairs happen instantly so we'd probably want to wait until they're done. We don't want to unequip a shield and equip a shield within 0.01 seconds. So let's give it a delay of 0.5. You can make it 0.25 also.

Now we need to know how to find out if the target is a mana user. The UnitPowerType function will give us just that. If UnitPowerType("target")==0 then they have a "blue" mana bar.

To put it together:

name: Shield Bash
trigger: PLAYER_TARGET_CHANGED
delay: 0.5
script:
if UnitPowerType("target")==0 then
EquipSet()
else
LoadSet()
end
--[[Equips a set when targeting a mana user]]

Now associate the set "Shield" with the "Shield Bash" event and you're done!

0.5 seconds after a PLAYER_TARGET_CHANGED pair, it will check if your target has a mana bar, and equip the associate set ("Shield") if so. If not, it will unequip the set to whatever you wore previously.

Note: LoadSet is an awkward name based on the 1.7-1.8 versions of ItemRack, when a SaveSet() was needed to store slots. It will likely get a pseudonym in the future of UnequipSet().

For a thread discussing events and how to create them, feel free to post here: ItemRack - Events.