Originally Posted by Phinix
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!
|
In some cases your catchspam doesn't work. I didn't really check if it's because event EVENT_ACTIVE_WEAPON_PAIR_CHANGED is fired more or less times then expected, but I have changed it back to EVENT_ACTION_SLOTS_FULL_UPDATE and it seems to be working better for me.
Lua Code:
local activeWeapon = ACTIVE_WEAPON_PAIR_NONE
local function SwapEffects()
local helmStatus = tonumber(GetSetting(SETTING_TYPE_IN_WORLD, IN_WORLD_UI_SETTING_HIDE_HELM))
SetSetting(SETTING_TYPE_IN_WORLD, IN_WORLD_UI_SETTING_HIDE_HELM, 1 - helmStatus)
SetSetting(SETTING_TYPE_IN_WORLD, IN_WORLD_UI_SETTING_HIDE_HELM, helmStatus)
end
local function OnWeaponSwap(eventCode, isHotbarSwap)
if isHotbarSwap and not IsBlockActive() then
local weapon = GetActiveWeaponPairInfo()
if activeWeapon ~= weapon then
SwapEffects()
activeWeapon = weapon
end
end
end
local function Init(eventCode)
activeWeapon = GetActiveWeaponPairInfo()
end
EVENT_MANAGER:RegisterForEvent(SomeAddon.Name, EVENT_ACTION_SLOTS_FULL_UPDATE, OnWeaponSwap)
EVENT_MANAGER:RegisterForEvent(SomeAddon.Name, EVENT_PLAYER_ACTIVATED, Init)