Events

Need help running MacroQuest2? Ask your questions about how to get things to work on your computer.

Moderator: MacroQuest Developers

chrismed
a lesser mummy
a lesser mummy
Posts: 38
Joined: Sat Jan 22, 2011 8:27 pm

Events

Post by chrismed » Sat Nov 12, 2011 1:25 pm

I have read the /doevents on wiki and understand what it does just not the best use of it.
My resent rewrite of my Enchanter's macro makes it obvious that I don't completely understant "Events" or the /doevents completely.
Though I have had success with custom events, I have also run into some problems with them that I have played with and played with and just don't understand.

Fist I will give you what I have written for my enchanter then explain the problem I'm having:

Code: Select all

#include Spell_routines.inc
#turbo 40
#chat group
#chat tell


#event mezthis "#1# tells the group, 'mez'"
#event runeme "#1# tells the group, 'rune'"
#event mindcandyall "#1# tells the group, 'mindcandy all'"
#event givemindcandy "#1# tells the group, 'mindcandy'"
#event helpcommands "#1# tells the group, 'Pandorica'"





Sub Main

/declare Mez   string outer   Entrance
/declare Dot   string outer   Suffocate
/declare Nuke  string outer   Anarchy
/declare haste string outer   Alacrity
/declare rune  string outer   Rune II
/declare MindCandySpell    string outer   Clarity

/declare dotimer       timer outer
/declare nuketimer     timer outer
/declare hastetimer    timer outer
/declare MTank    string outer  (Name of my Tank)

/declare x int local

|*****Med Loop*****|

:start
  /if ((!${Me.Casting.ID}) && (${Me.State.Equal[STAND]}) & (${Me.PctMana}<98)) /sit
/doevents  
/delay 10
  /if (${Me.PctMana}>30) /goto :next
/goto :start

:next
/doevents
/assist ${MTank}
/delay 1s
/if (${Target.PctHPs}<75 && ${Me.PctMana}>65 && ${Target.Type.NotEqual[CORPSE]} && ${Target.Type.Equal["NPC"]} && ${dotimer}==0) {
/call cast "${Dot}" gem1 3s
/varset dotimer 1m
}
/goto :nuking


:nuking
/assist &{MTank}
/delay 1s
/if (${Target.PctHPs}<75 && ${Me.PctMana}>65 && ${Target.Type.NotEqual[CORPSE]} && ${Target.Type.Equal["NPC"]} && ${nuketimer}==0) {
/call cast "${nuke}" gem2 3s
/varset nuketimer 10s
}
/goto :hastetank

:hastetank

/assist ${MTank}
/delay 1s
/if (${Target.PctHPs}<98 && ${Target.Type.Equal["NPC"]} && ${hastetimer}==0) {
/target ${MTank}
/delay 1s
/call cast "{haste}" gem 4 3s
/varset hastetimer 8m
}
/goto :start
/return



|-----------------------------------------------------|
|   CHAT COMMANDS type Help in channel for commands   |
|-----------------------------------------------------|

Sub Event_mezthis(Targ)
/assist ${Targ}
/delay 1s
/g Mezzing ==> [ %t ]
/call Cast "${Mez}" gem5 3s
/if (${Macro.Return.Equal[CAST_SUCCESS]}) /goto :mezsuccess
/if (${Macro.Return.Equal[CAST_IMMUNE]}) /goto :mezimmune


:mezsuccess
/g [ %t ] <== is mezzed, you break it you buy it!
/return

:mezimmune
/g [ %t ] <== sorry, it's immune to my wildly charms...
/return


Sub Event_runeme(Targ)
/target ${Targ}
/call cast "${rune}" gem7 3s
/return


Sub Event_givemindcandy(Line,Targ)
/assist ${Targ}
/delay 1s
:gmc
/call cast "${MindCandySpell}" gem8 3s
/if (${Macro.Return.Equal[CAST_SUCCESS]}) /goto :givemindcandysuccess
/goto :gmc

:givemindcandysuccess
/g enjoy the ${MindCandySpell} [ %t ], some one was thinking of you...
/return


