Thread Tools Display Modes
04/24/15, 11:28 AM   #1
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
EVENT_ACTIVE_WEAPON_PAIR_CHANGED always fired for every attack (even out of combat)

Hey there,

I just tried to use the event EVENT_ACTIVE_WEAPON_PAIR_CHANGED to see if the active weapon bar was changed.

1) It gets fired once with locked = true for the current active action bar (1) to lock it (but this does not happen always?).
2) Afterwards it gets fired for the new action bar (2) with locked = true.
3) And then finally it gets fired with the new action bar (2) and locked = false.

"Locked" means the small "lock symbol" at the action bar which says you cannot use or change the bar currently.

I just want to react on a player changing his action bar. But this chain of event firing will be ALWAYS fired with steps 2 and 3 if I even only use my attack skill of the weapon.
Bar gets locked 2), bar gets unlocked 3).

Any chance to filter this out so I can just react on a player "really" changing his action bars?

My current solution is:
-Upon login: Get active bar and save it into global addon variable
-Event is fired: Check if global variable differs from current event's active weapon pair id
-> As "locked = false" and weaponbar Id differs: Update the global variable with the new variable from the event

I only run my code if the last weapon bar id differs from the current one.

Any better solutions?

Thanks for your help.
  Reply With Quote
04/24/15, 12:00 PM   #2
Adalan
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 20
Originally Posted by Baertram View Post
Hey there,

I just tried to use the event EVENT_ACTIVE_WEAPON_PAIR_CHANGED to see if the active weapon bar was changed.

1) It gets fired once with locked = true for the current active action bar (1) to lock it (but this does not happen always?).
2) Afterwards it gets fired for the new action bar (2) with locked = true.
3) And then finally it gets fired with the new action bar (2) and locked = false.

"Locked" means the small "lock symbol" at the action bar which says you cannot use or change the bar currently.

I just want to react on a player changing his action bar. But this chain of event firing will be ALWAYS fired with steps 2 and 3 if I even only use my attack skill of the weapon.
Bar gets locked 2), bar gets unlocked 3).

Any chance to filter this out so I can just react on a player "really" changing his action bars?

My current solution is:
-Upon login: Get active bar and save it into global addon variable
-Event is fired: Check if global variable differs from current event's active weapon pair id
-> As "locked = false" and weaponbar Id differs: Update the global variable with the new variable from the event

I only run my code if the last weapon bar id differs from the current one.

Any better solutions?

Thanks for your help.
If you check out the code of my maintained GearSwap, it show you, that i got exactly the same problems and solved that by alot of blocker routines with boolean, to stop running into those routines more than two times. Its not enough to just stop the EVENT, because you need it running sometimes for another check.
It was a horrible coding action, because alot of situations raised the swap-effect, where no swap was done. (like mounting up, changing maps, talking to vendors and so on)

Forget the lock - use your own boolean and maybe a counter to suppress running into your routines more than two times by those raised events.
Btw, the ID-Check is that, what ive done also in GearSwap and help you at least for some occouring events to stop that.

Greets,
Adalan

Last edited by Adalan : 04/24/15 at 12:26 PM.
  Reply With Quote
04/25/15, 08:23 PM   #3
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
It sounds like you want this event instead:
Lua Code:
  1. local function OnChange(eventCode,  isHotbarSwap)
  2.     d("HotBarSwaped: "..tostring(isHotbarSwap))
  3. end
  4.  
  5. EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ACTION_SLOTS_FULL_UPDATE, OnChange)
  Reply With Quote
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
04/25/15, 10:26 PM   #5
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Phinix View Post
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!
Each time I swap weapons EVENT_ACTION_SLOTS_FULL_UPDATE only fires 1 time for me.

You can just call:
Lua Code:
  1. GetActiveWeaponPairInfo()
  2.         Returns: integer ActiveWeaponPair activeWeaponPair, boolean locked
To see what weapon pair their using.
  Reply With Quote
04/26/15, 06:29 AM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Phinix View Post
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:
  1. local activeWeapon = ACTIVE_WEAPON_PAIR_NONE
  2.  
  3. local function SwapEffects()
  4.     local helmStatus = tonumber(GetSetting(SETTING_TYPE_IN_WORLD, IN_WORLD_UI_SETTING_HIDE_HELM))
  5.     SetSetting(SETTING_TYPE_IN_WORLD, IN_WORLD_UI_SETTING_HIDE_HELM, 1 - helmStatus)
  6.     SetSetting(SETTING_TYPE_IN_WORLD, IN_WORLD_UI_SETTING_HIDE_HELM, helmStatus)
  7. end
  8.  
  9. local function OnWeaponSwap(eventCode, isHotbarSwap)
  10.     if isHotbarSwap and not IsBlockActive() then
  11.         local weapon = GetActiveWeaponPairInfo()
  12.         if activeWeapon ~= weapon then
  13.             SwapEffects()
  14.             activeWeapon = weapon
  15.         end
  16.     end
  17. end
  18.  
  19. local function Init(eventCode)
  20.     activeWeapon = GetActiveWeaponPairInfo()
  21. end
  22.  
  23.  
  24. EVENT_MANAGER:RegisterForEvent(SomeAddon.Name, EVENT_ACTION_SLOTS_FULL_UPDATE, OnWeaponSwap)
  25. EVENT_MANAGER:RegisterForEvent(SomeAddon.Name, EVENT_PLAYER_ACTIVATED, Init)
  Reply With Quote
04/26/15, 06:43 AM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Thanks for all the info guys.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » EVENT_ACTIVE_WEAPON_PAIR_CHANGED always fired for every attack (even out of combat)


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off