Thread Tools Display Modes
12-17-07, 09:24 AM   #1
Robinton
A Defias Bandit
Join Date: Apr 2006
Posts: 2
Using player_target_changed but getting nil errors

I am modifying some code my arena team lead asked me for - to enable an audible alert on what class I am targeting. I have been a bit successful with this:


if (UnitCreatureType("target") == "Humanoid") then
if not (UnitIsFriend("player","target")) then
if (targetClass == "Warrior") then
PlaySoundFile("Interface\\Addons\\Mymod\\Sounds\\warrior.wav");

I get my warrior.wav only when I have targeted an enemy humanoid - which is good.

Unfortunately, every event is triggering the sound, so I end up with warrior repeated endlessly - which is not so good.

So I registered this event:

this:RegisterEvent("PLAYER_TARGET_CHANGED");

and added this line of code:

if (event == "PLAYER_TARGET_CHANGED") then

My hope was the sound would only occur each time my target changed. Now I get errors - strng expected, got nil - or something like that.

Doing a bit of reading and googling (I have not created mods in the past, but I have been successful in modifying them), it seems there are arguments I am not passing correctly:

"PLAYER_TARGET_CHANGED" Category: Combat,Unit Info
This event is fired whenever the player's target is changed, including when the target is lost.

The arg1--arg9 values are undefined; they will be whatever they were in the previous event, i.e. if you click a unit portrait to change target, arg1 will be "LeftButton" - if you click a macro button, it will be the macro script, etc.

I have been trying to figure that out without much success. I think (hope) I am just missing something basic - not a software writer, but aspiring to be a mod writer. I appreciate your help and guidance.

Thanks,

Robinton
  Reply With Quote
12-18-07, 09:43 PM   #2
Tatheltek
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 43
Code:
function RobintonsAddon_OnLoad()
     this:RegisterEvent("PLAYER_TARGET_CHANGED"); 
end

function RobintonsAddon_OnEvent(event)
     local targetClass = UnitClass("target");

     if event == "PLAYER_TARGET_CHANGED" then
          if (targetClass == "Warrior") then
               if (UnitIsFriend("player","target")) then
                     return
               else
                    PlaySoundFile("Interface\\Addons\\RobintonsAddon\\Sounds\\Warrior.wav");
               end
          end
     end
end
Try that and let me know...

make sure to register your onload and onevent handlers in an xml file

Code:
	<Scripts xmlns="http://www.blizzard.com/wow/ui/">
		<OnLoad>
			RobintonsAddon_OnLoad();
		</OnLoad>
		<OnEvent>
			RobintonsAddon_OnEvent(event);
		</OnEvent>
	</Scripts>
Learning to write mods for WoW is a very comlicated and time consuming process with no definitive guide online...I spend alot of time trying to decifer wowwiki. however, wikis are user submitted info so really thats just what other people have figured out through trial and error and sometimes the information there is incomplete or incorrect or how the code functions remains not understood. Try looking at how blizzard codes things at http://wdnaddons.com/ Its a historical reference of the LUA/XML game files and you can learn alot from learing the logic there...thats what I've done as I continue to develop RedAlert.

Last edited by Tatheltek : 12-18-07 at 09:48 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Using player_target_changed but getting nil errors

Thread Tools
Display Modes

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