Hooks

Hooks are triggered at a predefined moment. Hooks can come with variables added to a lua table and passed in as a parameter, most values are provided as Type > String and therefore have to be converted to a number, if needed.
If the hook function returns false the hook is automatically removed.

Example:

addHook("onCharacterCreate", function(variables)
	game.print(getCharacterData(variables["character"], "extra", "name"))
end)
addHook("onPreTimePassed", function(variables)
	addCharacterData("player", "budgetcurrent", "hunger", tonumber(variables["timePassed"]) * -1.5)
end)

Basic Hooks

"onFrame"

Triggers every frame.
Variables: None

"onPreLoadFiles"

Triggers before Assets are loaded.
Variables: None

"onPostLoadFiles"

Triggers after Assets are loaded.
Variables: None

"onGameStarted"

Triggers after a game is started. Triggers after "onPostNewGame" or "onPostLoadGame".
Variables: None

"onPreNewGame"

Triggers after the new game window opened.
Variables: None

"onPostNewGame"

Triggers after a new game is started.
Variables: None

"onPreSaveGame"

Triggers before a save game is saved.
Variables: None

"onPostSaveGame"

Triggers after a save game is saved.
Variables: None

"onPreLoadGame"

Triggers before a save game is loaded.
Variables: None

"onPostLoadGame"

Triggers after a save game is loaded.
Variables: None

"onCharacterCreated"

Triggers after a character is created.
Variables:

  • "character" = character key

"onPreTimePassed"

Triggers before time is passing.
Variables:

  • "timePassed" = time passed in hours
  • "dayPassed" = true if a day will pass

"onPostTimePassed"

Triggers after time is passing.
Variables:

  • "timePassed" = time passed in hours
  • "dayPassed" = true if a day has passed

"onOptionsChanged"

Triggers after an options is edited.
Variables: None

"onInteractionStarted"

Triggers when an interaction starts.
Variables:

  • "interaction" = interaction key
  • "cX" = one variable per involved character, starting with "c0"
  • "pX" = one variable per involved place, starting with "p0"
  • "iX" = one variable per involved item, starting with "i0"

"onInteractionStopped"

Triggers when an interaction stops.

"onPostCharacterAttendance"

Triggers after characters attendance is calculated. Usually when time passes.
Variables:

  • "character" = character key
  • "place" = place key

"onEquip"

Triggers after an item is equipped by a character.
Variables:

  • "item" = item key
  • "character" = character key

"onUnequip"

Triggers after an item is unequipped by a character.
Variables:

  • "item" = item key
  • "character" = character key

"onVisitLocation"

Triggers when a location is visited.
Variables:

  • "location" = location key

"onVisitPlace"

Triggers when a place is visited.
Variables:

  • "place" = place key

"onVisitItem"

Triggers when a item is "visited".
Variables:

  • "item" = item key

"onItemAdded"

Triggers when an item is added to an inventory.
Variables:

  • "item" = item key
  • "inventory" = inventory key

Return Hooks

Return Hooks trigger whenever a hooked value is changed. The return value (variables["return"]) can be changed by the hook and is applied after all hooks are executed.

"onCharacter[Character Value]Set"

Hooks: "onCharacterExtraSet", "onCharacterSkillSet", "onCharacterAttributeSet", "onCharacterBudgetCurrentSet", "onCharacterBudgetMaxSet", "onCharacterFeatureSet", "onCharacterOutfitSet"

Triggers when a Character Value is set.
Variables:

  • "return" = value to change to
  • "character" = character key
  • "key" = value key

"onCharacterActivityRequest"

Triggers when the activities of a character are requested. This usually happens right before the attendance is calculated. The return determines the weight that is used to decide which place the character will attend, most of the times it should be between 0.0 and 1.0.
Variables:

  • "return" = activity weight
  • "character" = character key
  • "activity" = activity identifier

"onCharacterAttendanceSet"

Triggers when characters attendance is calculated. Usually when time passes.
Variables:

  • "return" = place key this character will attend
  • "character" = character key

"onPlace[Place Value]Set"

Hooks: "onPlaceExtraSet", "onPlaceAssignedSet", "onPlaceSlotSet"

Triggers when a Place Value is set.
Variables:

  • "return" = value to change to
  • "place" = place key
  • "key" = value key

"onResourceSet"

Triggers when a Resource Value is set.
Variables:

  • "return" = value to set to
  • "resource" = resource key

"onResourceAdd"

Triggers when a Resource Value is added to.
Variables:

  • "return" = value to add
  • "resource" = resource key

"onResourceAtleast"

Triggers when a Resource Value is checked against another value.
Variables:

  • "return" = result of atleast check
  • "resource" = resource key
  • "needed" = value checked against