World

Prefabs

Reusable groups of map objects placed as one - a brazier with its fire, light and trigger, a camp, a shrine with its script - and item prefabs, lights and effects an item carries while it is worn.

A prefab is a group of map objects you make once and place many times, like a Unity prefab or an Unreal blueprint: a brazier with its fire, its light and the trigger that lights it, a camp of tents and guards, a shrine with its script. A map places it as one object, and the game puts its parts in when the map is played.

A prefab can also be an item prefab: lights, effects and element particles an item carries while it is worn, with a Lua script that runs while it is worn.

Prefabs are prefabs/<id>.toml in the mod, made in the Prefabs module (World section) or straight from the Level Editor.

Making a prefab from a map

The quickest way: build the group in the Level Editor, select its objects, and press Make prefab in Details > Selection. The objects become prefabs/<id>.toml, and one placement of it stands where they were.

To change one placement's parts by hand, select it and press Unpack into its parts: it becomes ordinary objects again.

The Prefabs module

The list on the left has the mod's prefabs; type a name and press New to make one. The Details edit the selected prefab, the viewport draws a plan of its parts from above, and Save writes the file. Every change is an undo step.

  • Name, description, category: the category is the group it's listed under in the Level Editor's palette (default Prefabs).
  • Parts: each part is any object a map can place (Map objects), with a key, an offset and a facing (relative to the placement, turned with it) and its parameters. Lights have quick fields (colour, radius, Light mode). Add part adds one from templates (a light, a fire, a trigger, a prop, another prefab); Copy and Delete on each part; Add parameter on each.
  • Script: a QuestScript beside the prefab (prefabs/<id>.qs); Create the script makes a starting file. It is added to the map's own script once, however many placements there are.
  • Item: the items it attaches to, its Lua script and its attachments (below).

$name

In a part's values, $name stands for the placement's own name= (or prefab<N> when it has none). That's how each brazier in a map gets its own light and trigger names:

# prefabs/brazier.toml
[prefab]
name = "Brazier"
description = "A fire pot with its light; trigger(\"<name>\") puts it out"
category = "Props"
script = "brazier.qs"

[part.fire]
kind = "Firepot"
pos = [0, 0, 0]
p0 = "name=$name_fire"

[part.glow]
kind = "PointLight"
pos = [0, 0, 40]
p0 = "color=#ff9a40"
p1 = "radius=220"
p2 = "mode=flicker"
p3 = "name=$name"

Parts may be other prefabs, nested up to 8 deep.

Placing a prefab

In the Level Editor's Place palette, the Prefabs category lists the mod's prefabs and those of the mods it requires. A placement can change single parameters of its parts with <part>.<key>=<value>:

[object.30]
kind = "Prefab"
pos = [1200, -400, 0]
yaw = 90
p0 = "prefab=brazier"        # <id>, or <mod>/<id> for another mod's
p1 = "name=gate_fire"        # replaces $name in the parts' values
p2 = "glow.radius=320"       # this placement's light is bigger

A later mod's prefab of the same id wins. Everything a prefab places is an ordinary map object, so network games see the same parts on every machine.

Note A map that runs the base level's script (run_base_script) doesn't get the prefabs' scripts; the log says so.

Item prefabs

An item prefab dresses items: a blade that burns, a staff with a glow, a lantern on the belt. Its Item fields:

  • Items it attaches to, by name (comma separated): Short Sword, Long Sword.
  • Or prefixes / suffixes: every item rolled with that quality prefix or "of X" suffix, whatever its base. That's an affix's look; the Prefixes & Suffixes editor makes these for you.
  • A Lua script of hero hooks (in scripts/) that runs while the item is worn, like a class's script (Lua scripts). Create the Lua script makes a starting file.
  • Attachments: Add a light (colour, radius, mode, Casts shadows), Add an effect (an Effect Creator effect, looping while worn; Edit in the Effect Creator opens it), or Add element particles (fire, cold, poison, lightning, disease: the weapon enchantments' particles). Each has where it sits: along a held weapon (0 the grip, 1 the tip), or an offset on the body.
[prefab]
name = "Burning blade"
items = "Short Sword, Long Sword"
lua = "burning_blade.lua"

[attach.0]
type = "light"
along = 0.9          # near the tip
color = [1, 0.5, 0.2]
radius = 150
mode = "flicker"

[attach.1]
type = "element"
element = "fire"

[attach.2]
type = "effect"
effect = "my_glow"

Attachments follow a held weapon along its blade, and a worn item on the hero. Item lights are for show; they count toward the 16 nearest lights like any other.

Note Item attachment offsets are new and haven't been tuned in the game yet: expect to adjust along and the offsets by eye.