Modding:Lua/Hooks/NPC

From Starbounder - Starbound Wiki
Jump to: navigation, search

Description

These NPC hooks are stubs for global functions NPC scripts can define, which will be called by C++. Documentation for it was removed from the assets, but an old and outdated (2015) version can be found here: https://pastebin.com/GpuGV3Ms These functions are currently (2017 april) used in the /assets/npcs/bmain.lua script.

Hooks

init()

Called when the NPC is added to the world.

update(dt)

Update loop handler. Called once every `scriptDelta` (as defined in *.npctype) game ticks

damage(args)

Called after the NPC has taken damage.
'args' is a map of info about the damage, structured as:

{
sourceId = <entity id of entity that caused the damage>,
damage = <numeric amount of damage that was taken>,
sourceDamage = <numeric amount of damage that was originally dealt>,
sourceKind = <string kind of damage being applied, as defined in "damageKind" value in a *.projectile config>
}

Note that "sourceDamage" can be higher than "damage" if - for instance - some damage was blocked by a shield.

interact(args)

Called when the NPC is interacted with.
Available interaction responses are:

   "OpenCockpitInterface"
   "SitDown"
   "OpenCraftingInterface"
   "OpenCookingInterface"
   "OpenTechInterface"
   "Teleport"
   "OpenSongbookInterface"
   "OpenNpcCraftingInterface"
   "OpenTech3DPrinterDialog"
   "ShowPopup"
   "ScriptConsole"

'args' - Map of interaction event arguments:

   {
     sourceId = <Entity id of the entity interacting with this NPC>
     sourcePosition = <The {x,y} position of the interacting entity>
   }

Returns:

  1. nil (no interaction response)
  2. string - the interaction response that should be performed
  3. array - the interaction response and configuration:
   {
      <interaction response string>,
      <interaction response config table (map)>
   }

Quick Navigation

Quick Navigation