[url]http://wiki.garrysmod.com/page/ENTITY/Touch[/url]
When I put this code in Server , always Error
[CODE]function ENTITY:Touch( entity )
self:EmitSound( "ambient/explosions/explode_" .. math.random( 1, 9 ) .. ".wav" )
self:Remove()
end[/CODE]
[CODE] attempt to index global 'ENTITY' (a nil value)
[/CODE]
How can I use this ?
Please help me
Change "ENTITY" to "ENT".
[QUOTE=AwfulRanger;47130709]Change "ENTITY" to "ENT".[/QUOTE]
[CODE]attempt to index global 'ENT' (a nil value)
[/CODE]
Can you show me your entire code?
[QUOTE=AwfulRanger;47130724]Can you show me your entire code?[/QUOTE]
Just
[CODE]function ENT:Touch( entity )
self:EmitSound("ambient/explosions/explode_" .. math.random( 1, 9 ) .. ".wav", 500, 200)
end[/CODE]
What exactly do you expect this to do?
ENT:Touch is a function that only works on entities. Just calling it anywhere in a piece of code won't work, as ENT is undefined, unless your code is for an entity.
Where are you saving this?
[QUOTE=AwfulRanger;47130764]What exactly do you expect this to do?
ENT:Touch is a function that only works on entities. Just calling it anywhere in a piece of code won't work, as ENT is undefined, unless your code is for an entity.
Where are you saving this?[/QUOTE]
Can you give me a Example?
[QUOTE=weixin0914;47130782]Can you give me a Example?[/QUOTE]
[CODE]AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Example"
ENT.Author = ""
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = ""
ENT.Spawnable = true
ENT.Category = "Examples"
if SERVER then
function ENT:Initialize()
self:SetModel( "models/props_borealis/bluebarrel001.mdl" )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetTrigger( true )
end
function ENT:Touch( entity )
self:EmitSound( "ambient/explosions/explode_" .. math.random( 1, 9 ) .. ".wav", 500, 200 )
end
end
function ENT:Draw()
self:DrawModel()
end[/CODE]
Put that in garrysmod/lua/entities/yourentity/shared.lua
You might want to change Touch to StartTouch so that it doesn't play every frame that you're touching it.
Sorry, you need to Log In to post a reply to this thread.