Macro Guide
To be honest, the official guide to macro doesn’t tell you how to write macros, it only tells you what they are. It took me a really long time to understand macros, hopefully this guide will help you learn macros faster. This guide is only for newbies who don’t know how to write macros, but want to learn.
Some people don’t understand this. So I’m posting in bold. I have written this guide because I want you to understand macros and then write your OWN macros on your OWN without posting here or anywhere else asking for someone to do all the work for you. Atleast try, how do you think I learned?
I assume you already know how to use console commands and understand how they work. If not, before going further read through all console commands and try out ones like a, ai, move, cart get, storage add, talk, deal, take, direction commands, sl, sm, relog, pm and others.
Read the macro manual once so you are familiar with the terminology and stuff, and then read this, keeping both open for cross reference.
Okay, so there are 2 types….
-automacros – these trigger automatically
-macros – these do not trigger automatically but need to be called manually or by an automacro
-automacros – these trigger automatically
-macros – these do not trigger automatically but need to be called manually or by an automacro
Automacros
Automacros are macro which automatically trigger when certain conditions are met, just like how blocks in config.txt trigger depending on the conditions set in them.
The point of automacros is that you use them to check for conditions. When the condition is fulfilled you can either respond to it in the automacro or call a macro to do it. The format for automacros is…
automacro <name> {
condition 1
condition 2
…...
…...
call {
command 1
command 2
…..
…..
}
timeout <n seconds> (if necessary)
}
For example, suppose you’re playing manually but your slave priest is on Kore, and you want it to warn you if its running out of sp, you can use an automacro like this….
automacro sp {
sp < 200
call {
do c sp low
}
timeout 10
}
Taking it line by line,
automacro sp { – you need to put automacro to tell kore that its an automacro. Then you put the name of the macro, in this case its “sp”. Then you need to put an opening bracket “{“ which tells Kore that the automacro’s code begins there.
Sp < 200 – After the “{“, you put the conditions on successive lines. Here there is only one condition and I think its clear that the condition is that sp should be below 200.
call { – The word “call” tells Kore that now you’re going to be putting commands, not conditions. The opening bracket “{“ tells Kore that the commands will start now. These commands are the ones that will get carried out when the conditions are met, here when sp goes below 200.
do c sp low – “Do” tells Kore that this is a commands, some to be done. After “do”, just leave a space and type in the console command you want to execute exactly the way you do in the Kore console.
} – This closing bracket “}” tells Kore that the commands have ended.
timeout 10 – This isn’t a condition or a command, it works the same way it works in normal Kore blocks, so this automacro cannot trigger within 10 seconds of it already having been triggered. I ALWAYS put timeouts, so even if my conditions are faulty, the automacro doesn’t spam and mess up whatever my bot is doing. Otherwise if your automacro is messed up then you could die or something, so its better to put an appropriate timeout.
} – This closing bracker “}” tells Kore that your automacro code has ended.
So basically whenever, the bot’s sp goes below 200, it says in public chat “sp low”. This also has the advantage of making your bot not look like a bot =p.
Here’s another macro which illustrates how you can use macros to handle weird situations which Kore is not equipped to deal with. When fighting against metalings, the often strip you and then your oh-so-smart bot punches! To get around this, put the weapon you use in default auto equip and use this macro.
automacro strip {
status Strip Weapon
call {
do tele
do relog 10
}
timeout 10
}
Taking it line by line….
automacro strip { – Tell Kore this is an automacro, and it’s name is “strip”. The ‘{‘ tells Kore the code of the automacro starts here.
status Strip Weapon – The only condition in this macro. This checks your list of statuses for the status “Strip Weapon”
call { – The word “call” and “{” tells Kore that the commands to be executed start after the ‘{‘
do tele – ‘do’ tells Kore that what comes after is a console command to be carried out. Here the command is “tele” so you teleport away from the Metaling, so that incase you lag or something, you aren’t killed while executing the next instruction which is…..
do relog 10 – Tells Kore to now relog, so that when you login again, your “strip weapon” status will be cleared.
} – ‘}’ Tells Kore the commands have ended.
timeout 10 – Ensures automacro is not spammed, and 10 seconds is enough time to execute the automacro. So after 10 seconds, if for some reason you are still stripped, this automacro will trigger again. However, if you relogin and are stripped within 10 seconds, then macro will not trigger till the 10 seconds are up.
} – ‘}’ tells Kore the macro code has ended.
Summarising, on being stripped, you teleport away from the monster and then relogin, with a timeout of 10 seconds to ensure that the automacro is not spammed. Since the weapon you’re using is filled in in the default weapon option, after relogging Kore will automatically re-equip that weapon.
Lets try a more complicated macro. If you have a priest, you would want it to warp back to its lockmap or the nearest warp-able map near its lockmap. This macro does it. From the savemap, the bot takes the same route to the lockmap. So the first map outside the town, just set it to move to a designated tile, and cast warp on a nearby tile, and then more to the tile. You will need delays to allow the spell to be cast and commands to be completed.
automacro warp {
map gef_fild07
inventory "Blue Gemstone" > 0
call {
do ai manual
pause 1
do move 319 187
do sl 27 316 188
pause 2
do warp 1
pause 1
do move 316 188
do ai on
}
timeout 20
}
Taking it line by line,
automacro warp { - As explained, the automacro’s name is warp, and “{“ indicates that the automacro begins.
map get_fild07 - The first condition, the automacro will only trigger if the map is gef_fild07.
Inventory “Blue Gemstone” > 0 - Second condition, ensures there is atleast one blue gemstone in the inventory so that warp portal can be cast. Obviously you need a getAuto in config.txt for the gemstones.
Call { - Tells Kore, that the commands start here.
do ai manual - Frequently, I use this command in the more complicated and longer macros, so that Kore doesn’t get diverted into doing something else while your macro is running, for example, attacking a monster or gathering up an item.
Pause 1 - Inserts a delay of 1 second before the next command is carried out, VERY IMPORTANT. If you don’t use delays then Kore can and will miss steps in the macro and the result is a mess.
do move 319 187 - The “move” console command is used to move your bot to a set location.
do sl 27 316 188 - The “sl” console command is used to make your priest cast warp portal on a convenient spot near your location, in this case (316,188).
pause 2 - Very Important. A delay of 2 seconds is put, allowing enough time to cast warp portal. If you priest has low dex, this delay should be increased.
Do warp 1 - Console command “warp” is used to select memo location 1.
pause 1 - 1 second delay to allow the portal to form.
do move 316 188 - Move to the portal and Voila! You have been warped to the map.
Do ai on - You set ai to manual at the beginning of this macro, so now you need to turn it on.
} - Closing bracket indication end of commands.
Timeout 20 - Ensures that the bot does not spam the automacro. The timeout should be large enough to allow the completion of the automacro, so that the automacro does not trigger while the macro is executed.
} - Closing bracket indicates end of automacro code.
Note the use of appropriate delays and timeouts in this automacro.
The macro plugin also has many useful built in variables which give you your position for example. Its all listed in the macro manual. I just want to show how to extract your position from these variables.
$.pos gives you your position. Now to get your x and y coordinates the code is,
$px = @arg ("$.pos", 1)
$py = @arg ("$.pos", 2)
If you have a “monster” condition in your automacro, $.lastmonsterpos gives the position of that monster. To extract the x and y coordinates the code is,
$mx = @arg ("$.lastMonsterPos", 1)
$my = @arg ("$.lastMonsterPos", 2)
Run Once
Frequently, the run once condition is used instead of a timeout. It allows the automacro to run only once, so that automacro isn’t spammed. To get the automacro to be run again, a release command needs to be executed. However, sometimes due to a rogue situation the macro can hang and the release macro isn’t executed. This means your automacro is effectively stuck. To get around this I use a timeout instead of using run-once.
Frequently, the run once condition is used instead of a timeout. It allows the automacro to run only once, so that automacro isn’t spammed. To get the automacro to be run again, a release command needs to be executed. However, sometimes due to a rogue situation the macro can hang and the release macro isn’t executed. This means your automacro is effectively stuck. To get around this I use a timeout instead of using run-once.
The normal macros
In the 2 examples above, I’ve done everything using automacros. So you’re probably wondering what the point of macros is, if everything can be done using automacros. Well, not everything can be done using automacros. For example, I don’t think you can use macro variables such as $.pos in an automacro. So, if you get errors like “not an automacro variable” it means that cannot be done in an automacro and has to be done in a macro.
In the 2 examples above, I’ve done everything using automacros. So you’re probably wondering what the point of macros is, if everything can be done using automacros. Well, not everything can be done using automacros. For example, I don’t think you can use macro variables such as $.pos in an automacro. So, if you get errors like “not an automacro variable” it means that cannot be done in an automacro and has to be done in a macro.
Regular Expressions
Sometimes, in a macro you need to compare say the names of characters near you to see if it matches a certain name. This is where regular expressions come in handy. If you’re new to macros, you can read this later as it can be a bit complicated, the more advanced regexps can look hellish =P Visit http://www.regular-expressions.info/quickstart.htmlwhere its explained fairly well. I’m just going to put down some basics here.
Sometimes, in a macro you need to compare say the names of characters near you to see if it matches a certain name. This is where regular expressions come in handy. If you’re new to macros, you can read this later as it can be a bit complicated, the more advanced regexps can look hellish =P Visit http://www.regular-expressions.info/quickstart.htmlwhere its explained fairly well. I’m just going to put down some basics here.
$.lastpubMsg = /(A|a)uto (S|s)torage/
Here $.lastpubMsg is your macro variable holding the last public chat message. A regular expression can just be plain text so it could have been /auto storage/ or /auto/ and Kore would have checked if the public chat contained “auto storage” or “auto”.
However here we have used the “|” symbol which means “or”. Notice ‘A’ and ‘a’ are contained in brackets with a ‘|’ between them. It means both ‘auto’ and ‘Auto’ are checked for. Similarly both ‘storage’ and ‘storage’ are checked for. Now suppose you want to check for repetition, say ‘aauto storage’ also, then you can use /(a+|A+)uto (S|s)torage/. Notice I’ve used a ‘+’. This tells Kore that the character it is directly after, here ‘a’ or ‘A’, should be present one or more times. So even if someone says “aaaaaaaaaauto storage’ it will be valid. Other checks like the ‘+’ are
* Match 0 or more times eg. /(a*|A*)uto Storage/ so “ato storage” will also work
+ Match 1 or more times eg. as above
? Match 1 or 0 times eg /(a?|A?)uto Storage/ so “ato storage” and “auto storage” work but “aaaauto storage” won’t
* Match 0 or more times eg. /(a*|A*)uto Storage/ so “ato storage” will also work
+ Match 1 or more times eg. as above
? Match 1 or 0 times eg /(a?|A?)uto Storage/ so “ato storage” and “auto storage” work but “aaaauto storage” won’t
So if you want to check for “Kobold” just do /Kobold/ and if “Kobold” is anywhere in the string, it will be valid. For Kobold-1 and Kobold-2 only it will be /Kobold-(1|2)/.
Regexps can also come in handy when you’re using the “console /<regexp>/” condition in automacros, if you need to check for a variety of trigger texts.
These is just the basics, I recommend referring to link provided above if you need to make a more complicated regexp.
How to write a macro
Now that you have some idea of what a macro is, try writing one….
-Figure out under exactly what conditions you want your automacro to trigger
-Logically think out the steps your bot needs to perform in the automacro. Go step by step over this carefully.
-Ensure you have inserted appropriate pauses between the steps.
-Ensure you have a timeout or a run-once in your macro to prevent spamming of it.
-Now put the code in macros.txt and start the bot or reload macros.txt. If all is fine you won’t get any error messages. But if there is a problem in the syntax, say you missed out a “}”, then you will get an error message and the macro won’t work. Figure out what the error is, correct it, and reload macros.txt again to check if you corrected it properly or not.
Now that you have some idea of what a macro is, try writing one….
-Figure out under exactly what conditions you want your automacro to trigger
-Logically think out the steps your bot needs to perform in the automacro. Go step by step over this carefully.
-Ensure you have inserted appropriate pauses between the steps.
-Ensure you have a timeout or a run-once in your macro to prevent spamming of it.
-Now put the code in macros.txt and start the bot or reload macros.txt. If all is fine you won’t get any error messages. But if there is a problem in the syntax, say you missed out a “}”, then you will get an error message and the macro won’t work. Figure out what the error is, correct it, and reload macros.txt again to check if you corrected it properly or not.