Alright, so I am a sorta-noob to lua, and I need help. I need my ent to be removed when its health is at zero, also I need to set it so that when you use it, it keeps using it after the set time ( Two seconds currently ). Any help would be appreciated.
[code]AddCSLuaFile( "cl_init.lua" ) // Make sure clientside
AddCSLuaFile( "shared.lua" ) // and shared scripts are sent.
include('shared.lua')
function ENT:Initialize()
self.Entity:SetModel( "models/Items/ammocrate_ar2.mdl" )
self.Entity:PhysicsInit( SOLID_VPHYSICS ) // Make us work with physics,
self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) // after all, gmod is a physics
self.Entity:SetSolid( SOLID_VPHYSICS ) // Toolbox
self.Entity:SetHealth( 100 )
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self.use = true
end
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( "sent_AmmoCrate" )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Remove()
if Self:Health() = (0) then
Self:Remove()
end
end
function ENT:Use(activator)
if (self.use) then
activator:GiveAmmo( 30, "357" )
activator:GiveAmmo( 30, "Buckshot" )
activator:GiveAmmo( 30, "AR2" )
activator:GiveAmmo( 30, "Pistol" )
activator:GiveAmmo( 30, "SMG1" )
self.use = true
timer.Simple(2.0,usereply,self)
end
end
function usereply(self)
self.use = true
end[/code]
Hi,
Please post this in the correct section(s)
[QUOTE=Catheter Cat;39893585]
[code]
function ENT:Remove()
if Self:Health() = (0) then
Self:Remove()
end
end
[/code][/QUOTE]
ENT:Remove only trickers when the entity is being removed .. not when it take damage.
You need to use the "EntityTakeDamage" hook and a if with your entity's name.
Sorry, you need to Log In to post a reply to this thread.