Scripts, Text & Audio

Traits and gameplay rules

Named passives with parameters that races and classes list - the built-in trait library, writing your own trait script, and traits every hero has as gameplay rules - edited in the Class & Race Editor's Traits tab.

A trait is a named passive: a Lua script with parameters, a title and a description. Races and classes list the traits their heroes have, each with its own values. A trait every hero has is a gameplay rule.

Traits let one script serve many races and classes: "no shields", "resists lightning by 15%" and "heals on kills" are written once and given to whoever should have them.

Giving traits to races and classes

# gamedata/heroes.toml (from the example-traits example)
[race.ef]   # Erudite women: no shields (with the race's own refusal), a little lightning resistance
traits = "no_shields(text=\"Erudites leave shields to lesser minds.\"); resist(element=lightning, percent=15)"

[race.def]  # Dark Elf women: a kill heals them a little
traits = "bloodlust(percent=4)"

[class.6]   # the shaman: a disc class given traits changes only its traits
traits = "last_stand(below=25, damage=30, defence=10)"

traits is ;-separated. Each name may give its own values in parentheses, name(key=value, key="a, b"), over the trait's defaults.

A hero has its class's traits (a mod class without traits has its base class's), then its race's, then every gameplay rule. A trait is had once, whoever gives it. The creation screen lists a race's and its class's traits after its strengths, by title.

The trait library

These are built in, as lib/<name>.lua scripts any trait may use:

Trait Does Parameters
no_shields Refuses shields text (the refusal)
cloth_only Armour must be cloth (circlets aside), as the wizard text, shields (false), shield_text
forbid_gear Refuses what it names slots, kinds, damage (comma-separated names), cloth (only or never), text
allow_gear Allows what it names, over the class's rules slots, kinds, damage
own_armour Wears only its own armour types in the slots they cover, as the Erudites wear robes (Race Builder) pieces (comma-separated: frogbody, froghelmet), text
resist Takes less damage of an element element (fire cold lightning poison disease none all), percent
stat_bonus More statistics strength, intelligence, dexterity, stamina, armor, max_health, max_energy, crit, damage and speed (percents), per_level (each value × the level)
regeneration Faster regeneration health, energy (percents faster), heal_per_second
bloodlust Health and energy on kills percent (of maximum health), energy (percent of maximum energy), chance
last_stand Stronger when nearly dead below (percent health), damage (percent more), defence (percent less taken)
infinite_arrows Bow shots take no arrows chance (in 100; 100: never takes one)
infinite_throwing Throws take nothing chance
bonus_attributes More points each level stat (2: five a level instead of three), skill
retain_bloodstones The campaign's end keeps the bloodstones prefix (bloodstone), levels (bossgood, bossevil; empty: everywhere)

The slot, kind and damage names are those of the can_equip hook's item (see Lua scripts).

A mod can change a library trait's keys or parameters with its own [trait.<name>] (key by key), replace its script for everyone with scripts/lib/<name>.lua, or copy it as a new trait. The Traits tab does each.

Your own trait

# gamedata/heroes.toml
[trait.thick_hide]
title = "Thick Hide"                  # a text key or words; shown with the race's strengths at creation
description = "Takes less damage from blows, more from fire."
script = "thick_hide.lua"             # scripts/thick_hide.lua, or lib/<name>.lua (the library's)
category = "race"                     # race, class or rule: the devkit's grouping only
everyone = false                      # true: every hero has it (a gameplay rule)
hidden = false                        # true: not listed at creation

[trait.thick_hide.params]             # the defaults; hero.params in the script
blows = 10
fire = 10

[race.bm]                             # barbarian men have it, and regenerate faster
traits = "thick_hide; regeneration(health=20)"
-- scripts/thick_hide.lua
function on_hurt(hero, hurt, rank)
  local p = hero.params
  if hurt.element == "none" then return hurt.damage * (1 - (p.blows or 0) / 100) end
  if hurt.element == "fire" then return hurt.damage * (1 + (p.fire or 0) / 100) end
end

A trait's script may define any hero hook. It runs alongside the class script, the racial passive and the ranked skills' scripts. Parameters reach it as numbers, true / false or strings, in hero.params; hero.trait is the trait's name, and hero.data is kept per trait.

Gameplay rules

A trait with everyone = true is a rule every hero has, whatever their race and class. The port's gameplay switches are library traits, so a mod can turn them on and tune them:

Launcher switch Trait
Infinite Arrows infinite_arrows
Infinite Throwing Weapons infinite_throwing
Retain Bloodstones retain_bloodstones
Attributes Per Level bonus_attributes (or [levels] stat_points = 5)
# gamedata/heroes.toml (from the example-gameplay-rules example)
[trait.infinite_arrows]
everyone = true

[trait.infinite_arrows.params]
chance = 75                      # three shots in four are free

[trait.bonus_attributes]
everyone = true

[trait.bonus_attributes.params]
stat = 2                         # five attribute points a level instead of three
skill = 1                        # and one more skill point

The launcher's switches stay as they are and add to a mod's rules.

The Traits tab

The Class & Race Editor's Traits tab lists every trait by category (racial, class, gameplay rules):

  • New traits from the template, or as a copy of a library trait.
  • Each trait's title, description, script (checked in the sandbox, its hooks listed), the Every hero switch and its parameters.
  • Checkboxes giving it to any race or class. A disc race or class changed this way is written as only what changed.

The Races and Classes tabs edit each one's traits list with its own values.

Examples

example-traits gives Erudites, Dark Elves, Barbarians and the shaman traits, with a trait of its own script, and example-gameplay-rules turns the gameplay switches on as rules. See Examples.