eventMacro

From OpenKore Wiki
Revision as of 18:04, 1 March 2017 by Henrybkgg (talk | contribs)
Jump to navigation Jump to search

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

  • 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: