Thread Tools Display Modes
09-26-08, 03:50 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
UNIT_TARGET Event

Hi there,

I am currently developing my new orb system.

http://www.wowinterface.com/downloads/info11008.html

I use a function to create every orb and on given events I will update or hide/show that specific orb.

Its very dynamic and you can create as many orbs as you want.

I looked into the Blizzard UI to find out the event for the TargetofTarget change. To my suprise there is none.

Currently my orb system handles player and target orbs just fine. The next step is to add orbs that could be of the type pet, focus and targettarget.

I checked the Blizzard code and found out that they check the TargetofTarget with a OnUpdate script. I don't want to do that if I don't have to.

Patch 2.0.x introduced a new Event the UNIT_TARGET Event.

This is the script for my red orbs that I am using currently:
Code:
    
    f:SetScript("OnEvent", function(frame, event, unit)
      if event == "UNIT_HEALTH" and unit == unitid then
        --do stuff
      elseif event == "PLAYER_ENTERING_WORLD" then
        --do stuff
      elseif event == "PLAYER_LOGIN" then
        --do stuff
      elseif event == "PLAYER_TARGET_CHANGED" and unitid == "target" then
        if(UnitExists(unitid)) then
          f:Show()
          f3:Show()
          --do stuff
          --DEFAULT_CHAT_FRAME:AddMessage("1 "..unitid)
        else
          f:Hide()
          f3:Hide()
          --DEFAULT_CHAT_FRAME:AddMessage("2 "..unitid)
        end   
      end    
    end)
    f:RegisterEvent("UNIT_HEALTH")
    f:RegisterEvent("PLAYER_ENTERING_WORLD")
    f:RegisterEvent("PLAYER_LOGIN")
    f:RegisterEvent("PLAYER_TARGET_CHANGED")
It works just fine and now I want to add one condition for the targettarget.

UNIT_TARGET will be fired if the target of a primary unit changes. My guess is that unit "target" is one of this primary units. So I could take it as a base.

My guess is, if I track for the Event UNIT_TARGET and it is fired and my arg1 is "target" I could do a UnitExists-Check for targettarget.

I would change my Script to sth like this:
Code:
    
    f:SetScript("OnEvent", function(frame, event, unit, arg1)
      if event == "UNIT_HEALTH" and unit == unitid then
        --do stuff
      elseif event == "PLAYER_ENTERING_WORLD" then
        --do stuff
      elseif event == "PLAYER_LOGIN" then
        --do stuff
      elseif event == "PLAYER_TARGET_CHANGED" and unitid == "target" then
        if(UnitExists(unitid)) then
          f:Show()
          f3:Show()
          --do stuff
          --DEFAULT_CHAT_FRAME:AddMessage("1 "..unitid)
        else
          f:Hide()
          f3:Hide()
          --DEFAULT_CHAT_FRAME:AddMessage("2 "..unitid)
        end 
      elseif event == "UNIT_TARGET" and arg1 == "target" and unitid == "targettarget" then  
        if(UnitExists(unitid)) then
          f:Show()
          f3:Show()
          --do stuff
          --DEFAULT_CHAT_FRAME:AddMessage("1 "..unitid)
        else
          f:Hide()
          f3:Hide()
          --DEFAULT_CHAT_FRAME:AddMessage("2 "..unitid)
        end 
      end    
    end)
    f:RegisterEvent("UNIT_HEALTH")
    f:RegisterEvent("PLAYER_ENTERING_WORLD")
    f:RegisterEvent("PLAYER_LOGIN")
    f:RegisterEvent("PLAYER_TARGET_CHANGED")
    f:RegisterEvent("UNIT_TARGET")
What do you think?
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 09-26-08 at 03:57 AM.
  Reply With Quote
09-29-08, 04:25 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Found a solution when I finally could test it ingame.

Whats really bad is that UNIT_TARGET Event depends on who targets and who did something.

What worked for me was this condition:
Code:
elseif event == "UNIT_TARGET" and unitid == "targettarget" and (and unit == "target" or unit == "player) then
Why player? Because if you are going to clear the targettarget then the unit will be "player" since you did it and not someone else (target).

Well thats not the only problem with TargetTarget. There is no UnitHealth Event either which is really bad.

That means I will have to work with a onUpdate script to get all the data I need to make my targettarget orb work properly. :/
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
09-29-08, 08:59 AM   #3
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
OnUpdates are the best way to handle invalid units, although I would throttle it i.e.

Code:
local t = 0
f:SetScript("OnUpdate", function(self, el)
	t = t + el
	if t > 0.5 then
		t = 0
		--do stuff
	end
end)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » UNIT_TARGET 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