Sub Event_helpcommands(Line)
/g mez - I will mez your target master!
/delay 1s
/g mindcandy all - will give everyone that needs it my mindcandy
/delay 1s
/g mindcandy - I will give peace to you or someone that is close to you.
/return


Sub Event_mindcandyall(Line)
/g One Moment Plz Giving Everyone Mindcandy!
/declare g int local
/for g 0 to ${Group}
/if (${Group.Member[${g}].Type.NotEqual[CORPSE]}) /call castingmindcandy ${Group.Member[${g}].CleanName}
/next g
/return

Sub castingmindcandy(Targ)
/target ${Targ}
/delay 1s
/if (${Target.ID} && ${Select[${Target.Class.ShortName},SHD,PAL,RNG,BST,SHM,CLR,DRU,WIZ,MAG,ENC,NEC]}) /call cast "${MindCandySpell}"  gem8 3s
/return
1st.
The events where working correctly untill I just rewrote it. I have added things in the Sub Main that assists the Main Tank and so she keeps the Tank targeted majority of the time and besides the spell upgrades and some of the things in the Sub Main, I haven't touched the #events / Sub Event_(s).

2nd.
The problem is- Before I rewrote most of the Sub Main the #events where working corrctly. My wife, with her toon, could call commands as well as I and they would work for either one of us. It would trigger the event and target/assist the person triggering the event. No though it seems I'm having problems with it all of a sudden.

The problem to me specific, now after the rewrite, My wife say in group "mez" it keeps me targeted and either tried to mez me or what I have targeted like if I said it (I play the Main Tank).

Code: Select all

Sub Event_mezthis(Targ)
/assist ${Targ}
This worked before and now it's not. I do:

Code: Select all

/echo ${Targ}
and it returns

Code: Select all

[MQ2] (name of wife's toon)
which is correct. But for some reason I use /target or /assist it stay on me.
NOW ... with that said... I can replace ${Targ} with her name exactly and it will /assist her and do what it is suppose to but then only SHE can use the event. (wierd and I don't understand this)

Next problem....
The "rune" event.. worked fine before I rewrote (again didn't touch ANY of the #events or Sub Event_(s) when I rewrote the macro) but now when my wife or I say "rune" in group chat it keeps me targeted both times and continuosly casts rune. The error I'm getting is:

Code: Select all

There are no spawns matching: (0-100) any there are no spawns matching:(0-100) there are no spawn matching:(0-100) (name of my tank or my wife's toons name depending on who called rune) tells the group, 'rune'
Now I did notice one mistake I had made when I first start that for some reason kept the events from working at all. That was the /doevents at the top of the Sub Main in my sit/med section of my macro. For some reason since I forgot that (which I include it in all my macros there for medding for any caster macros, usualy just copy/paste) the events wouldn't work at all. With in there they started working but that was when I noticed these other problems.

Again have no idea why I'm having these problems now and after spending a few hours trying to fix I'm not sure how. It was working.. "someone" in the group triggers the event and it targets/assists the person saying it and does the event. but now it's not.

drzoon
a hill giant
a hill giant
Posts: 239
Joined: Tue May 04, 2004 5:38 pm

Re: Events

Post by drzoon » Sat Nov 12, 2011 4:39 pm

Your problem is occuring because every #event passes the full matching line as the first parameter to the sub. This is a feature of the #event code and cannot be changed. Additional variables, specified by #1#, #2#, etc, are passed as parameters after the initial line.

To fix this, change every Sub Event_blah(Targ) to Sub Event_blah(Line,Targ) and it should work fine. For example, change:

Code: Select all

Sub Event_mezthis(Targ)
to

Code: Select all

Sub Event_mezthis(Line,Targ)
This should fix both of your specified issues, and probably some others.


PS: Your haste section won't work either, the line:

Code: Select all

/call cast "{haste}" gem 4 3s
should be changed to

Code: Select all

/call cast "${haste}" gem4 3s

chrismed
a lesser mummy
a lesser mummy
Posts: 38
Joined: Sat Jan 22, 2011 8:27 pm

Re: Events

Post by chrismed » Sat Nov 12, 2011 4:57 pm

I have been trying:

Code: Select all

Sub Event(Line,Targ)
/assist ${Targ}
and

Code: Select all

Sub Event(Targ)
/assist ${Targ}
Either way it's still keeping my MTank targeted and assisting him the entire time no mater who I have in the group say "mez".
I see I do have to have the (Line,Targ) in there.. instead of getting just the name I get the entire line if I just have (Targ).
I replaced /assist with echo to see what it was doing.

Which brings me back to the same problem.
When I /echo instead of /assist with the (Line,Targ) it is giving the name of the person saying mez:
Line:

Code: Select all

Sub Event_mezthis(Line,Targ)
/echo ${Targ}
it gives me this:

Code: Select all

[MQ2] (persons name saying mez)
(keeps MTank targeted the entire time)

I replace again with:

Code: Select all

/assist ${Targ}
Instead of targeting who ever says it (which it doesn't matter who says it which is half right) it still remains targeting and assisting my MTank. UNLESS instead of ${Targ} I use /assist (Specific Name). This results in anyone saying mez and it will trigger the event then switches to the persons name listed with the /assist... But again only half right. I want it to /assist the person saying it.

drzoon
a hill giant
a hill giant
Posts: 239
Joined: Tue May 04, 2004 5:38 pm

Re: Events

Post by drzoon » Sat Nov 12, 2011 5:35 pm

To be clear I understand this, is the following what is happening?

1. There is a group of 3 members: Bob (tank), Jane (chanter) and Fred.
2. Bob is targeting Mob1 and tanking it.
3. Jane is targeting Bob.
4. Mob2 runs in as an add.
5. Fred targets Mob2 and says in group "mez".
6. Jane keeps targeting Bob and attempts to mez Bob.

If this is not the correct understanding, then please let me know what is happening. Also, what target is returned in group chat when the mez is triggered, ie. what is the result of this line:

Code: Select all

/g Mezzing ==> [ %t ]
For the assist code in your mez sub to work, the person saying "mez" in group needs to be targeting the mob that needs to be mezzed. But if that is the case, then I can't immediately see why your code is not working.

chrismed
a lesser mummy
a lesser mummy
Posts: 38
Joined: Sat Jan 22, 2011 8:27 pm

Re: Events

Post by chrismed » Sat Nov 12, 2011 6:50 pm

Yes that is correct. If the "tank" doesn't have anything targeted then the enchanter keeps the tank targeted. I f mez is called by someone in the group, and the tank is fighting something, she will target that mob (like she is doing in the Sub Main anyway) and will proceed to mez the mob that the tank is fighting INSTEAD of mezing the mob that the other person in the group has called.

Now if I replace the code /assist ${Targ} with /echo ${Targe} it is returning the persons name that is calling mez.
BUT if I use /assist ${Targ} or /target ${Targ} it is triggering the event BUT it's like those 2 items (/assist and/or /target) aren't even there and continues to try to assist through the tank.


I don't get it and yes .. I THINK the way I have it written it should work.... but it isn't which I don't get.

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: Events

Post by dewey2461 » Sat Nov 12, 2011 8:40 pm

EDIT: Just reread your code and you aren't using tells so this shouldn't apply but might be handy.

When you get a name from an event you need to strip off the hidden characters used to make the name a link.

Code: Select all


Sub Event_DoTell(string line, string Requestor, string Request)
    |/echo Line -${line}-
    |/echo Requestor -${Requestor}-
    |/echo Request -${Request}-
    /declare isTrusted int

	/if (${Requestor.Left[1].Compare[ ]}<0) /varset Requestor ${Requestor.Right[-2].Left[-1]} 

     |--- rest of the code
/return

chrismed
a lesser mummy
a lesser mummy
Posts: 38
Joined: Sat Jan 22, 2011 8:27 pm

Re: Events

Post by chrismed » Sun Nov 13, 2011 2:15 am

Ya, I remember this from when I first started writting the code for these macros. At the time someone had actualy given me the answer (this was about 4 weeks ago and was when I had ever touched any coding like this at all) but I didn't understand it enough to apply it. I finaly found a slight work around that worked for what I was wating to do at the time. Now though I have gotten to things where I needed to know how to do this and figure out why it wasn't working.
Thanks to don't_know_all I remembered this and also found the salution. Ya there are a few ways to write it but I found this to work well which is basicly the same thing you listed up there:

Code: Select all

Sub Event_mezthis(Line,Targ)
/target ${Targ.Right[-2].Left[-1]}
/assist
Now, I also asked if this would work everytime for this (.Right[-2].Left[-1]) and the answer was "it should".

I was wondering... is there a way to echo with the hidden characters? So you can see what it actualy returning? Just wondering.
Hope this information helps anyone who runs across the same problem with targeting and an event that doesn't know about this. I had been searching the forums for an answer to this and there was one, even though I couldn't ever find it. I was pointed to it thankfully. I forgot the link now but hopefully this one will help.

drzoon
a hill giant
a hill giant
Posts: 239
Joined: Tue May 04, 2004 5:38 pm

Re: Events

Post by drzoon » Sun Nov 13, 2011 1:02 pm

I've looked at your code and it should work as you expect. The fact that when you /echo ${Targ} you get the correct value, indicates that the correct value is being passed to the sub.

So it appears that there is an issue with the /assist line or with the /delay line. After thinking about it for a while, I wonder if the problem is a range issue. AFAIK, /assist has a fairly low range, so there's a chance that you're not close enough to whoever is calling "mez" to /assist successfully, and therefore it is not changing your target. I can think of two ways of dealing with this:

Firstly, you could clear the chanter's target before assisting, and then if you have no target after /assisting, then you do nothing. This doesn't fix the problem though, but it does prevent the chanter from mezzing the wrong mob.

Code: Select all

Sub Event_mezthis(Line,Targ)
/target clear
/assist ${Targ}
/delay 1s
/if (${Target.ID}) {
  /g Mezzing ==> [ %t ]
  /call Cast "${Mez}" gem5 3s
  /if (${Macro.Return.Equal[CAST_SUCCESS]}) /goto :mezsuccess
  /if (${Macro.Return.Equal[CAST_IMMUNE]}) /goto :mezimmune

  :mezsuccess
  /g [ %t ] <== is mezzed, you break it you buy it!
  /return

  :mezimmune
  /g [ %t ] <== sorry, it's immune to my wildly charms...
}
/return
The other possible solution is for the other player to call out the ID of the target that they want mezzed. So instead of just saying "/g mez", they say "/g mez ${Target.ID}". Although this will really only work if they use a hotkey rather than just typing "/g mez".

Code: Select all

#event mezthis "#1# tells the group, 'mez #2#'"

Sub Event_mezthis(Line,Targ,int TargID)
/target id ${TargID}
/delay 1s
/if (${Target.ID}==${TargID}) {
  /g Mezzing ==> [ %t ]
  /call Cast "${Mez}" gem5 3s
  /if (${Macro.Return.Equal[CAST_SUCCESS]}) /goto :mezsuccess
  /if (${Macro.Return.Equal[CAST_IMMUNE]}) /goto :mezimmune

  :mezsuccess
  /g [ %t ] <== is mezzed, you break it you buy it!
  /return

  :mezimmune
  /g [ %t ] <== sorry, it's immune to my wildly charms...
}
/return
Additionally, you could use something like TargetOfTarget, which doesn't have a range limitation, but requires that Group Leadership ability. Or you could use XTarget to determine adds. Both of these methods are more complicated though.

Blitter
a hill giant
a hill giant
Posts: 151
Joined: Sat Dec 29, 2007 11:07 pm
Location: Sky

Re: Events

Post by Blitter » Sat Nov 19, 2011 1:03 am

Agree with the above poster, I use EQBC and my tank /bc's his target ID, I'll use extended targets to then get everything else.
Howevert a thing you could try is check your target types b4 the mez.

Code: Select all

Sub Event_mezthis(Line, AssistTarg)
/assist ${AssistTarg}
/delay 15 ${Target.Type.Equal[NPC]}
/if (${Target.Type.Equal[NPC]) {
  /g Mezzing ==> [ %t ]
  /call Cast "${Mez}" gem5 3s
  /if (${Macro.Return.Equal[CAST_SUCCESS]}) {
      /g [ %t ] <== is mezzed, you break it you buy it!
  } elseif {
  /if (${Macro.Return.Equal[CAST_IMMUNE]}) {\
     /g [ %t ] <== sorry, it's immune to my wildly charms...
  }
}
/return
This is a longer /delay but it will move on if as soon as you've got an NPC targeted.

I would also had a couple more /doevents between you nuke and dot ,etc. It could be in the middle of a cast, and you targeter person points and /g mez waits 2-3 secs and it still isn't quite long enuf. /g mez will only be interpreted at the /doevents. When this mac starts, it will dot,nuke and haste b4 with no /doevents in between.

Blitter
a hill giant
a hill giant
Posts: 151
Joined: Sat Dec 29, 2007 11:07 pm
Location: Sky

Re: Events

Post by Blitter » Sun Nov 20, 2011 9:57 pm

Just one further thing.

I have a similar include file that helps others control my toons. You could implement it and add in requests for haste/buffs/nukes/etc as I've done for magician "Fire Skin" and clerics "DL". It will only take commands from a MasterToon list you can add to each macro you run. As you can see further down, folks could also ask you to load a new macro and they can ask you to camp out at the end of the night or if you have the cleric, and wipe, they can ask you to campfire back and rez the group up. Anyways it might help.

#include control.inc
/declare MasterToon string Bob|Fred|Jim|Alfred

control.inc

Code: Select all

#include wait4rez.inc
#include spell_routines.inc

#event BCCommand "<#1#> #2# #3#"
#event CommandList "#1# tells you, '#2# #3# #4# #5# #6#'"
#event CommandList "#1# tells you, '#2# #3# #4# #5#'"
#event CommandList "#1# tells you, '#2# #3# #4#'"
#event CommandList "#1# tells you, '#2# #3#'"
#event CommandList "#1# tells you, '#2#'"
#event Invited "#1# invites you to join #*#"
#event died "#*#Returning to home point, please wait...#*#"
#event died "#*#you have been slain#*#"

Sub Event_Invited(Line1,Toon)
 /if (!${MasterToon.Find["${Toon}"]}) {
    /echo Tell sent from non commander
    /delay 2s
    /return
  }
  /nomodkey /keypress invite_follow
/return

Sub Event_BCCommand(Line1,Toon1,Com1,Com2)
   /if (!${MasterToon.Find["${Toon1}"]}) {
    /echo Tell sent from non commander
    /doevents flush
    /delay 2s
    /doevents flush
    /return
 }
  /if (${Com1.Equal[DL]} && ${Me.Class.Name.Equal[Cleric]}) {
     /tar ${Com2}
     /delay 2s ${Target.Name.Equal[${Com2}]}
     /fs DL %T
     /call Cast "Divine Light" -maxtries|3
     /delay 1s
  }
  /if (${Com1.Equal[CH]} && ${Me.Class.Name.Equal[Cleric]}) {
     /tar ${Com2}
     /delay 2s ${Target.Name.Equal[${Com2}]}
     /fs CH %T
     /call Cast "Complete Heal" -maxtries|3
     /delay 1s
  } 
 /if (${Com1.Equal[DS]} && ${Me.Class.Name.Equal[Magician]}) {
   /tar pc ${Com2}
   /delay 3s ${Target.Name.Equal[${Com2}]}
   /tgb
   /if (${Target.Distance}<90) /casting "Fireskin" -maxtries|2
   /delay 2
   /delay 9s !${Me.Casting.ID}
   /delay 4
  }
/return

Sub Event_CommandList(Line1,Toon1,Com1,Com2,Com3,Com4,Com5)
/declare Toon string inner
  /varset Toon ${Toon1.Right[-2].Left[-1]}
  /if (!${MasterToon.Find[${Toon}]}) {
    /echo Tell sent from non commander
    /doevents flush
    /delay 2s
    /doevents flush
    /return
  }
  /if (${Com1.Equal[hi]}) {
    /fs Rez [X/ALL]
    /delay 1
    /fs MakeLeader X
    /delay 1
    /fs Campfire
    /delay 1
    /fs Camp
    /delay 1
    /fs Heal X PR DL SE
    /delay 1
    /fs Follow [X]
    /delay 1
    /fs DS [X]
    /delay 1
    /fs Merc - toggles merc
    /delay 1
    /fs CH X  - complete heal
    /delay 2
    /fs Load XX - Pull or Base
    /delay 2
    /fs Sit
    /delay 2
    /fs Loot  - toggle looting
  }
 /if (!${Defined[Com2]}) {
    /declare Com2 string inner
    /varset Com2 ${Toon}
 }
 /if (${Com1.Equal[MakeLeader]}) /makeleader ${Com2}
 /if (${Com1.Equal[DI]}) {
   /tar pc ${Com2}
   /delay 3s ${Target.Name.Equal[${Com2}]}
   /casting "Divine Intervention" -maxtries|2
   /delay 2
   /delay 5s !${Me.Casting.ID}
   /if (${Cast.Result.Equal[CAST_SUCCESS]}) {
     /fs DI on %T
   } else {
     /fs DI failed
   }
  }
  /if (${Com1.Equal[Follow]}) {
   /tar pc ${Com2}
   /delay 3s ${Target.Name.Equal[${Com2}]}
   /afol
   /fs Follow ${AdvPath.State}
  }
 /if (${Com1.Equal[Camp]}) {
   /fs Camping...
   /camp desktop
  }
  /if (${Com1.Equal[Rez]}) {
   /tar ${Com2}
   /delay 3s ${Target.Name.Equal[${Com2}]}
    /casting "Reviviscence" -maxtries|4
   /delay 2
   /delay 10s !${Me.Casting.ID}
   /if (${Cast.Result.Equal[CAST_SUCCESS]}) {
     /fs Rez on %T
   } else {
     /fs Rez failed
   }
  }
 /if (${Com1.Equal[DS]}) {
   /tar pc ${Com2}
   /delay 3s ${Target.Name.Equal[${Com2}]}
   /tgb
   /if (${Target.Distance}<90) /casting "Fireskin" -maxtries|2
   /delay 2
   /delay 9s !${Me.Casting.ID}
   /delay 4
  }
  /if (${Com1.Equal[Merc]}) /notify MMGW_ManageWnd MMGW_SuspendButton leftmouseup
  /if (${Com1.Equal[Campfire]}) {
    /delay 20s ${Me.CombatState.Equal[ACTIVE]}
    /casting "Fellowship Registration Insignia"
    /delay 2
  }
/if (${Com1.Equal[CH]}) {
   /tar ${Com2}
   /delay 3s ${Target.Name.Equal[${Com2}]}
   /fs CH %T
    /casting "Complete Heal" -maxtries|2
   /delay 2
   /delay 12s !${Me.Casting.ID}
 }
/if (${Com1.Equal[Sit]}) {
  /sit
}
/if (${Com1.Equal[DL]}) {
   /tar ${Com2}
   /delay 3s ${Target.Name.Equal[${Com2}]}
   /fs DL %T
    /casting "Sacred Light" -maxtries|2
   /delay 2
   /delay 12s !${Me.Casting.ID}
}
/if (${Com1.Equal[Load]}) {
  /if (${Com2.Equal[Pull]}) /mac ${Com2}
  /if (${Com2.Equal[Camp]}) /mac ${Com2}
  /if (${Com2.Equal[Base]}) /mac ${Com2}
  /if (${Com2.Equal[Wizard]}) /mac ${Com2}
  /fs Try again.
}
/if (${Com1.Equal[Loot]}) {
   /if (${Looter}) {
     /fs Not looting
     /varset Looter 0
   } else {
     /fs I am looting...
     /varset Looter 1
   }
 }
  /doevents flush
/return

Sub Event_died
  /echo dead
  /call Wait4Rez
/return