Attaching scripts
How scripts and blueprints are hooked up to what runs them - classes, races, skills, items, bonuses and creatures, level and map scripts, and objects' script fields - and how the devkit's editors attach them for you.
Scripts and blueprints are files of the mod: scripts/**.lua, maps/<id>.qs, a level's script.qs, and
assets/graphs/<name>.rgraph. What runs a script names it: a class names its passive, a creature its monster
script, an object the level script's public it runs. The devkit's editors list the choices and do the naming for you.
Actors: Lua scripts
Every field that names a Lua script is a list of the mod's Lua files, and of its hero-script blueprints with the file each writes:
| Field | In |
|---|---|
| A class's script, a race's passive | Class & Race Editor |
| A trait's script | Class & Race Editor, Traits tab |
| A scripted skill's script, a design's script | Class & Race Editor, Skill Designer |
| An item's or a bonus's script | Items |
| A creature's Lua hooks | Creature Editor |
Beside each field:
- Open opens the blueprint that writes the file, or the file in Lua Scripts.
- New blueprint makes a hero-script blueprint writing
scripts/<name>.lua, attaches it and opens it in the Blueprint Editor.
Note Creatures run monster hooks, which blueprints don't make yet: their field offers Lua files and existing blueprints only.
By hand, the keys are:
# gamedata/heroes.toml
[class.7]
script = "paladin.lua" # scripts/paladin.lua
[race.tm]
passive = "regen.lua"
# gamedata/items.toml
[item.lantern]
script = "lantern.lua"
[bonus.thunderstruck]
script = "thunderstruck.lua"
# gamedata/monsters.toml
[kind.goblinshaman]
script = "shaman.lua"
Game scripts (scripts/game/) need no naming: they run by themselves.
Levels
A level runs one script:
| Level | Script | Edit it |
|---|---|---|
| A custom map | maps/<id>.qs |
The Level Editor's Details > Map: Open blueprint (the one writing that file) or New blueprint (a level-script blueprint targeting it), and Edit as text in the Script Editor |
| A disc level | BG/DATA/<LEVEL>.GOB/<lump>.lmp/script.qs |
The Script Editor, or a blueprint whose target is that level (Where it writes) |
Objects
An object runs a public of its level's script by name, in its script fields:
| Field | On | Runs the public when |
|---|---|---|
initscript, deathscript, resurrectscript |
Creatures, ScriptGenerator |
It is placed, dies, comes back |
followLostScript, followFoundScript |
Creatures, ScriptGenerator |
A follower loses or finds the hero |
dialogscript |
NPC |
It is talked to |
exclamation |
NPC |
The game asks whether it has news (return 1 for the "!") |
t |
Trigger |
A player enters (and not<t> when the last one leaves) |
script |
MonsterTrigger |
For each creature inside, every think |
script |
Portals, catapults | Whether it may be used (a condition) |
key |
Doors, chests, PushTrigger |
Whether it opens (a condition; return 1 or 0) |
action, action<N> |
Doors, chests, props | It is used; a prop enters state N |
In the Level Editor, each field has a ... list of the map script's publics: the events of its blueprint, or the publics of its text. See Map objects.
Example Make a captain's death open a gate.
In the Level Editor, select the captain and set deathscript to
onCaptainDeath.Open the map's script (Details > Map > Edit as text) and add:
public onCaptainDeath() { trigger("exitGate", 1); }Play the map, kill the captain, and watch the gate.
