- Joined
- Sep 1, 2008
- Messages
- 250
- Reaction score
- 2
- Points
- 0
Greetings,
Ive decided to attempt to write a basic "How to write your own Macro's" manual. Hopefully as this evolves, i'll be able to add links to various topics so it is easier to find what you're looking for. As well, there are many members here that are very experienced with writing macro's, and they will hopefully add to this. I realize that i'll be skipping a LOT of stuff at the beginning, but if i chase down every bunny trail as i come across it, this wont make any sense. As well, i dont know everything, so feel free to correct me if i bumble anything
First, lets go over the anatomy of a macro.
Events
At the top of a macro you'll find your Events. The macro will monitor what is happening in EQ, and if it receives text that matches your Events, it will enact upon it at the next /doevents line. An Event looks like this:
The Event is called "Slowed", the text watching for is "slows down". Using #*#, you dont have to write the entire line to watch for. Any text before and after "slows down" will be acceptable.
Included Reference Files
Many macros use other files for reference on how to do things. A common one is Spell_Routines.inc. This file adds commands to your macro that will allow you to do more complex things.
Sub Main
All macros need to have a Sub Main, where everything branches off of. Inside your Sub Main, you'll have all the things that you want to happen in your macro, and all the things that happen will eventually return here.
Inside your Sub Main you can put Declares, your Main Loop, call other Sub's and basically keep it as simple or complex as you'd like. Simple is better More on these things below.
Declares
This section is probably the most confusing part of a macro, and a lot of playing around and asking questions in IRC are probably your strongest assests. Declares are written inside your Sub Main. A declare is a statement that is saying "Let something = X". For example
If you wanted to keep track of how many mobs died during the course of your macro, you would need to declare your DeadCount. This wont do it all by itself however, it ties into another part of your macro. At whatever point in your macro a mob dies, you would add
Then, so you know how many mobs have died, you could insert an /echo (text that MQ sends to your MQ window that only you see that reports information back to you from the macro)
Here's another example. Say you're doing an AFK macro, but you want your buddy to be able to join your character if he logs in when you're afk. But sometimes you dont want him to be able to. Here's where a declare comes in handy. You can change this without editing your macro every time you change your mind. Start with the declare
Right now, the CanInvite is set to TRUE. For your buddy to activate it, you'll need an Event.
So, when your buddy sends you the password, it will activate the event at the next /doevent line. Here's the actual event sub
Somewhere in your macro, you'll need something like this. I'll explain what each line means.
This line is where the macro will go after it hits your /doevent. When your buddy sends you the tell, the macro takes note that the password matches your event, and then stores that information until the next /doevent. When that happens, it takes action and goes to the event, in this case, InviteMe. The (Line, Player) keeps track of the name that sent the tell. This allows your buddy to log on different characters without you having to write an InviteMe event for every one of them.
If CanInvite is TRUE, the macro will execute the commands inside the {} brackets. In this case, thats
So your buddy is invited. Then your macro skips down to /return and progresses from where it jumped off at the /doevents. However, if InviteMe was FALSE, this would happen
You can change the TRUE and FALSE remotely with a second event. This allows you to do it within EQ without having to edit the macro itself at all.
This event would link to a Sub for YesInvite
Here's one last example for Declares for now. Say you want your macro to end if you ever leave the zone. This comes in handy for obvious reasons. Lets start with the declare
Then we can add 'checks' in our macro in various places (especially in loops) to make sure we're still in the same zone. Here's an example
We'll do more declares later
Main Loop
This is where the circle of a macro occurs that keeps it looping back upon itself. If you dont want a macro to go continuously, you'd obviously not have it. Here's what it will look like
So basically once this loop starts, it will do 'All your junk' and then hit the "/goto :Main_Loop" where it will return to the top and do it all over again. I reccommend keeping your Main Loop as simple as possible and to branch off from there with /call's and /doevents.
Call Subs
To do various things within your macro, you'll want to write them within Subs. You can /call Sub's from your Main Loop, or from other places within your macro. I'll use a Zonecheck Sub as an example. Whenever you want your macro to do a zonecheck, you can write
When your macro hits this line, it will deviate from where it was going and go to your Sub Zonecheck. Here's an example of Sub Zonecheck.
All sub's must end with a /return.
Thus concludes the anatomy of a macro. Next i'll do commands and structure.
Ive decided to attempt to write a basic "How to write your own Macro's" manual. Hopefully as this evolves, i'll be able to add links to various topics so it is easier to find what you're looking for. As well, there are many members here that are very experienced with writing macro's, and they will hopefully add to this. I realize that i'll be skipping a LOT of stuff at the beginning, but if i chase down every bunny trail as i come across it, this wont make any sense. As well, i dont know everything, so feel free to correct me if i bumble anything
First, lets go over the anatomy of a macro.
Events
Reference Files
Sub Main
Declares
Main Loop
Calls
/doevents
Return to Main Loop
/return
Subs
Events
At the top of a macro you'll find your Events. The macro will monitor what is happening in EQ, and if it receives text that matches your Events, it will enact upon it at the next /doevents line. An Event looks like this:
#Event Slowed "#*#slows down#*#"
The Event is called "Slowed", the text watching for is "slows down". Using #*#, you dont have to write the entire line to watch for. Any text before and after "slows down" will be acceptable.
Included Reference Files
Many macros use other files for reference on how to do things. A common one is Spell_Routines.inc. This file adds commands to your macro that will allow you to do more complex things.
#include Spell_Routines.inc
Sub Main
All macros need to have a Sub Main, where everything branches off of. Inside your Sub Main, you'll have all the things that you want to happen in your macro, and all the things that happen will eventually return here.
Sub Main
/return
Inside your Sub Main you can put Declares, your Main Loop, call other Sub's and basically keep it as simple or complex as you'd like. Simple is better More on these things below.
Declares
This section is probably the most confusing part of a macro, and a lot of playing around and asking questions in IRC are probably your strongest assests. Declares are written inside your Sub Main. A declare is a statement that is saying "Let something = X". For example
/declare DeadCount int outer
/declare MobsDead int outer 0
If you wanted to keep track of how many mobs died during the course of your macro, you would need to declare your DeadCount. This wont do it all by itself however, it ties into another part of your macro. At whatever point in your macro a mob dies, you would add
/varcalc MobsDead ${MobsDead} + 1
Then, so you know how many mobs have died, you could insert an /echo (text that MQ sends to your MQ window that only you see that reports information back to you from the macro)
/echo ${MobsDead} killed
Here's another example. Say you're doing an AFK macro, but you want your buddy to be able to join your character if he logs in when you're afk. But sometimes you dont want him to be able to. Here's where a declare comes in handy. You can change this without editing your macro every time you change your mind. Start with the declare
/declare CanInvite bool outer TRUE
Right now, the CanInvite is set to TRUE. For your buddy to activate it, you'll need an Event.
#Event InviteMe "#*#password#*#"
So, when your buddy sends you the password, it will activate the event at the next /doevent line. Here's the actual event sub
Sub Event_InviteMe(Line, Player)
/if (${CanInvite} ) {
/dzadd ${Player}
/invite ${Player}
} else {
/tell ${Player} inviting is currently off
}
/return
Somewhere in your macro, you'll need something like this. I'll explain what each line means.
Sub Event_InviteMe(Line, Player)
This line is where the macro will go after it hits your /doevent. When your buddy sends you the tell, the macro takes note that the password matches your event, and then stores that information until the next /doevent. When that happens, it takes action and goes to the event, in this case, InviteMe. The (Line, Player) keeps track of the name that sent the tell. This allows your buddy to log on different characters without you having to write an InviteMe event for every one of them.
/if (${CanInvite} ) {
If CanInvite is TRUE, the macro will execute the commands inside the {} brackets. In this case, thats
/dzadd ${Player}
/invite ${Player}
So your buddy is invited. Then your macro skips down to /return and progresses from where it jumped off at the /doevents. However, if InviteMe was FALSE, this would happen
} else {
/tell ${Player} inviting is currently off
}
You can change the TRUE and FALSE remotely with a second event. This allows you to do it within EQ without having to edit the macro itself at all.
#Event YesInvite "#*#different password#*#"
This event would link to a Sub for YesInvite
Sub Event_YesInvite
/echo inviting now enabled
/varset CanInvite TRUE
/return
Here's one last example for Declares for now. Say you want your macro to end if you ever leave the zone. This comes in handy for obvious reasons. Lets start with the declare
/declare MyZone string outer ${Zone}
Then we can add 'checks' in our macro in various places (especially in loops) to make sure we're still in the same zone. Here's an example
/if (!${Zone.Name.Equal[${MyZone}]}) {
/end
}
We'll do more declares later
Main Loop
This is where the circle of a macro occurs that keeps it looping back upon itself. If you dont want a macro to go continuously, you'd obviously not have it. Here's what it will look like
:Main_Loop
All your junk
/doevents
/goto :Main_Loop
So basically once this loop starts, it will do 'All your junk' and then hit the "/goto :Main_Loop" where it will return to the top and do it all over again. I reccommend keeping your Main Loop as simple as possible and to branch off from there with /call's and /doevents.
Call Subs
To do various things within your macro, you'll want to write them within Subs. You can /call Sub's from your Main Loop, or from other places within your macro. I'll use a Zonecheck Sub as an example. Whenever you want your macro to do a zonecheck, you can write
/call Zonecheck
When your macro hits this line, it will deviate from where it was going and go to your Sub Zonecheck. Here's an example of Sub Zonecheck.
Sub ZoneCheck
/if (!${Zone.Name.Equal[${MyZone}]}) {
/sit
/camp
/mqlog I logged off because i wasnt in the right zone!
/end
}
/return
All sub's must end with a /return.
Thus concludes the anatomy of a macro. Next i'll do commands and structure.