Garry's Mod Wiki

ENTITY:TriggerOutput

  ENTITY:TriggerOutput( string output, Entity activator, string data = nil )

Description

Triggers all outputs stored using ENTITY:StoreOutput.

Arguments

1 string output
Name of output to fire
2 Entity activator
Activator entity
3 string data = nil
The data to give to the output.

Example

Creates a brush entity that will run OnEndTouch outputs when compiled into a map

ENT.Type = "brush" ENT.Base = "base_brush" function ENT:Initialize() self:SetSolid(SOLID_BBOX) self:SetTrigger(true) -- Generates EndTouch and StartTouch callbacks end function ENT:KeyValue( k, v ) -- Store 'OnEndTouch' outputs for map created entities if ( k == "OnEndTouch" ) then self:StoreOutput( k, v ) end end function ENT:EndTouch(ent) -- Trigger all stored outputs self:TriggerOutput("OnEndTouch", ent) end

Example

For engine entities you can use Entity:Fire to hook outputs. This example hooks all trigger_teleport.

ACTIVATOR / CALLER / TRIGGER_PLAYER globals are only available during execution, they are unset directly afterwards.
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 )
Output: When player touches trigger_teleport this will be printed in the console:
Player [1][Player1] Entity [3][trigger_teleport]