ENTITY/TriggerOutput

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
 
Line 3: Line 3:
 
|Realm=Server
 
|Realm=Server
 
|Predicted=No
 
|Predicted=No
|Name=TriggerOutput
 
|Parent=ENTITY
 
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 21: Line 19:
 
|desc=The data to give to the output.
 
|desc=The data to give to the output.
 
|default=nil
 
|default=nil
 +
}}
 +
{{Example
 +
|Description=For engine entities you can use {{ClassFunction|Entity|Fire}} to hook outputs.
 +
This example hooks all trigger_teleport
 +
|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)
 +
|Output=When player touches trigger_teleport this will be printed in the console:
 +
<code>Player [1][Player1]    Entity [3][trigger_teleport]</code>
 
}}
 
}}

Latest revision as of 19:17, 12 January 2020

 ENTITY:TriggerOutput( )

Contents

Description

Triggers all outputs stored using ENTITY:StoreOutput.

Arguments

string output

Name of output to fire

Arguments

Entity activator

Activator entity

Arguments

string data=nil

The data to give to the output.

Examples

Example

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

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)

Output:

When player touches trigger_teleport this will be printed in the console: Player [1][Player1] Entity [3][trigger_teleport]
Personal tools
Navigation