Skip to content

Latest commit

 

History

History
213 lines (161 loc) · 7.21 KB

system-hooks.md

File metadata and controls

213 lines (161 loc) · 7.21 KB

Starfinder System Hooks

The Starfinder system has a couple of its own hooks available for module/macro developers.

General Hooks

onBeforeRoll

Name: onBeforeRoll

Called when: Whenever the system makes a roll.

Arguments: Object with three keys: formula, data, options.

  • formula: String that describes the roll formula.
  • data: Data to be passed along into the roll.
  • options: Options to be passed along into the roll.

Example usage:

Hooks.on("onBeforeRoll", (rollData) => {
    rollData.formula = rollData.formula + " + 1";
});

Actor Hooks

onActorSetCondition

Name: onActorSetCondition

Called when: Whenever the conditions on an actor are set or removed.

Arguments: Object with four keys: actor, item, conditionName, enabled.

  • actor: The actor who is getting the condition set.
  • item: The condition item that was created or destroyed.
  • conditionName: The name of the condition.
  • enabled: Boolean true or false, to indicate if the condition was set or removed.

Example usage:

Hooks.on("onActorSetCondition", ({actor, item, conditionName, enabled}) => {
    console.log(['Actor condition', actor, item, conditionName, enabled]);
});

onActorRest

Name: onActorRest

Called when: Whenever an actor does a short rest (10 min rest), a long rest (8 hour rest), or if they are repaired (Drone only).

Arguments: Object with several keys: actor, restType, deltaHitpoints, deltaStamina, deltaResolve, updateData, updateItems.

  • actor: The actor who is performing the rest.
  • restType: Supported values are "short", "long", or "repair", depending on the type of rest.
  • deltaHitpoints (optional): The amount of hitpoints gained during this rest.
  • deltaStamina (optional): The amount of stamina gained during this rest.
  • deltaResolve (optional): The amount of resolve points gained during this rest.
  • deltaSpellSlots (optional): The amount of spell slots gained during this rest.
  • restoredAbilityDamages (optional): The amount of ability damage removed during this rest.
  • updateData: The updated data as written to the actor's entity.
  • updateItems: Array of items that have been updated for this rest.

Example usage:

Hooks.on("onActorRest", ({actor, restType, deltaHitpoints, deltaStamina, deltaResolve, updateData, updateItems}) => {
    console.log(['Actor condition', actor, restType, deltaHitpoints, deltaStamina, deltaResolve, updateData, updateItems]);
});

Item Hooks

attackRolled

Name: attackRolled

Called when: Whenever an attack is rolled, either from the inventory, a chat card, a macro, or any other way of rolling attacks from a given actor and its items.

Arguments: Object with five keys: actor, item, roll, formula, rollMetadata.

  • actor: The actor who is rolling the attack.
  • item: The item that is used in the attack, may be null.
  • roll: The roll object generated by the attack.
  • formula: Object with two keys: base, final. Describes the formula used for the roll.
  • rollMetadata: Object that was passed into Item#rollAttack, used for passing along data for the attack.

Example usage:

Hooks.on("attackRolled", ({actor, item, roll, formula, rollMetadata}) => {
    console.log(['attacked', actor, item, roll, formula, rollMetadata]);
});

damageRolled

Name: damageRolled

Called when: Whenever damage is rolled, either from the inventory, a chat card, a macro, or any other way of rolling damage from a given actor and its items.

Arguments: Object with five keys: actor, item, roll, isCritical, formula, rollMetadata.

  • actor: The actor who is rolling the damage.
  • item: The item that is used in the damage, may be null.
  • roll: The roll object generated by the damage.
  • isCritical: Boolean true or false, to indicate if the damage was a critical damage or not.
  • formula: Object with two keys: base, final. Describes the formula used for the roll.
  • rollMetadata: Object that was passed into Item#rollDamage, used for passing along data for the damage.

Example usage:

Hooks.on("attackDamage", ({actor, item, roll, isCritical, formula, rollMetadata}) => {
    console.log(['damaged', actor, item, roll, isCritical, formula, rollMetadata]);
});

itemActivationChanged

Name: itemActivationChanged

Called when: Whenever an item is activated or deactivated.

Arguments: Object with three keys: actor, item, isActive.

  • actor: The actor who owns the item that is being activated or deactivated.
  • item: The item that is being activated or deactivated.
  • isActive: Boolean value indicating whether the item is being activated (true) or deactivated (false).

Example usage:

Hooks.on("itemActivationChanged", ({actor, item, isActive}) => {
    console.log(['activatedOrDeactivated', actor, item, isActive]);
});

itemReloaded

Name: itemReloaded

Called when: Whenever an item is reloaded, using the reload button on the character sheet.

Arguments: Object with two keys: actor, item.

  • actor: The actor who owns the item that is being reloaded.
  • item: The item that is being reloaded.

Example usage:

Hooks.on("itemReloaded", ({actor, item}) => {
    console.log(['reloaded', actor, item]);
});

Combat Hooks

Combat hook event data

Most of the combat hooks use a common object that is the same for all of them. Refer to this header to find more info on the data that is passed along.

Combat Event Data is an object with a series of keys:

  • combat: The Combat object that is involved.
  • isNewRound: Boolean true or false, to indicate that the current round is changing.
  • isNewPhase: Boolean true or false, to indicate that the current phase is changing.
  • isNewTurn: Boolean true or false, to indicate that the current turn is changing.
  • oldRound: Integer indicating the old round value.
  • newRound: Integer indicating the new round value.
  • oldPhase: Integer indicating the old phase value.
  • newPhase: Integer indicating the new phase value.
  • oldCombatant: Combatant object indicating the old combatant, if turn is changing.
  • newCombatant: Combatant object indicating the new combatant, if turn is changing.

onBeginCombat

Name: onBeginCombat

Called when: When a combat is began, i.e. right after the GM presses "Begin Combat" in the encounter tracker.

Arguments: Combat Hook Event Data

Example usage:

Hooks.on("onBeginCombat", (combatEventData) => {
    console.log(['combat began', combatEventData]);
});

onBeforeUpdateCombat

Name: onBeforeUpdateCombat

Called when: When a combat encounter is about to be updated, for example when "End Turn" is clicked.

Arguments: Combat Hook Event Data

Example usage:

Hooks.on("onBeforeUpdateCombat", (combatEventData) => {
    console.log(['combat about to be updated', combatEventData]);
});

onAfterUpdateCombat

Name: onAfterUpdateCombat

Called when: Right after a combat has been updated, for example when "End Turn" is clicked.

Arguments: Combat Hook Event Data

Example usage:

Hooks.on("onAfterUpdateCombat", (combatEventData) => {
    console.log(['combat was just updated', combatEventData]);
});

onBeforeCombatEnd

Name: onBeforeCombatEnd

Called when: Right before a combat ends.

Arguments: Combat object

Example usage:

Hooks.on("onBeforeCombatEnd", (combat) => {
    console.log(['combat is about to be over', combat]);
});