[LUA]
function ENT:Use( activator, caller )
self.Entity:Remove()
if (activator:IsPlayer() ) then
local DamagePerSecond = 2
local LengthOfTime = 50
timer.Create("Timer", 1, LengthOfTime, function()
activator:SetHealth(activator:Health() - DamagePerSecond)
end)
activator:SetHealth(activator:Health() - DamagePerSecond)
end
end
[/LUA]
I'm trying to make it so after 50 seconds the player runs out of health and dies. When I get to 0 health it looks like I'm crouching and I don't die. I'm not getting errors either.
Use [b][url=wiki.garrysmod.com/?title=Entity.TakeDamageInfo]Entity.TakeDamageInfo [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] instead so you have full control on the damage. You can even use it to deal poison damage from poison headcrabs.
Can you give me a example of how to use this? I'm a little confused.
[LUA]function ENT:Use( activator, caller )
if (activator:IsPlayer() ) then
self:Remove() -- self == self.Entity
local DamagePerSecond = 2
local LengthOfTime = 50
local dmginfo = DamageInfo()
dmginfo:SetDamage(DamagePerSecond) -- How much damage?
dmginfo:SetAttacker(self) -- Who/what is the source of the damage?
dmginfo:SetInflictor(self) -- What actually inflicted it?
dmginfo:SetDamageType(DMG_POISON)
timer.Create("Timer", 1, LengthOfTime, function(activator)
if not activator:Alive() then timer.Remove("Timer") end
activator:TakeDamageInfo(dmginfo)
end, activator)
activator:TakeDamageInfo(dmginfo)
end
end[/LUA]
Change the damage type to anything you want, this also lacks sound effects and all that good stuff.
Ah, I was pretty close. Thanks for the help!
Sorry, you need to Log In to post a reply to this thread.