Thread Tools Display Modes
10-11-11, 11:44 PM   #1
llubtoille
A Defias Bandit
Join Date: Oct 2011
Posts: 2
Combat weapons check

Hiya

I've a good habit of taking off my weapons in a wipe, but a bad habit of not re-equipping them (on my priest).

So given my total lack of a experience with wow addons or programming of any form, I thought I'd try and make an addon to alert me.

Basically when I enter combat, I want it to check my wand slot, and if it's empty I want it to play a soundfile,
I've borrowed quite a bit from tentonhammer.com, however I've pretty much hit a dead end.

This is what I've got so far, are there any glaring errors anyone can spot?

Weapons.xml
<Script file="Weapons.lua"/>
<Frame name="WeaponCore">
<Scripts>
<OnLoad>WeaponLoad();</OnLoad>
<OnEvent>WeaponEvent();</OnEvent>
</Scripts>
</Frame>

Weapons.lua
function WeaponLoad()
this:RegisterEvent("PLAYER_REGEN_DISABLED");
end

function WeaponEvent()
if("HasWandEquipped")=nil then
PlaySound("Interface\\AddOns\\Weapons\\Weapons.mp3")
end

Thanks =D
  Reply With Quote
10-12-11, 12:42 AM   #2
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
a) You don't need to mess with the xml... Your addon will be so small, it will create a slight overhead, that you don't really need.

b) Your code is almost correct, though:

lua Code:
  1. -- create a frame
  2. local frame = CreateFrame('Frame')
  3. frame:RegisterEvent('PLAYER_REGEN_DISABLED')
  4. frame:SetScript('OnEvent', function(self, event)
  5.     -- check for correct event (you don't really need this)
  6.     if ( event ~= 'PLAYER_REGEN_DISABLED' ) then return end
  7.  
  8.     if ( HasWandEquipped() ) then
  9.         -- do stuff here (play sound)
  10.     end
  11. end)

This should do the trick.

However, personally I would suggest to use IsEquippedItemType() with a slightly more complex condition to check for a combination of Main-hand and Range-slot (this would cover classes without wands).
__________________
  Reply With Quote
10-12-11, 03:02 AM   #3
llubtoille
A Defias Bandit
Join Date: Oct 2011
Posts: 2
Yay!
That works great,
I was originally looking for MainhandHasWeapon or something similar,
there's an OffhandHasWeapon is seems, but not mainhand for some reason...

I figure wand will do for now, as it's only really on my casters I wont notice if my weapon's equipped or not,
Whereas for melee and I'd imagine hunters, it's fairly obvious when half your screens greyed out XD
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Combat weapons check


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