View Single Post
04/25/15, 09:17 PM   #4
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
You could do something like what I did with my Fix Weapon Swap Effects mod and set up a "spam catcher" for event spam:

Code:
local ActiveWeapon = 0
local catchspam = 0

local function DoStuff(WeaponPair)
	Stuff done here that I only want to do if a real weapon swap happened...
	ActiveWeapon = WeaponPair
end

local function CheckStatus(WeaponPair)
	catchspam = catchspam + 1
	if catchspam == 3 then
		if WeaponPair ~= ActiveWeapon then
			DoStuff(WeaponPair)
		end
		catchspam = 0
	end
end

local function OnWeaponSwap(eventCode, WeaponPair, locked)
	CheckStatus(WeaponPair)
end

EVENT_MANAGER:RegisterForEvent(SomeAddon.Name, EVENT_ACTIVE_WEAPON_PAIR_CHANGED, OnWeaponSwap)
I find this works well for my purposes as it has the lowest possible overhead, which is important when firing something on weapon swap. Basically the three events registered go:

1) Ignored.
2) Ignored.
3) Do stuff.

I pass WeaponPair to the CheckStatus event so that I can check a global I store its value in to see if it has changed. This was important for me because Sorcerer ultimate Overcharge is considered a weapon swap for this event but keeps the current internal weapon pair ID, so I can tell not to refresh graphics which cause a Sorcerer to pull out a weapon for their ultimate which looks broken.

EDIT:

EVENT_ACTION_SLOTS_FULL_UPDATE is good if you don't need to know what weapon set the person equipped or if it changed. I used it before, and it is a simple Boolean if the bar change was triggered by a weapon swap.

The thing is, you will still want a spam filter. That event fires 5 times instead of just 3!

Last edited by Phinix : 04/25/15 at 09:44 PM.
  Reply With Quote