eventMacro: Difference between revisions
No edit summary |
No edit summary |
||
Line 188: | Line 188: | ||
|aling=center| eventMacros.txt | |aling=center| eventMacros.txt | ||
|align=center| file containing the macros and automacros | |align=center| file containing the macros and automacros | ||
|- | |||
|align=center| eventMacro_CheckOnAI | |||
|align=center| combination of 'auto', 'manual' and 'off' | |||
|aling=center| auto | |||
|align=center| In which AI states automacros will be checked | |||
|} | |} | ||
Line 1,051: | Line 1,056: | ||
[eventmacro log] \$i = 8 | [eventmacro log] \$i = 8 | ||
[eventmacro log] \$i = 9 | [eventmacro log] \$i = 9 | ||
== Automacros == | |||
At this point, you can define macros and call them, typing 'eventMacro <macro name>' in OpenKore's console input. | |||
Automacro is an automatic trigger for calling your macros, just like blocks in config.txt are automatic triggers for certain AI actions. | |||
Automacro block consists of: | |||
* One or more '''Parameters''' ('''call''' being the only required one). | |||
* One or more '''Conditions'''. | |||
Automacro does not trigger if there is currently running macro in exclusive mode. Otherwise, automacro clears macro queue (which means that all currently running macros are stopped) before call. | |||
The point of automacro is that you use them to check for certain conditions and call your macro when all conditions are fulfilled. | |||
=== Parameters === | |||
:* Each parameter can only be used once. | |||
:* Parameters define the way the automacro or the called macro will work. | |||
:* Most parameters have a default value that will be used when it is not defined. | |||
; call | |||
:* '''call''' is the only required parameter in every automacro. | |||
:* '''call''' defines which macro the automacro will execute. | |||
:* '''call''' can be a macro name or a macro block. | |||
Example when using a macro name: | |||
automacro <automacro name> { | |||
<automacro conditions and parameters (and only them)> | |||
call myMacro | |||
} | |||
macro myMacro { | |||
<macro instructions (and only them, as this is regular macro)> | |||
# for example: | |||
do move prontera | |||
do move payon | |||
} | |||
Example when using a macro block: | |||
automacro <automacro name> { | |||
<automacro conditions and parameters (and only them)> | |||
call { | |||
<macro instructions (and only them, as this is regular macro)> | |||
# for example: | |||
do move prontera | |||
do move payon | |||
} | |||
} | |||
:* Two examples above do the same thing. | |||
:* Note that the macro block used in the call parameter has the same rules as a normal macro block. | |||
The first syntax is useful if you want more than one automacro to call one simple macro: | |||
automacro First { | |||
<conditions> | |||
call print | |||
} | |||
automacro Second { | |||
<conditions> | |||
call print | |||
} | |||
macro print { | |||
log $.caller triggered | |||
} | |||
; delay | |||
:* '''delay''' is an optional parameter. | |||
:* '''delay''' defines the time in seconds to wait before executing the macro in call parameter. | |||
:* If not used in the automacro the default value will be used, which is: 0. | |||
:* Must have a numeric value. | |||
automacro <automacro name> { | |||
<automacro conditions and parameters (and only them)> | |||
delay 5 | |||
call myMacro | |||
} | |||
macro myMacro { | |||
<macro instructions (and only them, as this is regular macro)> | |||
log This is being logged 5 seconds after the automacro activated | |||
} | |||
; run-once | |||
:* '''run-once''' is an optional parameter. | |||
:* '''run-once''' defines if the automacro can activate only once, or multiple times. | |||
:* If not used in the automacro the default value will be used, which is: 0. | |||
:* When it's value is 1 the automacro will only activate once, when it's 0 it can activate multiple times. | |||
:* To make an automacro with run-once value of 1 which already was already activated be able to run again you can use the command 'release' [[eventMacro#Macro Syntax|Macro Syntax]]. | |||
automacro myautomacro { | |||
<automacro conditions and parameters (and only them)> | |||
run-once 1 | |||
call myMacro | |||
} | |||
automacro myaotherauto { | |||
<automacro conditions and parameters (and only them)> | |||
run-once 0 | |||
call myMacro | |||
} | |||
macro myMacro { | |||
<macro instructions (and only them, as this is regular macro)> | |||
log This macro will be called by myautomacro only once | |||
log but this macro can be called by myaotherauto many times | |||
} | |||
; CheckOnAI | |||
:* '''CheckOnAI''' is an optional parameter. | |||
:* '''CheckOnAI''' defines in which AI states the automacro can activate. | |||
:* The default value for this parameter can be set in the config key eventMacro_CheckOnAI [[eventMacro#Configuration files|Configuration files]]. | |||
:* If not used in the automacro the default value will be used, which is the config key eventMacro_CheckOnAI. | |||
:* If eventMacro_CheckOnAI is not set in the config the default value will be used, which is: auto | |||
:* It's values can be a combination of auto, manual and off, separated by comma. | |||
automacro MyAuto { | |||
<automacro conditions and parameters (and only them)> | |||
CheckOnAI manual | |||
call myMacro | |||
} | |||
macro myMacro { | |||
<macro instructions (and only them, as this is regular macro)> | |||
log This macro will only be called by MyAuto when AI is manual | |||
} | |||
automacro MyAuto2 { | |||
<automacro conditions and parameters (and only them)> | |||
CheckOnAI manual, off | |||
call myMacro | |||
} | |||
macro myMacro2 { | |||
<macro instructions (and only them, as this is regular macro)> | |||
log This macro will only be called by MyAuto2 when AI is manual or off | |||
} | |||
; disabled | |||
:* '''disabled''' is an optional parameter. | |||
:* '''disabled''' defines if the automacro is active of not. | |||
:* If not used in the automacro the default value will be used, which is: 0. | |||
:* When it's value is 1 the automacro won't activate ever, when it's 0 it can activate normally. | |||
automacro MyAuto { | |||
<automacro conditions and parameters (and only them)> | |||
disabled 1 | |||
call myMacro | |||
} | |||
macro myMacro { | |||
<macro instructions (and only them, as this is regular macro)> | |||
log This macro will never be called by MyAuto | |||
} | |||
automacro MyAuto2 { | |||
<automacro conditions and parameters (and only them)> | |||
disabled 0 | |||
call myMacro | |||
} | |||
macro myMacro2 { | |||
<macro instructions (and only them, as this is regular macro)> | |||
log This macro will be called by MyAuto2 normally | |||
} |
Revision as of 21:39, 1 March 2017
Description
- With this plugin you can create complex blocks of conditions called automacros and blocks of consecutive actions called macros.
- Macros can be called by one or more automacros when their conditions become true or be called by hand using a console command.
- Automacros have simple to use conditions like base level, zeny, job class and many others.
- Macros can be as simple as 'say something in chat' or 'save in kafra' and as complex as 'do a complete quest'.
Installation
- Download the eventMacro plugin. You can download it from the following link:
- Go to your OpenKore main folder (the folder which contains the file openkore.pl) and create a subfolder called plugins, if there isn't already one. Create a subfolder eventMacro in it.
- Inside the eventMacro plugin's zipfile (normally eventMacro-master.zip), you will find the file eventMacro.pl, the folder eventMacro and other files and folders. Extract them to your plugins/eventMacro folder, so eventMacro.pl ends up in plugins/eventMacro/eventMacro.pl.
- In your OpenKore control folder, create a blank file named eventMacros.txt. In this file you will put your macros/automacros.
After installation, your OpenKore file tree should look like this (ignoring OpenKore's own files):
openkore |-- openkore.pl |-- control | |-- eventMacros.txt |-- fields |-- logs |-- plugins | |-- eventMacro | | |-- eventMacro | | | |-- Automacro.pm | | | |-- Condition.pm | | | |-- Core.pm | | | |-- Data.pm | | | |-- FileParser.pm | | | |-- Lists.pm | | | |-- Macro.pm | | | |-- Runner.pm | | | |-- Utilities.pm | | | |-- Validator.pm | | | |-- Validator | | | | |-- ListMemberCheck.pm | | | | |-- NumericComparison.pm | | | | |-- RegexCheck.pm | | | |-- Conditiontypes | | | | |-- ListConditionEvent.pm | | | | |-- ListConditionState.pm | | | | |-- MultipleValidatorEvent.pm | | | | |-- MultipleValidatorState.pm | | | | |-- NumericConditionEvent.pm | | | | |-- RegexConditionEvent.pm | | | | |-- RegexConditionState.pm | | | | |-- SimpleEvent.pm | | | |-- Condition | | | | |-- AttackEnd.pm | | | | |-- AttackStart.pm | | | | |-- AttackStartRegex.pm | | | | |-- BaseLevel.pm | | | | |-- CartCurrentSize.pm | | | | |-- CartCurrentWeight.pm | | | | |-- CartMaxSize.pm | | | | |-- More conditions... | | |-- test | | | |-- unit_tests.pl | | | |-- RunnerStatementTest.pm | | | |-- RunnerParseCommandTest.pm | | | |-- LoadConditionsTest.pm | | | |-- GlobalVarRegexTest.pm | | | |-- FindVarTest.pm | | | |-- DynamicAutoVarsTest.pm | | | |-- CoreVarFunctionsTest.pm | | | |-- Validator | | | | |-- ListMemberCheckTest.pm | | | | |-- NumericComparisonTest.pm | | | | |-- RegexCheckTest.pm | | | |-- textfiles | | | | |-- DynamicAutoVarsTest.txt | | | | |-- DynamicAutoVarsTest2.txt | | | | |-- DynamicAutoVarsTest3.txt | | | | |-- empty.txt | | | | |-- LoadConditionsTest.txt | | |-- eventMacro.pl |-- src |-- tables
Console Commands
Syntax
eventMacro [MACRO|auto|list|status|check|stop|pause|unpause|var_get|var_set|enable|disable] [extra]
- eventMacro MACRO
- Run macro MACRO
Runs macro <macroname>.
Option | Value | Description |
---|---|---|
-repeat | n | repeat the macro n times |
-overrideAI | none | override openkore's AI |
-macro_delay | delay | override global macro_delay for this macro |
-exclusive | none | do not allow automacros to cancel this macro |
-orphan | method | use method for handling orphaned macros |
Parameters for the macro can be specified after a double dash (--). These parameters are saved to the variables $.param1 to $.paramN. Example:
macro foo { log Parameter 1 is $.param1 log Parameter 2 is $.param2 }
When called as eventMacro foo -- foo bar it would print out
[eventmacro log] Parameter 1 is foo [eventmacro log] Parameter 2 is bar
- eventMacro auto AUTOMACRO
- Get info on an automacro and it's conditions
- eventMacro list
- Lists available macros and automacros
- eventMacro status [macro|automacro]
- Shows current status of automacro, macro or both
- eventMacro check [force_stop|force_start|resume]
- Sets the state of automacros checking
- eventMacro stop
- Stops current running macro
- eventMacro pause
- Pauses current running macro
- eventMacro unpause
- Unpauses current running macro
- eventMacro var_get
- Shows the value of one or all variables
- eventMacro var_set
- Set the value of a variable
- eventMacro enable [automacro]
- Enable one or all automacros
- eventMacro disable [automacro]
- Disable one or all automacros
Configuration files
- control/eventMacros.txt
- Put your macros and automacros in here. You can change the file's name depending on what you configured on config eventMacro_file.
- control/timeouts.txt
- Add eventMacro_delay and set it to the number of seconds you want the plugin to pause between commands.
- control/config.txt
Option | Value | Default | Description |
---|---|---|---|
eventMacro_orphans | terminate reregister reregister_safe terminate_last_call |
terminate | How will openkore deal with macros that got cleanead out of AI queue |
eventMacro_file | file name | eventMacros.txt | file containing the macros and automacros |
eventMacro_CheckOnAI | combination of 'auto', 'manual' and 'off' | auto | In which AI states automacros will be checked |
Macro Syntax
macro MacroName { do this.. and that.. yattayatta.. }
- You can use any name you want for your macro. Be careful not to make two macros with the same name.
- Macros is executed from top to bottom.
- Only macro instructions can be used in macros. If you need to use console command, use do.
Macro Instructions
- do <command>
- Run <command>, as if it was entered in OpenKore terminal. Commands are from Console Commands.
macro foo { do move 123 234 prontera do sit do c hello world }
The command ai clear is disabled by default in the plugin.
If has a macro the command do ai manual or do ai off , the macro will stop its execution.
- log <text>
- Prints a text in the console. Can contain macro $variables and @stuff.
macro foo { log This line logs a text to console. log All your base are belong to us! }
- pause [<n>]
- Pauses the macro for n seconds.
macro foo { log It's 10:00:00 pause 10 log Now it's 10:00:10 log 10 seconds have passed after the first print. }
pause not only pauses the macro running, pauses all our character's actions.
- call <macroname> [<n>]
- Calls macro <macroname> [<n> times]. When <macroname> is finished the current macro continues.
- release (<name> | all)
- Reenables a locked automacro ("run-once" keyword or locked by "lock") or reenables all automacros when using release all.
- lock (<name> | all)
- Locks an automacro and disables it's checks. To lock all automacros, use lock all.
- stop
- Immediately terminates the running macro.
- set <option> <value>
- Sets macro features:
- orphan method
- macro_delay timeout
- overrideAI [0|1]
- repeat times
- exclusive [0|1]
Variables
- You can work with variables. Variable declaration is not needed. All macro variables are global.
- EventMacro variable system is based in perl and has support for scalars, arrays and hashes.
- Variable names may only contain letters and numbers.
- If you want to use any variable without replacing it for it's value you should escape it with \.
Types of variables and their definitions
- Scalar
- Scalar variables can hold a single piece of information, like a number or a string of characters.
- Scalars start with the symbol $.
- Array
- Array variables hold a list of things.
- Each member inside the array list has a index, which is it's position inside the list.
- The first index of an array is always 0, and the last is always the size of the array minus 1.
- Arrays start with the symbol @.
- Hash
- Hash variables hold many pairs of things.
- Each hash pair in consisted of a key and a value.
- Each key has only one value, but many keys can have the same value.
- Hashes start with the symbol %.
Declaration and usage
Scalars
Set value of scalar variable:
$variable = value
Get a value of variable (note that this is "Macro Syntax" section, so it doesn't apply to automacro conditions, config options etc):
$variable
macro Hello { $var = Hello $var1 = World! log $var $var1 }
This would print in the console:
[eventmacro log] Hello World!
It is possible to increment and to decrement a variable using $variable++ or $variable--.
macro Counter { $counter = 0 log Counter is at $counter $counter++ log Now it's $counter $counter-- log It's back to $counter }
The result is:
[eventmacro log] Counter is at 0 [eventmacro log] Now it's 1 [eventmacro log] It's back to 0
You can also unset/vanish the existing variable using 'undef' or 'unset':
$x = 1 log \$x is $x $x = undef # or you can use 'unset' log \$x now vanished: $x
Variable assignment doesn't evaluate, it only does macro substitutions, so use @eval for calculations.
macro math { $num = 2 $num2 = 3 $result = @eval($num+$num2) log sum of $num and $num2 is $result }
The result is:
[eventmacro log] sum of 2 and 3 is 5.
Arrays
Set value of array variable, it must be declared with it's members inside parentheses, separated by comma:
@variable = (member0, member1, member2)
Get a value of a certain index, use $ at the start instead of @, and put the index after the variable name, encapsulated by [ and ]:
$variable[index]
Get a size of the variable:
@variable
macro Hello { @var = (drops, poring) log The size of \@var is @var, the first member is $var[0] and the second is $var[1] }
This would print in the console:
[eventmacro log] The size of @var is 2, the first member is drops and the second is poring
- The definition of separate array members is the same as normal scalar.
They can be set:
$myarray[0] = harry $myarray[1] = potter
They can be incremented and decremented:
macro Counter { $counterArray[1] = 0 log \$counterArray[1] is at $counterArray[1] $counterArray[1]++ log Now it's $counterArray[1] $counterArray[1]-- log It's back to $counterArray[1] }
And they can be unset:
$var[5] = 1 log \$var[5] is $var[5] $var[5] = undef # or you can use 'unset' log \$var[5] now vanished: $var[5]
- Array Keywords
- There are 4 keywords which can be used on arrays:
- push: Adds a new element to the end fo the array, increasing it's size by 1.
- pop: Removes the last element from the end of the array, decreasing it's size by 1.
- shift: Removes the first element of the array and moves the whole array 1 index to the left, decreasing it's size by 1.
- unshift: Adds a new element to the start of the array and moves the whole array 1 index to the right, increasing it's size by 1.
- push
push syntax is as follows:
&push(@array, newmember)
push must have 2 parameters: the array you want to push, and the new member to be pushed.
Here's an example of an array started from scratch using push:
&push(@names, john) &push(@names, mary) &push(@names, juan)
This is the array afterwars:
(john, mary, juan)
And this macro:
macro print_names { &push(@monsters, poring) &push(@monsters, wolf) &push(@monsters, maya) log The array \@monsters has size @monsters and it's members are $monsters[0], $monsters[1] and $monsters[2] }
Prints this:
[eventmacro log] The array @monsters has size 3 and it's members are poring, wolf and maya
- pop
pop syntax is as follows:
&pop(@array)
pop must have 1 parameter: the array you want to pop.
Here's an example of an array, and it after a pop:
@jobs = (teacher, doctor, seller) log The array \@jobs has size @jobs and it's members are $jobs[0], $jobs[1] and $jobs[2] &pop(@jobs) log The array \@jobs has size @jobs and it's members are $jobs[0], $jobs[1] &pop(@jobs) log The array \@jobs has size @jobs and it's members are $jobs[0]
This prints this:
[eventmacro log] The array @jobs has size 3 and it's members are teacher, doctor and seller [eventmacro log] The array @jobs has size 2 and it's members are teacher, doctor [eventmacro log] The array @jobs has size 1 and it's members are teacher
- shift
shift syntax is as follows:
&shift(@array)
shift must have 1 parameter: the array you want to shift. Here's an example of an array, and it after a shift:
@jobs = (teacher, doctor, seller) log The array \@jobs has size @jobs and it's members are $jobs[0], $jobs[1] and $jobs[2] &shift(@jobs) log The array \@jobs has size @jobs and it's members are $jobs[0], $jobs[1] &shift(@jobs) log The array \@jobs has size @jobs and it's members are $jobs[0]
This prints this:
[eventmacro log] The array @jobs has size 3 and it's members are teacher, doctor and seller [eventmacro log] The array @jobs has size 2 and it's members are doctor, seller [eventmacro log] The array @jobs has size 1 and it's members are seller
After a shift the whole array is moved to the left, so after the first shift the member 'seller' which was in index 2 moved to index 1,
and after the second shift it moved to index 0.
- unshift
unshift syntax is as follows:
&unshift(@array, newmember)
push must have 2 parameters: the array you want to push, and the new member to be pushed.
Here's an example of an array started from scratch using push:
&unshift(@foods, bread) &unshift(@foods, carrot) &unshift(@foods, apple)
This is the array afterwars:
(apple, carrot, bread)
Note that since unshift puts the new member in the start of the array the first member is now 'apple' which was added last.
And this macro:
macro print_names { @array = (apple, banana) log The array \@array has size @array and it's first member is $array[0], and the second is $array[1] &unshift(@array, pineapple) log The array \@array has size @array and it's first member is $array[0], and the second is $array[1] &unshift(@array, melon) log The array \@array has size @array and it's first member is $array[0], and the second is $array[1] }
Prints this:
[eventmacro log] The array @array has size 2 and it's first member is apple, and the second is banana [eventmacro log] The array @array has size 3 and it's first member is pineapple, and the second is apple [eventmacro log] The array @array has size 4 and it's first member is melon, and the second is pineapple
Hashes
Set value of hash variable, it must be declared with it's pairs inside parentheses, separated by comma, the key and the value must be separated by =>:
%variable = (key1 => value1, key2 => value2, key3 => value3)
Get a value of a certain key, use $ at the start instead of %, and put the key after the variable name, encapsulated by { and }:
$variable{key1}
- Keys can contain letters and numbers.
Get a size of the variable:
%variable
macro Hello { %ages = (john => 25, george => 32) log John is $ages{john} years old, and George is $ages{george} years old }
This would print in the console:
[eventmacro log] log John is 25 years old, and George is 32 years old
- The definition of separate hash members is the same as normal scalar.
They can be set:
$name{first} = harry $name{last} = potter
They can be incremented and decremented:
macro Counter { $hash{monterskilled} = 0 log \$hash{monterskilled} is at $hash{monterskilled} $hash{monterskilled}++ log Now it's $hash{monterskilled} $hash{monterskilled}-- log It's back to $hash{monterskilled} }
And they can be unset:
$myhash{value} = 1 log \$myhash{value} is $myhash{value} $myhash{value} = undef # or you can use 'unset' log \$myhash{value} now vanished: $myhash{value}
There's one hash keyword, delete, it completely delete a key from a hash, as if it had never existed.
delete usage:
&delete($names{john})
example:
macro print_names { %fruitsprice = (apple => 1000, banana => 700) log The hash \%fruitsprice has size %fruitsprice. log The apple price is $fruitsprice{apple} and the banana price is $fruitsprice{banana} &delete($fruitsprice{apple}) log The hash \%fruitsprice has size %fruitsprice. log The price of banana is: $fruitsprice{banana} log The price of apple has vanished: $fruitsprice{apple} }
Prints this:
[eventmacro log] The hash \%fruitsprice has size 2. [eventmacro log] The apple price is 1000 and the banana price is 700 [eventmacro log] The hash \%fruitsprice has size 1. [eventmacro log] The price of banana is 700 [eventmacro log] The price of apple has vanished:
Special Variables
There are special read-only variables which begin with a dot. They are pre-defined with the eventMacro plugin.
Variable | Definition | Example |
---|---|---|
$.map | The map you're on | prontera |
$.pos | Your current position | 123 234 |
$.time | Current time as unix timestamp | 1482275422 |
$.datetime | Current date and time | Tue Dec 20 21:22:34 2016 |
$.hour | Current hour time in 24h format | 14 |
$.minute | Current minute time (0 - 59) | 34 |
$.second | Current second time (0 - 59) | 53 |
$.hp | Current HP | 2304 |
$.sp | Current SP | 345 |
$.lvl | Current base level | 175 |
$.joblvl | Current job level | 60 |
$.spirits | Number of current spirit spheres or coin flip's coins | 3 |
$.zeny | Current zeny | 8478341 |
$.status | Current statuses in a comma-separated list | Attention Concentrate,Endure,Two-Hand Quicken |
$.paramN | Command line parameters (see Syntax) | N/A |
$.caller | Nome da última automacro ativada | N/A |
$.weight | Current weight of the character | 1948 |
$.maxweight | Current maximum weight of the character | 2400 |
Special Keywords
These keywords (having common form of &<keyword>(<arguments>) each) interpolated to corresponding values just about anywhere inside macro blocks (except goto, end, label definitions, macro name in call, set). Macro variables can be used in arguments, with the exception for &nick()
.
- &npc (<x> <y> | /regexp/i | "<name>")
- Return NPC's index which location is <x> <y> or NPC's name match regexp or NPC's name is equal to <name> . Returns -1 if no NPC was found.
- &inventory (<item>)
- Returns inventory item index of <item>. If <item> doesn't exist, it returns -1.
- &Inventory (<item>)
- Same as &inventory but returns all matching indexes as a comma-separated list or -1 if the item was not found.
- &invamount (<item>)
- Returns the amount of the given <item> in inventory.
- &cart (<item>)
- Returns cart item index of <item>. If <item> doesn't exist, it returns -1.
- &Cart (<item>)
- Same as &cart but returns all matching indexes as a comma-separated list or -1 if the item was not found.
- &cartamount (<item>)
- Returns the amount of the given <item> in cart.
- &storage (<item>)
- Returns storage item index of <item>. If <item> doesn't exist, it returns -1.
- &Storage (<item>)
- Same as &storage but returns all matching indexes as a comma-separated list or -1 if the item was not found.
- &storamount (<item>)
- Returns the amount of the given <item> in storage.
- &player (<name>)
- Returns player index of player <name>. If player <name> is not found, it returns -1.
- &monster (<name|ID>)
- Returns monster index of monster <name|ID>. If monster <name|ID> is not found, it returns -1.
- &vender (<name>)
- Returns vender index of vender <name>. If vender <name> is not found, it returns -1.
- &store (<name>)
- Looks for an item in a store and returns index or -1 if the item was not found.
- &shopamount (<item>)
- Returns the amount of the given <item> in shop.
- &random ("<argument1>", "<argument2>", ...)
- Returns randomly one of the given arguments .
- &rand (<n>, <m>)
- Returns a random number between (and including) <n> and <m>.
- &eval (<argument>)
- Evaluates the given <argument>. Contents of &eval is Perl and does NOT have eventMacro plugin syntax, except for variables and @() substitution.
- &arg ("<argument>", <n>)
- Returns the <n>th word of <argument> or an empty string if the word index is out of range.
- &config (<variable>)
- Returns the value of <variable> specified in config.txt.
- &venderitem (<name>)
- Looks for an item in a player's shop and returns index or -1 if the item was not found.
- &venderprice (<indexID>)
- Looks for an item in a player's shop and returns its price.
- &nick (<word>)
- Escapes all the regexp metacharacters and some of the perl special characters with \ (a backslash). Especially for player's name.
Chaining commands
You can run multiple commands one after another without having to wait for openkore's AI or macro_delay or whatever. Just enclose these commands with [ and ].
0 macro foo { 1 do whatever 2 log yet another line 3 [ 4 do something 5 do something else 6 log foo 7 ] 8 log done 9 }
Line 3 starts the chaining mode. This line has no delay. Lines 4, 5 and 6 are run as soon as the previous command has finished with no delay and they cannot be interrupted. Line 7 stops the chaining mode and line 8 will be run $macro_delay seconds after that.
Sub-lines
Instead of using one command/var assignments per line, you can separate them using a semi-colon ";".
macro foo { $i = 1; pause 5; log \$i = $i; $ii = 2; $iii = 3; $i++; $ii--; lock automacroName; release automacroName; set overrideAI 1 }
Commands separated by a semi-colon ";" the normal macro_delay between them.
Operators
Supported operators in eventMacro plugin are:
Operator | Description |
---|---|
< | less than |
<= | less or equal to |
== or = | equal to |
> | greater than |
>= | greater or equal to |
!= | not equal to |
~ | <left part> is element of <right part (comma-separated list)> |
=~ | <left part> matches regular expression <right part>
|
arg .. arg2 | Between arg and arg2. Where arg can be a number, a % or a variable. |
Flow control and labels
- Just as prevalent in high-level languages constructs like "if .. else", "while", "foreach", "for .. next", "do .. while" and other commands.
- eventMacro plugin also has the operations "if", "else", "elsif", "switch", "case", "goto" and "while". There's also label declaration.
Syntax of command conditions
If
Right now, macro if conditions are very close to the perl if statements. It accepts unlimited number of statements in just one if condition line, regexp matching is allowed (unfortunately, no backreference using parenthesis) and the use of && for and meaning and || for or meaning.
You can use a simple statement;
if (arg1 <Operators> arg2) (goto <label> | call <macro> [<n>] | stop | { )
A simple statement with OR condition;
if (arg1 <Operators> arg2 || arg3 <Operators> arg4) (goto <label> | call <macro> <n> | stop | { )
A simple statement with AND condition;
if (arg1 <Operators> arg2 && arg3 <Operators> arg4) (goto <label> | call <macro> <n> | stop | { )
Or with both;
if ((arg1 <Operators> arg2 || arg3 <Operators> arg4) && arg5 <Operators> arg6) (goto <label> | call <macro> <n> | stop | { ) if ((arg1 <Operators> arg2 && arg3 <Operators> arg4) || arg5 <Operators> arg6) (goto <label> | call <macro> <n> | stop | { ) if ((arg1 <Operators> arg2 && arg3 <Operators> arg4) || (arg5 <Operators> arg6 && arg7 <Operators> arg8)) (goto <label> | call <macro> <n> | stop | { ) if ((arg1 <Operators> arg2 || arg3 <Operators> arg4) && (arg5 <condition> arg6 || arg7 <condition> arg8)) (goto <label> | call <macro> <n> | stop | { )
- Notice inside of each brackets containing the AND and OR symbols.
Where;
- arg can be a variable, a nested variable, a special keyword, &eval, letters and numbers or even a Perl Subroutines function.
- <label>, the name of an existing label, can only contain letters and numbers
- <macro>, the name of a existing macro, and
- <n>, the number of times it will call the macro.
- < { >, the beginning of a block of commands that will be executed if the condition is true, to finish it, use }.
Note:
- If <n> is defined as 0 or even if it is undefined, the called macro name will run at once and then stop, not continuing the previous macro caller at a run time.
- If <n> is greater than 0, the called macro name will run at n time/s and then continuing the previous macro caller line at a run time.
Note²: If statements are unlimited, you can use as many statements as you want.
if (arg1 <Operators> arg2 || arg3 <Operators> arg4 || ... || argN <Operators> argN+1) (goto <label> | call <macro> <n> | stop)
Where;
- arg can be a variable, a nested variable, a special keyword, &eval or letters and numbers.
- All the conditions is up to the Nth argument <Operators> N+1th argument.
- While N is an integer number/s which is greater than zero.
Postfix control
Another way to use the if is to put it at the end of the command.
<command> if (arg1 <Operators> arg2)
The command before the if statement will only be executed if the condition is true. The way to create the condition is the same as previously explained.
In this example below, the two commands are equivalent:
call buy if ($.zeny > 1000) if ($.zeny > 1000) call buy
Else
In case if is used with open braces ( { ), it's possible to use the command else along closed braces ( } ) in the end of the command block if, to start a new command block that will be executed if if is false.
if (arg1 <Operators> arg2) { command1 command2 ... commandN } else { command1 command2 ... commandN }
In this case, the first command block will be executed if the condition turns out being true. If it's false, the second command block (preceding by else) will be executed.
Note: Inside braces you're allowed to use tons of commands.
Note: It is not compulsory to wear else.
Elsif
It is like the else + if. The elsif is in the same place else with the difference being added conditions to its command block is executed if its conditions are true.
if (arg1 <Operators> arg2) { command1 command2 ... comandoN } elsif (arg1 <Operators> arg2) { command1 command2 ... commandN } else { command1 command2 ... commandN }
In this case, the first block of commands will be executed if the condition is true. If it is false, the second block of commands (preceded by the elsif) will be executed if its condition is true. Should also be false, the command blocks else to be executed.
Note: As in the else, inside braces of elsif you're allowed to use tons of commands.
Note: It is not compulsory to wear the else or elsif.
Switch/case
It's similar to if followed by enumerous elsif. It's useful to leave the code cleaner when the paramater being analyzed is the same, this way you don't need to repeat it.
switch (arg1) { case (<Operators> arg2) (goto <label> | call <macro> <n> | stop | {) (If you use "{", the commands should be used here and in a separated line that should be closed with the block "}") case (<Operators> arg2) (goto <label> | call <macro> <n> | stop | {) (If you use "{", the commands should be used here and in a separated line that should be closed with the block "}") ... else (goto <label> | call <macro> <n> | stop | {) (If you use "{", the commands should be used here and in a separated line that should be closed with the block "}") }
Note: The use of else is optional. Note: In case that no case ends being true, else will be activate if it exists.
Examples
This macro will go a random walk
macro walk { $num = &rand(1, 4) if ($num == 1) { do c I will follow the path 1 do north } if ($num == 2) { do c I will follow the path 2 do south } if ($num == 3) { do c I will follow the path 3 do east } if ($num == 4) { do c I will follow the path 4 do west } }
Simplified version of the above macro, using postfix control.
macro walk { $num = &rand(1, 4) do c I will follow the path $num do north if ($num == 1) do south if ($num == 2) do east if ($num == 3) do west if ($num == 4) }
The following macro will tell if you've over 1.000z or 1.000z or less.
macro checkZeny { if ($.zeny > 1000) { do c I've over 1.000z! } else { do c I've 1.000z or less... } }
A little more complete than the above macro. Informa has more than 1.000z, has exactly 1.000z or has less than 1.000z with emoticons
macro checkZeny { if ($.zeny > 1000) { do c I've over 1.000z! do e money } elsif ($.zeny == 1000) { do c I have exactly 1.000z. do e ! } else { do c I've 1.000z or less... do e panic } }
Similar to the above but with a different syntax
macro checkZeny { switch ($.zeny) { case (> 1000) { do c I've over 1.000z! do e money } case (== 1000) { do c I have exactly 1.000z. do e ! } else { do c I've 1.000z or less... do e panic } } }
The below macro will print \$num is 1 if $num == 1, \$num is 2 if $num == 2, \$num is 3 if $num == 3.
macro checknum { $num = &rand(1, 3) if ($num == 1) goto one if ($num == 2) goto two if ($num == 3) goto three :one log \$num is 1 stop :two log \$num is 2 stop :three log \$num is 3 stop }
The above macro can be written using call instead of goto.
macro checknum { $num = &rand(1, 3) if ($num == 1) call one if ($num == 2) call two if ($num == 3) call three } macro one { log $num is 1 } macro two { log $num is 2 } macro three { log $num is 3 }
A more complicated macro
macro if { $i = 1 log \$i = $i if (((($i = 1 || $i < 5 || $i ~ 0 .. 5) && &eval(&eval($i - 1) - &eval($i - 0)) = -1) && ($i != 2 && $i > 0 && &eval($i - 1) = 0) && ($i != 2 && $i > 0 && &eval($i - 1) = 0)) && $i = 1) goto somewhere if (($i = 1 || $i < 5 || $i ~ 0 .. 5) && ($i != "" && $i > 0 && &eval($i - 1) = 0)) goto somewhere if (&eval (&eval($i-1) - 1) != "") goto somewhere if ((($i = 1) || ($i < 5 && $i ~ 0 .. 5)) && ($i != "" && $i > 0 && &eval($i - 1) > 0)) goto somewhere log ko stop :somewhere log OK }
WHILE Loop
A while in macros means that certain commands will be ran while the defined conditions are met.
Syntax
while (arg <condition> arg) as <loop> do bla bla ... end <loop>
Where;
- arg can be a variable, a nested variable, a special keyword, &eval or letters and numbers. And
- <loop> is the name of the loop. You can give any name you want.
Conditions can be found on Operators.
Examples
macro while { $i = 0 while ($i < 10) as loop log \$i = $i $i++ end loop }
The result is
[eventmacro log] \$i = 0 [eventmacro log] \$i = 1 [eventmacro log] \$i = 2 [eventmacro log] \$i = 3 [eventmacro log] \$i = 4 [eventmacro log] \$i = 5 [eventmacro log] \$i = 6 [eventmacro log] \$i = 7 [eventmacro log] \$i = 8 [eventmacro log] \$i = 9
Automacros
At this point, you can define macros and call them, typing 'eventMacro <macro name>' in OpenKore's console input.
Automacro is an automatic trigger for calling your macros, just like blocks in config.txt are automatic triggers for certain AI actions.
Automacro block consists of:
- One or more Parameters (call being the only required one).
- One or more Conditions.
Automacro does not trigger if there is currently running macro in exclusive mode. Otherwise, automacro clears macro queue (which means that all currently running macros are stopped) before call.
The point of automacro is that you use them to check for certain conditions and call your macro when all conditions are fulfilled.
Parameters
- Each parameter can only be used once.
- Parameters define the way the automacro or the called macro will work.
- Most parameters have a default value that will be used when it is not defined.
- call
-
- call is the only required parameter in every automacro.
- call defines which macro the automacro will execute.
- call can be a macro name or a macro block.
Example when using a macro name:
automacro <automacro name> { <automacro conditions and parameters (and only them)> call myMacro } macro myMacro { <macro instructions (and only them, as this is regular macro)> # for example: do move prontera do move payon }
Example when using a macro block:
automacro <automacro name> { <automacro conditions and parameters (and only them)> call { <macro instructions (and only them, as this is regular macro)> # for example: do move prontera do move payon } }
- Two examples above do the same thing.
- Note that the macro block used in the call parameter has the same rules as a normal macro block.
The first syntax is useful if you want more than one automacro to call one simple macro:
automacro First { <conditions> call print } automacro Second { <conditions> call print } macro print { log $.caller triggered }
- delay
-
- delay is an optional parameter.
- delay defines the time in seconds to wait before executing the macro in call parameter.
- If not used in the automacro the default value will be used, which is: 0.
- Must have a numeric value.
automacro <automacro name> { <automacro conditions and parameters (and only them)> delay 5 call myMacro } macro myMacro { <macro instructions (and only them, as this is regular macro)> log This is being logged 5 seconds after the automacro activated }
- run-once
-
- run-once is an optional parameter.
- run-once defines if the automacro can activate only once, or multiple times.
- If not used in the automacro the default value will be used, which is: 0.
- When it's value is 1 the automacro will only activate once, when it's 0 it can activate multiple times.
- To make an automacro with run-once value of 1 which already was already activated be able to run again you can use the command 'release' Macro Syntax.
automacro myautomacro { <automacro conditions and parameters (and only them)> run-once 1 call myMacro } automacro myaotherauto { <automacro conditions and parameters (and only them)> run-once 0 call myMacro } macro myMacro { <macro instructions (and only them, as this is regular macro)> log This macro will be called by myautomacro only once log but this macro can be called by myaotherauto many times }
- CheckOnAI
-
- CheckOnAI is an optional parameter.
- CheckOnAI defines in which AI states the automacro can activate.
- The default value for this parameter can be set in the config key eventMacro_CheckOnAI Configuration files.
- If not used in the automacro the default value will be used, which is the config key eventMacro_CheckOnAI.
- If eventMacro_CheckOnAI is not set in the config the default value will be used, which is: auto
- It's values can be a combination of auto, manual and off, separated by comma.
automacro MyAuto { <automacro conditions and parameters (and only them)> CheckOnAI manual call myMacro } macro myMacro { <macro instructions (and only them, as this is regular macro)> log This macro will only be called by MyAuto when AI is manual } automacro MyAuto2 { <automacro conditions and parameters (and only them)> CheckOnAI manual, off call myMacro } macro myMacro2 { <macro instructions (and only them, as this is regular macro)> log This macro will only be called by MyAuto2 when AI is manual or off }
- disabled
-
- disabled is an optional parameter.
- disabled defines if the automacro is active of not.
- If not used in the automacro the default value will be used, which is: 0.
- When it's value is 1 the automacro won't activate ever, when it's 0 it can activate normally.
automacro MyAuto { <automacro conditions and parameters (and only them)> disabled 1 call myMacro } macro myMacro { <macro instructions (and only them, as this is regular macro)> log This macro will never be called by MyAuto } automacro MyAuto2 { <automacro conditions and parameters (and only them)> disabled 0 call myMacro } macro myMacro2 { <macro instructions (and only them, as this is regular macro)> log This macro will be called by MyAuto2 normally }