Garry's Mod Wiki

Revision Difference

ENTITY:TriggerOutput#525298

<function name="TriggerOutput" parent="ENTITY" type="hook"> <ishook>yes</ishook> <description>Triggers all outputs stored using <page>ENTITY:StoreOutput</page>.</description> <realm>Server</realm> <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>⤶ <code>⤶ local function SetupMapLua()⤶ MapLua = ents.Create( "lua_run" )⤶ MapLua:SetName( "triggerhook" )⤶ MapLua:Spawn()⤶ ⤶ for k, v in pairs( ents.FindByClass( "trigger_teleport" ) ) do⤶ print( v )⤶ 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>⤶