eventMacro: Difference between revisions
No edit summary |
No edit summary |
||
Line 261: | Line 261: | ||
:* exclusive [0|1] | :* exclusive [0|1] | ||
=== | === Variables === | ||
* You can work with variables. Variable declaration is not needed. All macro variables are global. | * 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. | * EventMacro variable system is based in perl and has support for scalars, arrays and hashes. | ||
* Variable names may only contain letters and numbers. | |||
==== Types of variables and their definitions ==== | |||
: '''Scalar''' | : '''Scalar''' | ||
:* Scalar variables can hold a single piece of information, like a number or a string of characters. | :* Scalar variables can hold a single piece of information, like a number or a string of characters. | ||
Line 277: | Line 278: | ||
:* Arrays start with the symbol '''@'''. | :* Arrays start with the symbol '''@'''. | ||
: ''' | : '''Hashe''' | ||
:* Hash variables hold many '''pairs''' of things. | :* Hash variables hold many '''pairs''' of things. | ||
:* Each hash pair in consisted of a '''key''' and a '''value'''. | :* 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. | :* Each key has only one value, but many keys can have the same value. | ||
:* Hashes start with the symbol '''%'''. | :* 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! | |||
If you want to use the '''''$''''' symbol you should escape it with '''''\'''''. | |||
macro money { | |||
log I have a lot of $ | |||
} | |||
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. |
Revision as of 20:17, 28 February 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 |
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.
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 @.
- Hashe
- 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!
If you want to use the $ symbol you should escape it with \.
macro money { log I have a lot of $ }
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.