No active sessions yet.

No games yet.

No conversations yet.

No characters yet.

Hooks

The moments a rule can attach to, and what each one carries.

A hook is a rule that runs when the engine does something anywhere in the world. An item rule, by contrast, runs when a player uses one specific object.

A hook has a trigger, an optional condition, and a body.

Triggers

Trigger Fires when $.event carries
onSpawnCreature a creature enters the world
onSpawnItem an item enters the world; the item is the subject
onDamage hit points actually drop, from any source amount killed abilityName weapon weaponKey
onHeal hit points actually rise amount
onDeath someone dies (players too), after loot and XP
onCombatStart a fight begins; subject is the location
onCombatRoundEnd a combat round closes; subject is the location
onEffectApplied an effect applies to someone
onAttack every swing, misses included weapon weaponKey ranged ammo rounds attacking
onLocationEnter the party arrives (NPCs moving do not fire it); subject is the new location
onMapEdge the party reaches a dead end, every exit already visited exits
onItemUse an item rule runs
onAbilityUse someone uses an ability (players, NPCs and creatures); subject is the caster abilityName target passed
onRoll a skill check resolves; it can't change the roll passed total dc margin crit botch stat note abilityName reason
onTurnStart once per actor per turn
onTurnEnd once per actor per turn, NPCs off-screen included inCombat rested
onTimePasses in-game time advances during a turn, travel, or sleep minutes resting
onTravel the party covers ground distance
onBeforeAction someone tries something, before it happens: every swing by a player, NPC or creature, and a player's other combat moves and rest attack weapon ranged combatAction swings stat note actionOrdinal
onBeforeTravel before each leg of a walk; subject is where the party stands from to destination leg legs distance arriving
onBeforeNpcTravel before an NPC on an errand, schedule or patrol steps to the next place, off screen too; subject is the NPC from to distance

A hook can also answer another plugin's event, written pluginId:eventKey, like rest:sleep. See Cooperation.

Picking one

  • Trying vs hurting. onAttack fires on every swing. onDamage fires only when hit points move. Stamina per swing goes on the first; bleeding goes on the second.
  • Per turn vs per minute. For anything that ticks per character per turn, use onTurnEnd. onTimePasses minutes can be the narrator's guess; see Minutes are not time.
  • The creature vs its gear. A hook writes to its subject. onSpawnCreature writes to the bandit; onSpawnItem writes to the bandit's sword. A rolled modifier or a curse on an object goes on the second.
  • The party vs everyone. onLocationEnter, onTravel and onBeforeTravel follow the party; onBeforeNpcTravel is the NPCs' road. A rule about NPCs wherever they are goes on onTurnEnd and reads their state, such as $.subject.location === $.subject.home.
  • Round vs turn. A turn is one actor, while a round is everybody. Things that last "a round", like a brace or a mark, expire on onCombatRoundEnd.
  • Swinging vs swung at. A plugin's onAttack hook runs once per swing, about the target. A character's, creature's or effect's hook runs for whichever side it's on, and $.event.attacking says which: true when they swung, false when they were swung at.
  • weapon vs weaponKey. weapon is the item's name. weaponKey is that exact object. Wear and tear goes on the key, or it lands on the spare in the pack instead of the blade in hand.
  • What hurt them. On onDamage, abilityName is the ability cast that dealt the harm, and weapon / weaponKey the weapon swung or the item whose rule dealt it. Each is empty for harm with no ability or weapon, such as a poison tick, a world event or a bare fist.
  • ammo is the round the swing spent, such as Bodkin Arrow, and empty when it spent none. $.spawnItem({ itemExpr: $.event.ammo, at: "self" }) drops the loosed arrow where the target stands.
  • rounds is how many rounds the swing spent: 0 for none, 1 for most shots, more for a burst. A magazine counter takes by: -$.event.rounds.

onBeforeAction says no

It's the trigger for refusing. A refuse in it stops the action and says why.

if ($.event.attack && $.field('stamina') < 5) {
  $.refuse('their arms are too heavy to lift the blade again')
}

$.event.actionOrdinal is which action this is in the turn (0 for the first), so $.event.actionOrdinal > 0 limits a turn to one action.

Every swing by a player, an NPC or a creature passes through it before any ammunition is spent. The subject is the one swinging, and $.weapon is what they hold.

A gun with a magazine

