RPG script
WARNING: Information here is incompatible with 2.6.1 and earlier
How things work
The system is stack based. Basically when scripts are executed the stack is pushed, the script executed and then popped. This allows the system/user to define additional lookups on the stack. There are two types of references, regular and temporary references, both serve different purposes, and the stack is searched in reverse for them.
The only notable difference between them is how they're set. Regular lookups search the whole stack for an existing reference to modify, temporary lookups only search the top of the stack for an existing instance and create one if it doesn't exist. This effectively allows temporary references to ghost references in the lower stack; In other words with temporary references, you can have two references with the exact same name which point to two distinctly different things.
Users cannot define temporary lookups. In addition most commands require references to function.
r_loop_maps ref [ //ref here refers to the current map r_loop_ents ref ref [ //ref here refers to the current entity, the map version is ghosted but not lost //now lets do something productive like killing everyone but the player if (! (r_matchref ref player)) [r_kill ref player] ] ]
Reserved lookups
Since the RPG works with named lookups, there are several named you should never explicitly define or set. There's no rule against doing so, but keep in mind very bad things may happen if you do. They are as follows.
- player - a reference to the player
- hover - a reference to whatever the player's cursor is hovering over (even nothing)
- curmap - a reference pointing to the current map
- talker - (dialogue) a reference to whoever is talking to the player
The following can be overwritten, but exercise due caution when doing so. They are defined when the RPG explicitly calls character, item and map scripts (albeit using temporary references).
- self - in map or ent scripts, refers to the invokee
- actor - when scripts are executed, this refers to the entity who invoked them.
- item - during item scripts this refers to the selected item
Loops
There are 4 loops, each iterate over certain things, they are as follows
Command: r_loop_maps reference body
Makes a temporary reference named 'reference', and has it reference each of the maps in turn on which it executes the body.
Command: r_loop_ents map_reference reference body
map_reference: must reference a map
Makes a temporary reference named 'reference', and has it reference each of the entities that exist on the map pointed to by map_reference.
Command: r_loop_aeffects map_reference ent_reference reference body
map_reference: must reference a map
ent_reference: must reference an entity if bounds checking is desired
Makes a temporary volatile named reference that iterates over all area effects on the map_reference that afflicts ent_reference (if provided), loops over all area effects otherwise
Command: r_loop_inv ent_reference reference body
ent_reference: must reference either a character (such as the player) or an object (such as a chest)
Makes a temporary reference named 'reference', and has it reference each of the items that exist in the entity's inventory
Command: r_loop_equip ent_reference reference body
ent_reference: must reference a character
Makes a temporary volatile reference named 'reference', and has it reference each of the items the entity has equipped. you sohuld avoid unequipping anything while doing this
Command: r_loop_veffects ent_reference reference body
ent_reference: must reference an entity
Makes a temporary volatile reference named 'reference', and has it reference each of the status effects that plagues the provided entity