Have a look at the SpellStatus library: API Doc
If you don't want to include the whole library for just one little thing, it depends on the type of spell (instant, channeling, whether you want to do something on casting start or stop, etc). Maybe the Spell Event Section of the WoW-Wiki can help you.
I don't seem to be able to download the SpellStatus library, so in looking at the other link you posted...
I want to fire my function off whenever I cast Resurrection.
So, looking at this event from your link.
"SPELLCAST_START" Category: Spell
Fired when a spellcast is begun. This event seems to work if the spell has a casting time.
arg1 Spell Name
arg2 Duration
Would I register for the SPELLCAST_START event?
Then do something like this?
spell.name, spell.duration = SPELLCAST_START( name, duration )
if spell.name = "RESURRECTION"
then
<etc, etc>
end
Then do something like this?
spell.name, spell.duration = SPELLCAST_START( name, duration )
if spell.name = "RESURRECTION"
then
<etc, etc>
end
Nope. SPELLCAST_START is not a function, it's an event. This is a huge difference. When you register an event, you specify a function that is called when this event occurs. I'm not sure how you register your events (Ace1? Ace2? Without Ace?), so I can't help you out there unless you describe what you want to do and what you use to achieve it.
All I'm trying to do is send a message from a table of messages to "SAY" whenever I cast the Resurrection spell.
My mod is written using ACE2 libs at this point.
I've got the function that spits out the message to work, and it bumps up the index on the table to display the next message.
I just need to figure out how to call my function when Resurrection is cast.
Again, I thank you for your assistance, it is very much appreciated.
Perfect! Then it's easy:
1. Register the event in your OnEnable Function with AceEvent
2. Define a function MyAddon:SPELLCAST_START(spellname, duration) (you can name it whatever you want, but don't forget to give RegisterEvent(...) the right name). In this function, compare the name with the name of the ressurection spell and call your message function.
To be safe, print the
spellname
argument to the chatpanel. It might be delivered with rank ("Ressurection (Rank X)"). If so, then you might want to strip the rank:
if(string.find(spellname, "Ressurection .*")) then
<bla, bla>
end
I don't know if this pattern really works, but it's a start.
Quote from Faydra »
Again, I thank you for your assistance, it is very much appreciated.
Well, I must be doing something wrong, I changed the spell to Lesser Heal, just to test the functions without having to res somebody. :)
But, It never appears to get hit the function....
I have:
function FayRes:OnEnable()
self:RegisterEvent("SPELLCAST_START")
end
and then:
function FayRes:SPELLCAST_START(spellname, duration)
self.Print "Just to see if we got here"
if(string.find(spellname, "LESSER .*")) then
self.db.profile.message = messages[self.db.profile.msgnum]
self.db.profile.msgnum = self.db.profile.msgnum + 1
target = UnitName("target")
if self.db.profile.msgnum > 10 then
self.db.profile.msgnum = 1
end
SendChatMessage(self.db.profile.message, "SAY")
end
end
I did both those things and it still never seems to get there - nothing prints. (it hates me). :(
function FayRes:SPELLCAST_START(spellname, duration)
self:Print("Just to see if we got here")
self:Print("Spell: " .. spellname)
self:Print("Duration: " .. duration)
end
And nothing at all happens?
Only other thing I can think of is maybe that only shows HOSTILE spellcasts, maybe try going into an av and see if it starts spitting out stuff on the chatframe?
Well, I ended up borrowing(stealing) code from another mod (hotcandybar or something like that).. and using UNIT_SPELLCAST_SENT instead of SPELLCAST_START. And now it is working! (yay!).
Thank you to whomever I stole from.
Not sure why SPELLCAST_START doesn't work for me. Karma, maybe. I killed a cockroach in a previous life?
I'm very happy though.. my first functioning working mod. :)
That would've been the next thing I would have suggested, poking at other mods that fiddle with spellcasts, see what they use. No reason to tear your hair out trying to reinvent the wheel :)
My mod is almost doing exactly what I want it to do. :)
I just keep slowly plugging away at it.
Couple of things are confusing me though...
I want to do something everytime I cast a particular spell, and I'm not sure how to capture that event?
If you don't want to include the whole library for just one little thing, it depends on the type of spell (instant, channeling, whether you want to do something on casting start or stop, etc). Maybe the Spell Event Section of the WoW-Wiki can help you.
Thank you so much, Nimbal, for the reply.
I don't seem to be able to download the SpellStatus library, so in looking at the other link you posted...
I want to fire my function off whenever I cast Resurrection.
So, looking at this event from your link.
"SPELLCAST_START" Category: Spell
Fired when a spellcast is begun. This event seems to work if the spell has a casting time.
arg1 Spell Name
arg2 Duration
Would I register for the SPELLCAST_START event?
Then do something like this?
spell.name, spell.duration = SPELLCAST_START( name, duration )
if spell.name = "RESURRECTION"
then
<etc, etc>
end
?
Yes
Nope. SPELLCAST_START is not a function, it's an event. This is a huge difference. When you register an event, you specify a function that is called when this event occurs. I'm not sure how you register your events (Ace1? Ace2? Without Ace?), so I can't help you out there unless you describe what you want to do and what you use to achieve it.
All I'm trying to do is send a message from a table of messages to "SAY" whenever I cast the Resurrection spell.
My mod is written using ACE2 libs at this point.
I've got the function that spits out the message to work, and it bumps up the index on the table to display the next message.
I just need to figure out how to call my function when Resurrection is cast.
Again, I thank you for your assistance, it is very much appreciated.
Perfect! Then it's easy:
1. Register the event in your OnEnable Function with AceEvent
2. Define a function MyAddon:SPELLCAST_START(spellname, duration) (you can name it whatever you want, but don't forget to give RegisterEvent(...) the right name). In this function, compare the name with the name of the ressurection spell and call your message function.
To be safe, print the argument to the chatpanel. It might be delivered with rank ("Ressurection (Rank X)"). If so, then you might want to strip the rank:
I don't know if this pattern really works, but it's a start.
No problem.
Of course!!! Too easy, no wonder I couldn't figure it out.
Thank you so much - send me a personal message with your address and I'll send you homemade macadamia nut chocolate chip cookies!
(Not homemade by me, mind you - I have a cooking skill of 1)..
:)
Err, thanks, but I still have roughly half a ton of cookies here. I love Christmas, it's so... sweet and... sweet.
Please note that I have edited my previous post twice (first one to add the string matching, second one to correct an error)
But, It never appears to get hit the function....
I have:
and then:
What am I missing?
Maybe
(Note the colon)
If not that, then I don't know. :-/
self:Print("Spell: " .. spellname)
self:Print("Duration: " .. duration)
etc, its much easier than pulling your hair out trying go guess how blizzard writes things, hehe.
Only other thing I can think of is maybe that only shows HOSTILE spellcasts, maybe try going into an av and see if it starts spitting out stuff on the chatframe?
Thank you to whomever I stole from.
Not sure why SPELLCAST_START doesn't work for me. Karma, maybe. I killed a cockroach in a previous life?
I'm very happy though.. my first functioning working mod. :)
Thanks to all for the /assist.
2.0 changes post is your friend =P
Specifically post 6: