ENTITY/Use

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Don't mix activator and caller arguments in example)
 
Line 30: Line 30:
 
{{Example
 
{{Example
 
|Description=Kills any player that uses this entity.
 
|Description=Kills any player that uses this entity.
|Code=function ENT:Use( activator, caller )
+
|Code=function ENT:Use( activator )
  
if IsValid(activator) and activator:IsPlayer() then  
+
if activator:IsPlayer() then  
  
caller:Kill()
+
activator:Kill()
  
 
end
 
end

Latest revision as of 23:53, 14 August 2019

 ENTITY:Use( )

Contents

Description

Called when another entity uses this entity, example would be a player pressing "+use" this entity.

To change how often the function is called, see Entity:SetUseType.

NOTE

This hook only works for "nextbot", "ai" and "anim" scripted entity types.

Arguments

Entity activator

The entity that caused this input. This will usually be the player who pressed their use key

Arguments

Entity caller

The entity responsible for the input. This will typically be the same as activator unless some other entity is acting as a proxy

Arguments

number useType

Use type, see USE_ Enums.

Arguments

number value

Any passed value.

Examples

Example

Kills any player that uses this entity.

function ENT:Use( activator )

	if activator:IsPlayer() then 

		activator:Kill()

	end

end
Personal tools
Navigation