eventMacro
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 |
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 macro 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.