draining health

what the lua for draining health I want it to drain the players health

Something like this.

[lua]
local drainingPlayers = {}
function _R.Player:DrainHealth()
table.insert(drainingPlayers , self)
end

hook.Add(“Think” , “DrainPlayers” , function()
for k , v in pairs(drainingPlayers) do
v:SetHealth(math.floor(Lerp(0.1 , v:Health() , 0)))
end
end )

hook.Add(“PlayerDeath” , “StopDrain” , function(pl)
for k , v in pairs(drainingPlayers) do
if v == pl then
drainingPlayers[k] = nil
end
end
end )
[/lua]

Just as another opinion, wouldn’t it be more effecient to create a timer that performs that action rather then in the Think hook?

Think is usually better

The source code of a timer is basically calculated inside a think hook itself. By doing this, you cut out the middleman.

Jesus christ, if he doesn’t know how to remove health from a player how the fuck can you expect him to understand for loops and tables?

I prefer giving people what I think is the best way to do something. If they don’t understand it, they can read up on it and see how and why I did it.

Your logic is flawed, if the person in question can’t solve a basic issue, you expect them to solve an even more complex one?

You think? When I get stuck on any problem, getting the solution and working backwards is the easiest way to learn it.

You still fail to see the point, he asks for help with a simple problem and you present to him a piece of undocumented code and think you are being helpful. Besides spoonfeeding is not optimal either.

I was a hell of a lot more helpful than you - actually trying to help rather than complaining and offering no alternative. There’s no easy way to explain to him how to drain health without giving him code to do it, so you’re making a pretty invalid point.

His grammar isn’t great meaning he could be foreign which could also mean in his mind “draining” is the same as “taking away” or “subtracting”. In this case your answer is very simple.
[lua]
local Damage = 25
PLAYER:SetHealth(PLAYER:Health() - Damage)
[/lua]

Otherwise if you just want to drain a players health over a period of time then you could do it like this.
[lua]
local DamagePerSecond = 2 --Player will be dealt 2 damage every second.
local LengthOfTime = 10 --Player will suffer damage for 10 seconds.
timer.Create(“Timer”, 1, LengthOfTime, function()
PLAYER:SetHealth(PLAYER:Health() - DamagePerSecond)
end)
PLAYER:SetHealth(PLAYER:Health() - Damage)
[/lua]
Of course you would also have to add a failsafe that would kill the player and stop the timer if it tries to put the players health into the negatives.

You didn’t explain anything to him. Imagine if you ask someone how to do multiplications in brainfuck and I post this:



,>,>++++++++[<------<------>>-]
<<[>[>+>+<<-]>>[<<+>>-]<<<-]
>>>++++++[<++++++++>-],<.>.


Is this enough of an explanation in your opinion? Is this helpful in a way that you can use it for future references? Have you learned how to do multiplactions in brainfuck now? No.

Edit:

This is alot better.

-snip- Seth has informed me im wrong

Yeh i agree alot better.