WoWInterface (
-   Released AddOns (
-   -   ItemRack - Events (

Gello 12-08-05 09:16 PM

ItemRack - Events
Version 1.7 of ItemRack introduces event-driven scripts to swap gear. You can grab it here:

The purpose of this thread is for a place to ask questions about how to make events in ItemRack or to post events that you make. I'm going to post the events manual here and in the next post I'll be putting events as I come across them for anyone to use.

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.

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:

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:
  • 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
    SaveSet() : Remembers the gear currently in the slots of the associated set
    LoadSet() : Equips the gear saved with SaveSet() in the slots of associated set
    ToggleSet() : Toggles between "SaveSet() EquipSet()" and "LoadSet()".
  • You can pass names of sets in the above functions also:
    EquipSet("setname") : Equips a set named "setname"
    SaveSet("setname") : Remembers the gear currently in the slots of "setname"
    LoadSet("setname") : Equips the gear saved with SaveSet() in the slots of "setname"
    ToggleSet("setname") : Toggles between "SaveSet("setname") EquipSet("setname")" and "LoadSet("setname")"
  • If either EquipSet, SaveSet, 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.

Originally I had hoped to keep the mod's primary purpose evenly split between being a bar mod to swap individual slots on the fly, and a gear sets mod to swap entire sets of gear at once. As the events concept has fleshed out it's becoming apparent that this mod will have three purposes: bar, sets, events. It will probably be broken into a more modular form in the future, so that those who never use the bar can delete it, and those who never use the events can delete that as well.

The goals when adding events were:
  • Make it completely optional. I personally only use the mount script and there's many good mods out there that do the same thing. So it's important that not a single frame is spent processing the baggage I wouldn't use.
  • Make it self sustaining. Every class can probably come up with events when they may swap gear. There are lots of ways to go about choosing when to swap. Hunters are great but I'd rather not devote half my modding time to the many peculiarities of Hunters vs the WoW UI.
  • Make it usable without knowing a thing about Lua. Realistically, those who know Lua well don't need the help of this mod to swap gear for them.
Have fun with the events and if you make some good ones feel free to post them. The original list of events is pretty small partly because if I make them then people will expect me to support them. My hope is that users will create events themselves and share so we can all benefit. I'll be including more over time and if you make a new one that gets included in the default I'll be sure to credit you in the --[[Event notes]].

Thanks to everyone who helped in the beta of this. It was a fun technical challenge and I enjoyed it immensely.

Gello 12-08-05 09:16 PM

Some events. I'll add more as I run across them. Feel free to add your own also!

From an idea posted by Liler:

This event will swap in your skinning gear (likely Finkles) when you mouseover something that can be skinned. It swaps back to your normal gear when you mouseover something/someone else. A variation can be made to switch to skinning gear if you trigger on UI_ERROR_MESSAGE with the exact text when your skill is too low, then swap out when you finish looting on trigger LOOT_CLOSE. Not having a skinner I really can't test this. Feel free to post if you do make one :)

Event: Skinning
Delay: 0
if UnitIsDead("mouseover") and
GameTooltipTextLeft3:GetText()=="Skinnable" then
if not SKINNINGMODE then
elseif SKINNINGMODE then
--[[Equips a set when you mouseover something that can be skinned.]]


This macro/event pair will swap in your spirit gear when you begin casting Evocation and then swap it out when you're done.

1. Make this macro to cast Evocation:
/script EVOCING=1 SaveSet("Spirit Gear") EquipSet("Spirit Gear")
/cast Evocation

2. Make this event:

Event: Mage:Evocation
Delay: 1
if EVOCING and not CastingBarFrame.channeling then EVOCING=nil LoadSet() end
--[[Unequips a set when done casting Evocation]]

3. Associate the set "Spirit Gear" to the event. (can name it anything you want, doesn't need to be "Spirit Gear")

Elkano 12-09-05 04:51 AM

wrt your skinning script:
Using UNIT_SKINNABLE instead of "Skinnable" should make the script language independent :)
just have a look at globalstrings.lua for more of this 'auto localized' strings :)

Gello 12-09-05 12:40 PM

That's a good point. But I'm hoping to cast the events as just normal macros anyone can create and GlobalStrings are rarely used in macros.

Maglev 12-09-05 01:57 PM

How do you create an ItemRack event, for example ..

When event = PLAYER_REGEN_ENABLED then equip WeaponA else if PLAYER_REGEN_DISABLED then equip WeaponB ?

Thanks !

Gello 12-09-05 02:51 PM

In its simplest form:

Event: In Combat
Script: EquipSet()

Event: Out of Combat
Delay: 0
Script: EquipSet()

Then associate the weapon sets you want to each condition.

dereg 12-13-05 02:29 PM

I'm looking for a way to swap weapons if I run out of mana, taking the skinning mode example, i was wondering if the following would work?

Event: ManaWeaponChange
Trigger: UNIT_MANA
Delay: 0
if UnitMana("player") <= 40 then
if OOM then
elseif OOM then

Gello 12-13-05 03:01 PM

Yep that should work. Tho to make it less annoying when you're casting on mana fumes:

if UnitMana("player") <= 40 then
if OOM then
elseif OOM and UnitMana("player")>150 then

That will swap to a set when you go below or equal to 40 mana, and swap back when mana is over 150.

If you wanted to swap at 40% mana, change UnitMana("player") to UnitMana("player")*100/UnitManaMax("player")

Maglev 12-19-05 12:27 PM

hmm, i am a noob when it comes to all these lua scripts.

Lets say I want to trigger a weapon swap with PLAYER_REGEN_DISABLED but only at 80% mana is reached, how do I do that ?

Many thanks !

Gello 12-19-05 04:44 PM

Do you mean if you drop below 80% mana while in combat?

Trigger: UNIT_MANA
Script: if UnitAffectingCombat("player") and (UnitMana("player")/UnitManaMax("player"))<.8 then EquipSet() end

If you mean when you're below 80% when PLAYER_REGEN_DISABLED fires:

Delay: 0
Script: if (UnitMana("player")/UnitManaMax("player"))<.8 then EquipSet() end

Maglev 12-19-05 06:52 PM


Originally Posted by Gello
Delay: 0
Script: if (UnitMana("player")/UnitManaMax("player"))<.8 then EquipSet() end

Yes, I think this should be it.

Weapon swap on condition that I am in combat and my mana is below 80%.

Thanks alot !

absentmindedmage 12-20-05 01:10 AM

First of all, thank you, thank you, thank you for this!

I recently switched over to a Warrior after numerous amounts of Mages on different servers, and I've been searching high and low for a macro that would swap to a 2-h weapon when I did Overpower. My workaround was creating a macro that swapped weapons and clicking that before hitting the Overpower key, but sometimes I'd take to long to swap and lose the opportunity.

Now, I'm not very good at this lua mumbojumbo so I don't have the foggiest idea how to create and event, but the problem I have is that I accidentally deleted the Warrior:Overpower End event when I was first fiddling with the addon. I tried deleting the folder and re-installing the addon, but it's still not showing up. I generally use dual wield when I'm in Battle Stance and would like to swap back to dual wield after Overpower. Can you post the event here so I can cut and paste it?

Also, how would I go about creating an event that switches to Defensive Stance and 1h+shield when I want to do a Shield Bash? I've already defined 1h+shield as my equipment for Defensive Stance.

Thanks in advance. I hope that by looking at some examples, I'll be able to figure out how to create my own events.

Gello 12-20-05 06:57 AM

If you do "/itemrack reset events" it will restore the default events.

On defensive+shield, events can't change forms or do other things that require a hardware event, like using abilities or items. Both the form changing and shield bashing can't be automated.

huffyrox 12-21-05 06:53 AM

Can someone please post an event for gouge so that when a enemy is gouged it will swap your MH sword into a dagger. When it comes to LUA (or pretty much all other forms of programming) i dont have a clue...yet


Gello 12-21-05 05:13 PM

Try this:

Name: Gouged
Trigger: UNIT_AURA
Delay: 0
if arg1=="target" then
local i
for i=1,16 do if UnitDebuff("target",i)=="Interface\\Icons\\Ability_Gouge" then EquipSet() i=17 end

I'm not sure what the debuff texture is for gouge. If Interface\\Icons\\Ability_Gouge doesn't work another rogue may need to help.

absentmindedmage 12-22-05 07:03 PM

Can there be an event that swaps to 2-h after becoming Enraged? How would I create that?

Gello 12-22-05 07:14 PM

Name: Enraged
Delay: 0
local i
for i=1,24 do
if string.find(UnitBuff("player",i) or "","UnholyFrenzy$") then

Should work

Needy 01-07-06 09:11 AM

Hi, Could you please help me on this event:
When vanish cooldown is up, equip set fullnightslayer

basically i have macro to equip mix & match set when I click on vanish, not much trouble there.
I can't however seem to get the reverse right; check my cooldown on vanish, once cooldown is finished, equip full nightslayer set so to be ready when I need to vanish I can take advantage on the 8 piece NS bonus to gain 500HP on vanish.

I posted on wow ui forum about this as well, not sure if u frequent the site, so here I am.
Thank you a lot if you see this!

Needy 01-07-06 09:20 PM

I realized that the event script i made didnt work because somehow I couldnt find the right trigger.
local e, f, g = GetSpellCooldown(48, SpellBookFrame.bookType);if (f <= 0) then

works when i made it into a macro and test it.

somehow it just wont trigger, i tried many events, just wont work.

If you could help me on what event trigger to use which fires when your cooldown ends, that would be great.

I tried

for some reason they dont fire when my cooldown ends, I tested it wit spell 47 which is my stealth, which should change to the set when my 10s cooldown of stealth ends. (I stealth and unstealth, which brings 10s CD on the spell, then waited it out the 10s, nothing happened.)

I also tried delay set to 0.5 and 0 and 1 s

Talone 01-08-06 05:07 AM

Hi Gello

Love the work, BEST OUTFIT/WARDROBE Mod.

Issues with Same Items/Different Enchants

I was having some issues with the mount/dismount event.
So after deleting the ItemRack Directory and the savedvaribles file and re-installing it (I also removed TitanRider .lua and .xml from the Titan Directory) the same problem occurs.

I found what appeared to be an issue with events. In my case the Mount-Dismount event.

Here is my set up.

I have everything the same except for my Trinket, Boots and Gloves.

These are the same type Shadowcraft Boots, one with +Agil on them and the others with Mith Spurs, also Shadowcraft Gloves with +Agil on one pair and Riding Enchant on the other.

So I have these 2 different sets done.
One for Mounted and the other I call Skull-Any, due the the Skullforge Reaver I wear.
I set the Skull-Any up and saved them. Then clicked the equip.

I then set up the Mount select and saved it, and allocted it to the mount event in the events panel, and activate the "Events" box.

When I mount and mismount it leaves the +Agil Gloves and Boots on for both outfits, but switches the Trinkets assigned.

After some testing I think I have found the issue.

As both Boots and Gloves are of the same type (Shadowcraft), but have different Enchants, it does register them as being different, but as the same.

I did this testing by getting another set of Gloves and Boots I have and switching them in the "Mount" Profile, I kept the other "Skull-Any" Profile as is. I then mounted and dismounted and the different Gloves and Boots items switched back and forwards with no problems.

Has this issue come up before, any ideas about a work around to detect that they are same type/piece, but with different enchants?
Is there a way to make a custom script for this?



All times are GMT -6. The time now is 06:26 AM.

vBulletin © 2018, Jelsoft Enterprises Ltd
© 2004 - 2017 MMOUI