Modding:Lua/Hooks/NPC
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"
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:
- nil (no interaction response)
- string - the interaction response that should be performed
- array - the interaction response and configuration:
{ <interaction response string>, <interaction response config table (map)> }