- Joined
- Dec 12, 2007
- Messages
- 3,956
- Reaction score
- 49
- Points
- 38
MQ2 is down and though i do plan to make a video for this, I cant at the moment. I figured I would make a quick tutorial here since I see the question asked on a semi regular basis: What do these symbols mean? !, &&, ||.
Those are called operators. Here is the wiki entry:
http://www.macroquest2.com/wiki/index.php/Operators
Operators:
The following three can be used with all variable types:
! mean "not" or "no value"
&& means "and"
|| means "or"
The others are used for integer (number) comparisons.
a==b - does a equal b
a!=b - does a not equal b
a<=b - is a less than or equal to b
a>b - is a greater than b
a>=b - is a greater than or equal to b
Then there are the math specific operators (skipping some):
a+b - add b to a
a-b - subtract b from a
a/b - a divided by b
a*b - a multiplied by b
a\b - whole number of times a is divided by b (useful for money or cost calculations)
a%b - remainder of a\b (useful for money or cost calculations)
You can use 2 methods to do calculations, /varcalc or Math.Calc:
/varcalc a ${a}+1
/varset a ${Math.Calc[${a}+1]}
Both of those examples will add 1 to "a"
Ok, so now how to use those with /if statements.
If statements are a form of flow control (http://www.macroquest2.com/wiki/index.php/Flow_Control) and use the following format:
Use parentheses to wrap ideas together. Everything inside a parentheses will ultimately evaluate as TRUE or FALSE and if TRUE, execute a command(s)
or, if you want to execute more than 1 command:
You can break those up over multiple lines if you want, as long as it is enclosed in { }.
So now you can use variables and operators in conjunction with if statements to check conditions and issue commands. Lets see some basic examples.
Situation: if my HP are less than 50%, and I have more than 10% mana, let's cast my self heal.
code:
Situation: if there are no tanks in group or if I have more than 1 Xtarget, cast AE mez.
code:
Situation: if there are 2 npcs within 10 radius nearby AND there is no healer in group OR I am less than or equal to 10% HP, burn a disc and use ability mend if it is ready:
You can also use ! to mean no value or with strings or bools:
Situation: i want to /echo hi if i have no hitpoints and my name isnt equal to "petesampras".
Strings also have their own built in way of using !, and you can use either method:
But if you use a double negative, then it checks the opposite, so this would check to see if my name really is equal to petesampras due to double negative:
You can also nest parentheses and if statements inside each other.
Situation: if there are more than 3 npcs within 10 radius check to see if a series of discs are ready, and depending on how many npcs there are, use certain discs.
You can bury as many /if statements inside each other as you want. Using the combo of operators and if statements will allow you to set up MQ2melee holyshits and give you a means to control what is happening in a macro.</conditions></conditions></conditions>
Those are called operators. Here is the wiki entry:
http://www.macroquest2.com/wiki/index.php/Operators
Operators:
The following three can be used with all variable types:
! mean "not" or "no value"
&& means "and"
|| means "or"
The others are used for integer (number) comparisons.
a==b - does a equal b
a!=b - does a not equal b
a<=b - is a less than or equal to b
a>b - is a greater than b
a>=b - is a greater than or equal to b
Then there are the math specific operators (skipping some):
a+b - add b to a
a-b - subtract b from a
a/b - a divided by b
a*b - a multiplied by b
a\b - whole number of times a is divided by b (useful for money or cost calculations)
a%b - remainder of a\b (useful for money or cost calculations)
You can use 2 methods to do calculations, /varcalc or Math.Calc:
/varcalc a ${a}+1
/varset a ${Math.Calc[${a}+1]}
Both of those examples will add 1 to "a"
Ok, so now how to use those with /if statements.
If statements are a form of flow control (http://www.macroquest2.com/wiki/index.php/Flow_Control) and use the following format:
Use parentheses to wrap ideas together. Everything inside a parentheses will ultimately evaluate as TRUE or FALSE and if TRUE, execute a command(s)
Code:
/if (conditions<conditions>) /command
Code:
/if (<conditions>conditions) { /command1 /command2 /command1000 }
Code:
/if (<conditions>conditions) {
/command1
/command2
/command1000
}
Situation: if my HP are less than 50%, and I have more than 10% mana, let's cast my self heal.
code:
Code:
/if (${Me.PctHPs}>50 && ${Me.PctMana}>10) /casting "Self Heal" gem1
code:
Code:
/if (!${SpawnCount[group tank]}||${Me.XTarget}>1) /casting "AE Mez" gem2
Code:
/if (${SpawnCount[npc radius 10]}==2 && !${SpawnCount[group priest]}||${Me.PctHPs}<=10 && ${Me.AbilityReady[Mend]}) {
/disc "disc name"
/doability "mend"
}
Situation: i want to /echo hi if i have no hitpoints and my name isnt equal to "petesampras".
Code:
/if (!${Me.PctHPs} && !${Me.Name.Equal[petesampras]}) /echo hi
Code:
${Me.Name.NotEqual[Petesampras]}
Code:
!${Me.Name.NotEqual[PeteSampras]}
Situation: if there are more than 3 npcs within 10 radius check to see if a series of discs are ready, and depending on how many npcs there are, use certain discs.
Code:
/if (${SpawnCount[npc radius 10]}>=3) {
/if (${SpawnCount[npc radius 10]}==3 && ${Me.CombatAbilityReady[Innerflame]}) /disc innerflame
/if (${Me.CombatAbilityReady[Whirlwind]} && (${Me.PctHPs}<50||${SpawnCount[group tank]})) /disc whirlwind
/if (${Me.SpellReady[ae aggro]}) /casting "AE aggro" gem1
}
Last edited: