Thread Tools Display Modes
07-05-09, 03:24 PM   #1
ilimo
A Deviate Faerie Dragon
Join Date: Jul 2009
Posts: 15
weapon changing event ?

hello,

is there any event to be fired when one changes weapon
or any other to know which weapon you hold as main ?


"EQUIPMENT_SETS_CHANGED"

is this one do what i need ?? or it is for a group of gears



than you for your help
  Reply With Quote
07-05-09, 03:32 PM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
UNIT_INVENTORY_CHANGED, but use arg1 to filter out 'player' so it doesnt update too much.
  Reply With Quote
07-05-09, 05:43 PM   #3
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
UNIT_INVENTORY_CHANGED is fired when any piece in the PaperDollFrame is changed. And even more, actually.

You can check if your weapon has changed by setting a variable to the name of the weapon, and compare it. If it not the same then your weapon has changed, obviously:

Code:
local lastweapon, compareweapon
function addon:UNIT_INVENTORY_CHANGED(unit)
    if unit ~= 'player' then return end
    compareweapon = GetInventoryItemLink("unit", 16)
    if lastweapon ~= compareweapon then
        //do stuff
    end
    lastweapon = compareweapon
end
This is drycoded however, it has not been tested ingame.

Last edited by ravagernl : 07-05-09 at 05:54 PM.
  Reply With Quote
07-06-09, 01:10 AM   #4
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
You also want to react to this on a timer - say, after 0.25 seconds. Otherwise, you may react to multiple occurrences of the event as it can happen in rapid succession.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
07-06-09, 03:07 AM   #5
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
Yes, you need to throttle it down, 0.25 is simply too low, try something along the lines of 1-2 seconds. UNIT_INVENTORY_CHANGED is a horrible event, only seconded to BAG_UPDATE and the event that warns for durability updates (its name escapes me atm). It will fire when something new is added (or destroyed) in any of your bags, either via looting, splitting a stack etc (with the exception of moving items in your bank), in addition to an item being equipped or unequipped. Unfortunately, it is the only event that Blizzard has provided us, in order to reliably check for equipped item changes, in 4 years
__________________
  Reply With Quote
07-06-09, 04:06 PM   #6
ilimo
A Deviate Faerie Dragon
Join Date: Jul 2009
Posts: 15
well anything like sleep in lua ??

i found nothing using google, curious

thank you again

  Reply With Quote
07-06-09, 09:09 PM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Unfortunately, no. You will have to use an OnUpdate() - to the effect of:

Code:
do
	local last_update = 0
	local updater = CreateFrame("Frame", nil, UIParent)

	updater:Hide()
	updater:SetScript("OnUpdate",
			  function(self, elapsed)
				  last_update = last_update + elapsed
				  if last_update >= 0.25 then
					  DoStuffHere
					  self:Hide()
				  end
			  end)

	function YourAddOn:UNIT_INVENTORY_CHANGED(event, unit)
		if unit ~= "player" then return end
		if not updater:IsVisible() then
			last_update = 0
			updater:Show()
		end
	end
end	-- do
Obviously you'll need to modify it slightly to suit your needs.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » weapon changing event ?


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