r/GLua • u/Heeheewhatelse • Feb 27 '21
if 0 hp then kill (NEED HELP)
hey, i'm just doing an addon and the player loose 10 hp every 5seconde, that's pretty easy.
but when he reached 0hp, the player don't die...
i try something like:
function SWEP:Think()
if self:Health < 0
self:kill ()
end)
what can i do ???
3
Upvotes
2
u/AdamNejm Feb 27 '21
Here
selfrefers to the scripted weapon, not the player.Weapons owner is stored in the
Ownerkey, so to access it you doself.Owner.Additionally your code has a syntax error in the if statement as youre trying to call a method without
()or access the table with:, whatever you're trying to do right now won't work.Also keep in mind that original player method used to kill him is called
Kill, notkill. It's case sensitive.1
u/[deleted] Feb 27 '21
If you want to gradually reduce the health of a player, use Entity:TakeDamage(). I'm assuming you're doing something like
Entity:SetHealth( Entity:Health() - 10 )which is why the player isn't dying when their health reaches 0. If you do this you shouldn't need the code you posted at all. There's a lot of things wrong with that code but I'm assuming you just wrote it quickly from memory and it doesn't actually look like that.