• Health regeneration on crouch
    9 replies, posted
I wanted to make it so when a player crouches, he slowly regenerates health But when I put this into gmod it says: function arguements expected near and Whats wrong with the script? function myFunc(ply) for k, v in pairs(player.GetAll()) do if v:Alive and v:Crouching then do v:SetHealth(ply:Health() + 1) else return end end timer.Simple( 1, myFunc )
[lua]local HealthRegen = {} HealthRegen.Amount = 1 HealthRegen.GiveDelay = 0.05 HealthRegen.MaxRegen= 100 hook.Add( "Think", "RegenHealth", function() for k,v in pairs( player.GetAll() ) do if v:Alive() and v:Crouching() and v:Health() < HealthRegen.MaxRegen and ( !v.lastregen or v.lastregen < CurTime() - HealthRegen.GiveDelay ) then v.lastregen = CurTime() v:SetHealth( v:Health() + HealthRegen.Amount ) end end end )[/lua] Don't use timers for something like that.
I thought that using CurTime would be more appropriate but I had no idea how to use them, thanks.
attempt to compare nil with number, It keeps giving me this error and as far as I can see, the code is flawless.
Try it again. I updated my post.
attempt to perform arithmetic on a boolean value I wish I had a clue so I could fix it myself :C
Change [lua] ( !v.lastregen or v.lastregen < CurTime() ) - HealthRegen.GiveDelay then [/lua] to [lua] ( !v.lastregen or v.lastregen < CurTime() - HealthRegen.GiveDelay) then [/lua]
Bleh, my bad.
Eh I just remade my own: local RegenerateAmount = 1 local RegenerateTime = 1 local RegenerateMax = 100 local function RegenerateHealth() for k,v in pairs(player.GetAll()) do if v:Alive() and v:Crouching() and v:Health() < RegerateMax then v:SetHealth(math.min(v:Health()+RegenerateAmount,math.max(100,RegenerateMax))) end end timer.Simple(RegenerateTime,RegenerateHealth) end RegenerateHealth()
[QUOTE=vegasx;28035086]I wanted to make it so when a player crouches, he slowly regenerates health But when I put this into gmod it says: function arguements expected near and Whats wrong with the script? function myFunc(ply) for k, v in pairs(player.GetAll()) do if v:Alive and v:Crouching then do v:SetHealth(ply:Health() + 1) else return end end timer.Simple( 1, myFunc )[/QUOTE] v:Alive => v:Alive(), same with v:Crouching [lua] local RegenerateAmount = 1 local RegenerateTime = 1 local RegenerateMax = 100 local function RegenerateHealth() for k,v in pairs(player.GetAll()) do if v:Alive() and v:Crouching() and v:Health() < RegenerateMax then v:SetHealth(math.min(v:Health() + RegenerateAmount, math.max(100,RegenerateMax))) end end timer.Simple(RegenerateTime, RegenerateHealth) end RegenerateHealth() [/lua] Took out typos and nothing else, lol got no time
Sorry, you need to Log In to post a reply to this thread.