AI Scripting Overview
AI Scripting
The Ryzom Core AI system has a sophisticated custom scripting language that is used for scripting the various group states.
You can also get thorough documentation by going to AI Scripting Native Functions Reference.
Here's an example of a simple code block:
(aggroSize)getAggorListSize(0); // to much player are attacking the boss if (aggoroSize > 10) { ($player1)getAggroListElement(0); ($player2)getAggroListElement(1); ($player3)getAggroListElement(2); // so the boss teleport 3 person from its aggro list at the end of the world teleportPlayer($player1, 14233, 123123, 0, 0); teleportPlayer($player2, 14233, 123123, 0, 0); teleportPlayer($player2, 14233, 123123, 0, 0); clearAggroList(); }
In addition to code segments within AI actions you can also create AI script templates in World Editor using the script_rep and script nodes. It looks a little like this:
AI Script Rep Container in World Editor
AI Script Window for Script Rep
General information
Its a C like code.
Comments are defined after two slashes like this:
// my comment
Code is used to specify decisions for state machine on group. Each group can have different variables and functions, they can only be affected via code only.
Variables don't need to be defined before they are used. They are automatically created with value equals to 0 or "".
Variables are either floating point numbers (no prefix), character strings ('$' prefix) or script contexts ('@' prefix).
There are two special object that are hard-coded and that can be used to call function:
- parent: represent the parent group of the current group
- caller: represent the group that called a function on the current group
Additionnaly one can reference any static group defined in the same AI instance by its name. The usage is similar to that of 'parent' and 'caller'. In fact 'parent', 'caller' and group names are a kind of pseudo-contexts and can be used as such (without the '@' prefix).
Debug and log
There are two special function for debug and logging:
- print: used for debug purpose, removed in release mode
- log: used to display any information that should be read in release mode
About Functions
You can dynamically define function on the group.
User functions don't have parameters.
Functions can be defined this way:
You can call a function like this (note that if a function is not defined for a group, nothing is called):
my_function(); // call my_function from this group group1_tryker.my_function(); // call my_function for group1_tryker (inside this function the current group is accessible via caller keyword)
Variable manipulation
Some simple mathematical operators can be used: +, -, /, * with or without parenthesis.
You can do comparison with variables and or numbers (can be used for if and while statements).
Code flow structure
Classical code flow constructs
while, if, else can be used as in C.
onchildren
onchildren
Native function calls
Native calls are available too. Native calls offer hard coded services to the scripter.
Native calls have input and output parameters (AKA parameters and return values).