Thread Tools Display Modes
04-20-08, 02:14 AM   #1
Tealc
A Defias Bandit
 
Tealc's Avatar
Join Date: Dec 2007
Posts: 3
Script for API Function "Unit Reaction"

Trying to write a script for eePanels2 here and I need a little help.

The idea is to change the background colour of a frame based on the targets hostility towards you using the "UnitReaction" API function key.

For example if the target was hostile towards you the frame would be red, if they neutral the frame would be yellow and if they were friendly the frame would be green. I have tried to find as much info as I can on this function key but to be honest there is not much available.

Now I am no coder (that’s where you guys come in) but this is what I have so far. I expect it is far far from being correct but any help or advice any one could offer would be great.

Code:
function eepanels2:local reaction = UnitReaction(unit, "player");
	if (reaction) then
		if reaction >=5 then
			eePanels2.db.profile.panels[4].background.frame:SetGradientAlpha("VERTICAL", 0, 1, 0, 1, 0, 1, 0, 1)
		elseif reaction = 4 then
			eePanels2.db.profile.panels[4].background.frame:SetGradientAlpha("VERTICAL", 0, 1, 1, 1, 0, 1, 1, 1)
		elseif reaction <=3 then
			eePanels2.db.profile.panels[4].background.frame:SetGradientAlpha("VERTICAL", 1, 0, 0, 1, 1, 0, 0, 1)
		end
	end

eePanels2:RegisterEvent("REACTION_FRIENDLY")
eePanels2:RegisterEvent("REACTION_NEUTRAL")
eePanels2:RegisterEvent("REACTION_HOSTILE")
When I get this basic part worked out I would also like to add some other colours for dead/ghost target, friendly players etc.
  Reply With Quote
05-05-08, 02:37 PM   #2
Everglow
An Aku'mai Servant
 
Everglow's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
Originally Posted by Craker View Post
Trying to write a script for eePanels2 here and I need a little help.

The idea is to change the background colour of a frame based on the targets hostility towards you using the "UnitReaction" API function key.

For example if the target was hostile towards you the frame would be red, if they neutral the frame would be yellow and if they were friendly the frame would be green. I have tried to find as much info as I can on this function key but to be honest there is not much available.

Now I am no coder (that’s where you guys come in) but this is what I have so far. I expect it is far far from being correct but any help or advice any one could offer would be great.

Code:
function eepanels2:local reaction = UnitReaction(unit, "player");
    if (reaction) then
        if reaction >=5 then
            eePanels2.db.profile.panels[4].background.frame:SetGradientAlpha("VERTICAL", 0, 1, 0, 1, 0, 1, 0, 1)
        elseif reaction = 4 then
            eePanels2.db.profile.panels[4].background.frame:SetGradientAlpha("VERTICAL", 0, 1, 1, 1, 0, 1, 1, 1)
        elseif reaction <=3 then
            eePanels2.db.profile.panels[4].background.frame:SetGradientAlpha("VERTICAL", 1, 0, 0, 1, 1, 0, 0, 1)
        end
    end
 
eePanels2:RegisterEvent("REACTION_FRIENDLY")
eePanels2:RegisterEvent("REACTION_NEUTRAL")
eePanels2:RegisterEvent("REACTION_HOSTILE")
When I get this basic part worked out I would also like to add some other colours for dead/ghost target, friendly players etc.
Well, to start... the events you are trying to register don't exist. You may want to register the "PLAYER_TARGET_CHANGED" event.

Second you need to set up an event handler, either in an xml file or using the lua-only method:

Code:
local eePanels2 = CreateFrame("Frame")
 
eePanels2:SetScript("OnEvent", function(self, event, ...)
   if (event == "PLAYER_TARGET_CHANGED") then
      if(UnitIsDeadOrGhost("target")) then
         -- set color for dead/ghost target
      else
         local reaction = UnitReaction("target", "player")
         -- code to set your color based on reaction
      end
   end
end)
 
eePanels2:RegisterEvent("PLAYER_TARGET_CHANGED")
other global functions available are:
UnitIsDead("unit")
UnitIsGhost("unit")

You can see a list of all available events at http://www.wowwiki.com/Events_From_Disassembly
__________________
Everglow - Sisters of Elune/US

Last edited by Everglow : 05-05-08 at 03:01 PM.
  Reply With Quote
05-10-08, 06:29 PM   #3
Maccaa
A Fallenroot Satyr
 
Maccaa's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 27
Not quite.

eePanels2 has it's own little script area he is on the right track.

I've personally never used eePanels2 but going from the Wiki page maybe this will work.

Code:
function eePanels2:TargetReaction(self, event, ...)
	local reaction = UnitReaction("target", "player")
	if reaction <= 3 then
		--Hostile
	elseif reaction == 4 then
		--Neutral
	elseif reaction >= 5 then
		--Friendly
	end
end

eePanels2:RegisterEvent("PLAYER_TARGET_CHANGED", eePanels2:TargetReaction)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Script for API Function "Unit Reaction"


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