Garry's Mod Wiki

Revision Difference

ENTITY:TriggerOutput#547127

<function name="TriggerOutput" parent="ENTITY" type="hook">⤶ <cat>classfunc</cat>⤶ <function name="TriggerOutput" parent="Entity" type="classfunc">⤶ <description>Triggers all outputs stored using <page>ENTITY:StoreOutput</page>. <note>ACTIVATOR / CALLER / TRIGGER_PLAYER globals are only available during execution, they are unset directly afterwards.⤶ https://github.com/Facepunch/garrysmod/blob/1a50a5f72f61e6cb714ed50ebccd33a01b4b6ecc/garrysmod/gamemodes/base/entities/entities/lua_run.lua#L38</note>⤶ </description> <realm>Server</realm> <file line="105-L123">gamemodes/base/entities/entities/base_entity/outputs.lua</file>⤶ <predicted>No</predicted> <args> <arg name="output" type="string">Name of output to fire</arg> <arg name="activator" type="Entity">Activator entity</arg> <arg name="data" type="string" default="nil">The data to give to the output.</arg> </args> </function> <example> <description> For engine entities you can use <page>Entity:Fire</page> to hook outputs. This example hooks all `trigger_teleport`. </description>⤶ <note>ACTIVATOR / CALLER / TRIGGER_PLAYER globals are only available during execution, they are unset directly afterwards.</note> ⤶ </description>⤶ <code> local function SetupMapLua() local MapLua = ents.Create( "lua_run" ) MapLua:SetName( "triggerhook" ) MapLua:Spawn() for _, v in ipairs( ents.FindByClass( "trigger_teleport" ) ) do v:Fire( "AddOutput", "OnStartTouch triggerhook:RunPassedCode:hook.Run( 'OnTeleport' ):0:-1" ) end end hook.Add( "InitPostEntity", "SetupMapLua", SetupMapLua ) hook.Add( "PostCleanupMap", "SetupMapLua", SetupMapLua ) hook.Add( "OnTeleport", "TestTeleportHook", function() local activator, caller = ACTIVATOR, CALLER print( activator, caller ) end ) </code> <output> When player touches trigger_teleport this will be printed in the console: ``` Player [1][Player1] Entity [3][trigger_teleport] ``` </output> </example>