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)

The update loop handler. Called once every scriptDelta (defined in the .npctype file) ticks. The dt argument indicates the number of seconds since the last invocation.

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"

Now,"OpenMerchantInterface" and "ScriptPane" are effective.

'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