Ammunition draws loose rounds from the pack. For a gun that keeps a count of the rounds loaded in it, with one rifle empty while the spare is full, leave the gun's fires empty and give it a number variable such as mag. Then a plugin needs two hooks.

onBeforeAction refuses the shot when that gun is empty:

if ($.event.attack && $.event.ranged && $.weapon && $.weapon.fields.mag <= 0) {
  $.refuse('the magazine is empty')
}

onAttack spends the round from that exact gun. Its subject is the target. The gun is read off $.source.weapon and written through $.event.weaponKey:

if ($.event.ranged && $.source.weapon && $.source.weapon.fields.mag > 0) {
  $.adjustField({ field: 'mag', by: -1, item: $.event.weaponKey })
}

Reloading is a way of using the gun (reload) whose rule spends a magazine and refills the count: $.consume('Rifle Magazine'), then $.setField({ field: 'mag', to: 30 }). NPCs use items too and reload the same way. A gun like this has no ammo kind, and an NPC with an empty one does not switch weapons by itself. The refusal tells them why the shot never comes.

onBeforeTravel decides the road

A walk can cross several places in one turn. Before anyone moves, onBeforeTravel runs once for each leg, in order, with the place the party stands in as its subject. A refuse ends the walk immediately. The party spends the turn in $.event.from and the narrator tells the reason. A refusal on the first leg means the party never sets out.

$.event
from where the party stands before this leg
to the next place
destination where the walk is headed
leg / legs which leg this is (1 for the first) and how many there are
distance this leg's length
arriving true on the leg that ends the walk

It runs before the people present answer, so everything the hook does is already there when they do. A creature it spawns appears in from, waiting where the walk stops, and anyone hostile there gets the usual ambush.

Some long walks through wild country stop short:

if ($.event.legs > 1 && !$.event.arriving && $.random() < $.dial('roadTrouble')) {
  $.refuse('the road is washed out, and the party has to find a way round')
}

Bandits on the road out of town:

if ($.event.leg === 2 && $.random() < 0.15) {
  $.spawnMob({ mob: 'Highway Bandit' })
  $.refuse('bandits step out onto the road ahead')
}

When the players are headed for different places that turn, the walk is decided later and this trigger doesn't fire. onTravel and onLocationEnter still fire for each leg actually walked.

onBeforeNpcTravel is the same gate for NPCs

NPCs walk one place per turn on their errands, schedules, patrols and wanderings. Before each step, onBeforeNpcTravel runs with the NPC as its subject. A refuse keeps them where they are, and they remember why. A gate shut at night, for everyone:

if ($.event.to === "Old Town" && $.timeBetween("22:00", "06:00")) {
  $.refuse("the town gate is barred for the night")
}

Pair it with the same check in onBeforeTravel and the gate holds for the party too. It does not fire for an NPC keeping pace with the party, fleeing a fight, or walking in on the party as part of how the people present answer.

onRoll answers, never rewrites

An onRoll hook runs once the roll is decided, before the people present answer. It can't change the roll. The roll card always explains its number, but whatever it sets off lands: damage, an effect, an item taken or given, a world flag, a creature, a narrated line.

That's how a game gives failures teeth. Add a complication on a bad fail, but not on every fail, and not one that grants what the roll denied:

if (!$.event.passed && $.event.margin <= -5 && $.random() < $.dial('mishapChance')) {
  $.setWorld({ key: 'WATCH_ALERTED', value: 'YES', scope: 'location' })
  $.narrate('the clatter carries down the street, and someone shouts for the watch')
}

It's also how something improves with use:

if ($.event.passed && $.event.margin > 5 && $.event.note === 'read') {
  $.adjustField({ field: 'insight', by: 1 })
}

margin is total minus DC, negative on a failure. crit and botch read the natural die, which is a different question from passed.

Example: a fever, in three hooks

onTimePasses: it climbs.

if ($.field('fever') > 0) {
  $.adjustField({ field: 'fever', by: $.timed
    ? ($.event.minutes / 60) * $.dial('feverPerHour')
    : $.dial('feverPerTurn') })
}

onTurnEnd: a high fever hurts.

if ($.field('fever') >= 10) {
  $.damage({ amount: 1 })
}

onBeforeAction: too sick to fight.

if ($.event.attack && $.field('fever') >= 15) {
  $.refuse('the fever has taken their balance; the blade will not answer')
}

Next

Conditions: gating when a hook may run.