MQEmulator.net • View topic - Macro basics (2024)

Macro basics - a tutorial

Pretty much all macroquest commands, and all eq commands are co-mingled while MQ2 is loaded. This means that while you are in game you can type /target npc, and it will target the closest npc. This is a mq command. Alternatively if you are writing a macro, you can put /rude or /salute in it, and it will perform the same funciton it does when you type it in game.

Hello.mac

Macro

Way the start overly simple eh... dunno who's gonna be reading this so here we go.
#turbo can be set from 1 to 20. It declares the number of lines that can be executed per iteration. This stops bad macros from crashing eq.

Code is broken down into smaller modular parts called Subs. Imagine these as parts on an engine. The engine isn't built as 1 solid piece, its several modular chunks. If you carburetor goes bad you just pull it off and swap it. Same with subs, if your sub that makes you follow your tank goes bad you just have to work on that small sub, and not anything else in your program.

Sub Main - always remember that this is the first line of your code that macroquest will start executing. So the "/say Hello EQ!", which does the same thing it would in game will be the first thing out of this macro.

/return - for right now, all you need to know about this is it is the end of your Sub.

firstvariable.mac
Hello.mac

Macro

A variable is a place to save information. Like a percentage that you want your cleric to heal your warrior at. Before you use your variable you have to declare it. /declare <name> <type> <scope> <value>. The name is just what you want to call it, it is case sensitive. The type is typically going to be string or int, which is text or number. The scope... this is where your code first starts to become neat or sloppy. Mine is really sloppy =). Inner means that it can be used within the Sub it was declared in, if you try to use it in another sub it wont exist there. This is very important. Say for instance you are using a variable to count a number "Index" and you use it to count spawns withing 100ft of you, and in another place you use it to count guild members within 10 feet of you. If those two subs execute at the same time, those values could get mixed up. If you declare them as "inner" then they only exist withing their own subprogram, and each one would be unique to its own sub, and they won't get mixed up. If you do need a value across all subs then you declare it as "Outer". The value is optional, default is NULL which means nothing. Since it is optional I could have set it later, like this:

Macro

Referencing variables: There are two ways to use a variable, by reference and by value. By reference is like saying someones house address. By value is like saying "Blue house, with red door." A byvalue looks like this "${myvariable}" ANYWHERE this apears in your script will get replaced at runtime with whatever value is there. This can sometimes be hard to wrap your mind around. Notice /varset and /declare dont use the ${} syntax. Thats because those are byreference methods. By reference is looking at the location... the house address. It represents a location in memory. Declare creates the location, and /varset puts a value into the address.

To maybe Illustrate this a little better take a look at this.

Macro

New command here.. /varcalc, this is used to not just set a value in a variable, but to do some basical calculation to it. What I'm going to do to try to illustrate what is going on here behind the scense is im going to change the referent access to a memory address, and the value access to the actual value save there.

Macro

I hope that makes a little more sence like that. in the declare your opening memory slot 9AB9 up to hole an integer, and putting a 4 into it. In varcalc you putting 4+1 into that meomry slot. And in /say your saying 5, the value saved in that memory spot. It might be worthwhile for me to say that byreference only works with certain commands. By value works pretty much anywhere. If i put /say myint, you will literally say "myint" on your screen, not some wierd memory address or something.

Conditionals:
Conditionals are pieces of code that only execute if a value is TRUE. This may seem at first a little odd.. what if I want to do something if a value is false... well there is a way around it so just wait. Some information first. TRUE, and anything greater than 0 is TRUE. FALSE,NULL, and 0 are all FALSE. || means OR. && means AND. ! means NOT. So there are all the values you need to know to work with conditionals. TRUE FALSE AND OR NOT. The basic format of an /if statement is "/if ( <condition here> ) <command here>" if you do a single command. Multiple command looks like this"

Macro

Game data:
MQ also makes a large ammount of data available to you at runtime. For instance ${Me} will give you access to your name. ${Me.Attacking} will give a TRUE if you are attacking FALSE if not. Pretty cool eh? Now lets put this together.

Macro

If you are standing this will make you sit. If you are sitting it does nothing. Lets break it down. The ! is a NOT. So now its "NOT${Me.Sitting}" If you are sitting then Me.Sitting returns a true. So now its "NOT TRUE", and no true is "FALSE". and remember the code only gets executed if the condition is TRUE. We got a false so it doesnt make you sit. If your standing the Oposite would happen. You would get a "NOT FALSE" and it would get changed to "TRUE" it would execute and you would sit down.

This only does it one time... i wanna do it constantly so my caster is always sitting. Well we need a loop then. We wil start with the infirnite loop that is usually found in the Sub Main. We will also add some extra stuff to the condition to make sure you don't interupt casting and stuff. I'll also change the /if to the multiline format so you can see it.

Macro

OK! :mainloop is a placeholder, a label, it does nothing =). The /goto we added at the end sends program flow back up to that label. You can name them whatever you want. The /delay 1 i added in there makes it wait a tenth of a second wanna be careful in infinite loops you can spam so much crap out of a loop that the your chat screen will keep spaming text even after you turn the macro off. The loop is easy. The most confusing part is the (!${Me.Sitting}&&!${Me.Casting}&&!${Me.Moving}) so lets break it down to see what is happening. Sitting, Casting, and Moving all return True of False. So I'm just going to take them out of variable form and replace them with words. (!SITTING &&!CASTING&&!MOVING)
&& is AND. (!SITTING AND !CASTING AND !MOVING) and lastly the ! is NOT. IF (NOT SITTING AND NOT CASTING AND NOT MOVING) THEN SIT. I hope that makes sence.

So if you are running it wont make you sit, as soon as you stop moving. Same with casting. as soon as you stop casting you will sit.
_________________
Give me your land!

MQEmulator.net • View topic - Macro basics (2024)
Top Articles
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 6343

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.