Skip to content

Entity.AddOutput Entity.RemoveOutput Entity.GetOutputs methods

Shararvev edited this page Jun 12, 2023 · 5 revisions

Эта страница доступна на Русском

Discussion: #1911, #2, #1984, #1984 (comment).

AddOutput

integer Entity:AddOutput(string output, function callback, number delay, integer repetitions)

Add a callback function to a specific output. Unlike MetaTarget allows you to add multiple callbacks to one output, and has native builtin delay and repetitions params.

This method does not check if the function has already been added to this entity before, so if you add the same callback twice, it will be run twice! Make sure to add your callback only once or use MetaTarget.

If the value of repetitions is set to greater than 0, then the output will be removed from the engine at some point. However, the Lua function will remain in the entity.

Arguments

string output

  • The output name to hook onto. Different entities have different outputs, you need to look at output names on the Valve Developer Wiki.

function callback

number delay

  • Sets the delay value for the created output. The default value is 0.

integer repetitions

  • Sets the max times to fire value for the created output. The default value is -1. The value 0 is the same as -1.

Returns

integer

  • The output id that was just added, which can later be used in Entity:RemoveOutput.

RemoveOutput

Entity:RemoveOutput(string output, integer id)

Removes a callback previously added with Entity:AddOutput.

This method does not remove the output on the engine side, but only the function on the Lua side. After that, the output is silently ignored. Constantly adding and removing outputs in this way (over a hundred times) will cause a drop in performance. Please don't use this too many times.

Arguments

string output

  • The output name to remove. Different entities have different outputs, you need to look at output names on the Valve Developer Wiki.

integer id

  • The output id previously retrieved with the return of Entity:AddOutput or Entity:GetOutputs.

GetOutputs

table Entity:GetOutputs(string output)

Returns the specified output callbacks for this entity added with Entity:AddOutput. The callbacks can then be removed with Entity:RemoveOutput.

Arguments

string output

  • The output name to retrieve the callbacks from. Different entities have different outputs, you need to look at output names on the Valve Developer Wiki.

Returns

table

  • A table containing the output id and function of all the callbacks for the specified output name.

Output callback

callback(Entity ent, Entity activator, Entity caller, any value)

In most cases, caller is the entity ent itself, but individual outputs can override it. See Keywords notes and special cases. So for example, if you create an OnLockedUse output for func_door, then activator and caller will be a player.

Some entities works incorrectly with outputs, and instead of the player activator will entity ent itself. So for example, if you create an OnOpen or OnClose outputs for func_door, then activator and caller will be this door. This is an engine error.

Arguments

Entity ent

  • The entity on which this output is was fired. Since there can be several nested entities, you need to use this variable to access the entity directly.

Entity activator

  • The entity that started the events sequence. If the button was pressed by a player, then the player will be here. If you manually started button1:Fire("Press") and didn't pass the activator argument, then there will be NULL.

Entity activator

  • The entity that directly fires the output. For example, the button that was pressed.

any value

  • If the output has a generated parameter, this value is passed here as string, number or boolean. For example, momentary_rot_button > Position or math_counter > OutValue. In all other cases, it will be nil.

Clone this wiki locally