Event checking for spells wearing off.

Need some help with that macro you're working on or aren't quite sure how to get your macro to do something? Ask here!

Moderator: MacroQuest Developers

NotHere
a lesser mummy
a lesser mummy
Posts: 40
Joined: Fri Jan 09, 2004 5:59 am

Event checking for spells wearing off.

Post by NotHere » Sun Mar 21, 2004 10:52 am

Hi.

Trying to work out a kite macro that automatically registers when DOTs wear off, and queues them up for recasting.

Using the following code to test the behavior:

Code: Select all

#event SpellFaded " has worn off."

Sub Main
   :Loop
      /doevents SpellFaded
   /goto :Loop
/return

Sub Event_SpellFaded
  /echo SpellFaded: @Param0
  /delay 5s
/return
The macro sleeps just as its supposed to, up untill the time a spell wears off. Then I get spammed (and lag out, unless I break the macro). The output from the macro is:

Code: Select all

[MQ2] SpellFaded: Your Swarming Death spell has worn off.
[MQ2] SpellFaded: [MQ2] SpellFaded: Your Swarming Death spell has worn off.
[MQ2] SpellFaded: [MQ2] SpellFaded: [MQ2] SpellFaded: Your Swarming Death spell has worn off.
with 5 seconds delay between each line. And it keeps on going, scrolling fast through my chat windows.

Tried looking for an explantaion, but I cant seem to figure it out (Maybe its just the hangover, but fresh eyes might see it).

Any idea what causes this behavior? Am I using the event the wrong way? Do I have to "clear" the event, since it seems to be called over and over again?
NotHere
/afk

Zazoot
a hill giant
a hill giant
Posts: 163
Joined: Sat Feb 07, 2004 11:02 am

Post by Zazoot » Sun Mar 21, 2004 11:06 am

check out the twist.mac in the depot

i think it has a good example of recasting when you see spell faded messages

NotHere
a lesser mummy
a lesser mummy
Posts: 40
Joined: Fri Jan 09, 2004 5:59 am

Post by NotHere » Sun Mar 21, 2004 11:15 am

Got a bit further.

Code: Select all

#event SpellFaded " has worn off."

Sub Main
   :Loop
      /doevents
   /goto :Loop
/return

Sub Event_SpellFaded
  /echo SpellFaded: @Param0
  /doevents flush
/return
This works fine and dandy. Is this the right way to do it?

Also, Im a bit in doubt what happens, if say, the /doevents are only done once every 5 seconds, and two spells fades inside that same period.

Would it be triggered twice, or only once (and with what inside the param?)

More elegant way to do it (Off to look at twist.mac too)?
NotHere
/afk

Gumby
a ghoul
a ghoul
Posts: 99
Joined: Sat Jan 24, 2004 5:27 pm

Post by Gumby » Sun Mar 21, 2004 12:36 pm

NotHere wrote:Got a bit further.

Code: Select all

#event SpellFaded " has worn off."

Sub Main
   :Loop
      /doevents
   /goto :Loop
/return

Sub Event_SpellFaded
  /echo SpellFaded: @Param0
  /doevents flush
/return
This works fine and dandy. Is this the right way to do it?

Also, Im a bit in doubt what happens, if say, the /doevents are only done once every 5 seconds, and two spells fades inside that same period.

Would it be triggered twice, or only once (and with what inside the param?)

More elegant way to do it (Off to look at twist.mac too)?
*chuckle*

Been there done that, and yeah, it's easy to overlook for first runs through scripting with events.

What's happening with the first code is you're /echoing out the initial Text which triggered the #event in the first place. Since #events parse on matches to what you have defined, a "[MQ2] blah blah worn off" meets the requirements to executue it

What this creates is a cyclic loop, causing the event to be triggered over, and over, and over again as events can trigger from any chat medium including MQ2ChatWnd (or MQ2Chat). The /doevents flush "works" but I don't recommend it... I've had it crash one my macros when executed from a Sub Event as you have though I was attempting to do something more complicated. You also, if two events were triggered at really close quarters, could conceivably flush a good event too but it's unlikely giving your basic loop ninja executing /doevents.

As for "corrections", simply don't echo out the full text. Really for macros beyond simple notification you're going to want individual spells being evented as there's a large difference between a snare wearing off and a dot's wearing off from a macro execution / response perspective, but this:

Code: Select all

#event SpellFaded " has worn off."

Sub Main
   :Loop
      /doevents
   /goto :Loop
/return

Sub Event_SpellFaded
  /echo SpellFaded
/return
Would work but only give you "SpellFaded" (admittably not what you're attempting to accomplish). To be notified as to *what* specific spell faded, use $arg and a loop to hack out the spell name.

As an illustration, taking Ensnare as an example, the wearing off would be:

"Your Ensnare spell has worn off"

Simply $arg(2,"@Param0") to pick up the word "Ensnare" out of the event text. If you want to get the full spell name, you'll need to repeat args through and build a small text string (or array or whatever) until the word parsed matches "spell" at which point you're done and /echo out the resulting string or array elements.

I'd also recommend putting a delay in your loop too, as a half second or second difference will matter not much at all, and when you add more things (or even #turbo) it'll keep resource utilization down.

G

NotHere
a lesser mummy
a lesser mummy
Posts: 40
Joined: Fri Jan 09, 2004 5:59 am

Post by NotHere » Sun Mar 21, 2004 1:50 pm

Gumby wrote:What this creates is a cyclic loop, causing the event to be triggered over, and over, and over again as events can trigger from any chat medium including MQ2ChatWnd (or MQ2Chat).
DOH! :oops:

Totally overlooked this one (and didnt consider that MQ2ChatWnd was monitored anyway).

What Im trying to accomplish is a generic kite script that allows you to program it with anchors and dots/nukes to use, and saving those into an .ini file. When it get to a point where I think its good, I'll throw it in the Depot.

Thanks alot for the help, helped me immensily. :D
NotHere
/afk