• Player health question
    54 replies, posted
use the [b][url=http://wiki.garrysmod.com/?title=Player.KillSilent]Player.KillSilent [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] or [b][url=http://wiki.garrysmod.com/?title=Player.Kill]Player.Kill [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] functions.
Ahh yes! Exactly what i was looking for but couldn't find, thank you! Taking another crack at this, this should work right? [code] if ply:Health() = 0 then Player:KillSilent( ) [/code] Correct me if i'm wrong though. :/
ply:KillSilent()
That is correct. Although I think it would be better if you did <= instead of = because sometimes health could go into -1 or below if you are experiencing this problem. When the player goes into "crouch death" then can you tell us if it says the player was killed or not.
[QUOTE=Science;29804076]That is correct. Although I think it would be better if you did <= instead of = because sometimes health could go into -1 or below if you are experiencing this problem. When the player goes into "crouch death" then can you tell us if it says the player was killed or not.[/QUOTE] it's not right, Player:KillSilent() is not right but you were correct about the less than or equal to 0, which surprised me
Alright, i corrected the code, but however i add it into the code it seems to break it, no errors or anything just wont work.
Please paste the code here in lua tags
[lua] timer.Create("BleedTimer",3,0,function() for k,v in pairs(player.GetAll()) do if v:Health() < 50 then v:SetHealth(v:Health() - 1) end if v:Health() == 1 then if v:Alive() then v:Kill() end end end end) [/lua] Anddddddddd fixed.
Learning how to tab will benefit you greatly
:3 It's a habit, I'm trying to tab more now but I don't see it useful >.>
Organization is half the battle
C-unit i pmed you it.
Account I put a working code down lol
[lua]timer.Create("BleedTimer", 3, 0, function() for k, v in pairs(player.GetAll()) do if( v:Health() < 50 ) then v:SetHealth(v:Health() - 1) elseif( v:Health() == 1 )then if( v:Alive() ) then v:Kill() end end end end)[/lua]
[QUOTE=jrj996;29806721][lua] timer.Create("BleedTimer",3,0,function() for k,v in pairs(player.GetAll()) do if v:Health() < 50 then v:SetHealth(v:Health() - 1) end if v:Health() == 1 then if v:Alive() then v:Kill() end end end end) [/lua] Anddddddddd fixed.[/QUOTE] My eyes....they burn. Tabbing is invaluable in my eyes. I can't read code that isn't properly indented. Let me help you. [lua] timer.Create("BleedTimer",3,0,function() for k,v in pairs(player.GetAll()) do if v:Health() < 50 then v:SetHealth(v:Health() - 1) end if v:Health() == 1 then if v:Alive() then v:Kill() end end end end) [/lua] Or the shorter version [lua] timer.Create("BleedTimer",3,0,function() for k,v in pairs(player.GetAll()) do if v:Health() < 50 then v:SetHealth(v:Health() - 1) end if v:Health() == 1 then if v:Alive() then v:Kill() end end end end) [/lua] Typically if an if statement only has one line in it i'll put it on the same line as the if.
OH SHIT, that's how people tab! Hurf a fucking durf.
[QUOTE=c-unitV2;29807155][lua]timer.Create("BleedTimer", 3, 0, function() for k, v in pairs(player.GetAll()) do if( v:Health() < 50 ) then v:SetHealth(v:Health() - 1) elseif( v:Health() == 1 )then if( v:Alive() ) then v:Kill() end end end end)[/lua][/QUOTE] That won't work. It will never see the v:Health() == 1. If their health is less than 50 it will always use the first line and won't pass the elseif statement.
Alright, i'll test it out, i kinda just wanted to see what went wrong with mine but thanks
Well dude post it down here.
[QUOTE=Feihc;29807205]That won't work. It will never see the v:Health() == 1. If their health is less than 50 it will always use the first line and won't pass the elseif statement.[/QUOTE] Yeah you're right, didn't even look at it
Nah its fine, mine was just a bunch of mess compared to your's, so somewhere in there i probably messed it up. but thanks for the cod it helped.
Np :P
-SNIP- read wrong page
22 posts of people trying to do simple shit and only one person did it correctly my god what is this section coming to
hell, im just trying to learn.
Sorry, you need to Log In to post a reply to this thread.