water damage

How do I make a gamemode say, if someone touches the water, they will lose hp every second?

And where would I put it? shared, init?

[lua]hook.Add(“Think”,“CheckWaterDamage”,function()
for _,v in ipairs(player.GetAll()) do
if v:WaterLevel() > 0 the
v:SetHealth( math.Clamp( v:Health() - 10, 0, 100000 ) )
end
end
end)[/lua]

That does it every tick, and I’m lazy so you can figure out how to make it happen every second. It would go in init.

What is every tick? o_O ; I am noob xD

Every frame, roughly.

Doesn’t seem to work on my gofish server, it makes no one to be able to join fishmen team and gives them weapons. =/

Think is called every 1/60th of a second.

Couldn’t that be really laggy?

Replace “the” with “then”…

doesn’t work still D:
players go unassigned and the gamoemode doesnt work

post the errors you get

Couldn’t include file ‘gofish2/gamemode/cl_init.lua’ (File not found)



********** COULDN’T LOAD GAMEMODE!! **********



There was a problem opening the gamemode file ‘gofish2/gamemode/cl_init.lua’

Don’t know why it says cl_init when I’m putting the code in init.lua
Once I remove the code, its all good.

http://en.wikipedia.org/wiki/Tick !

Nah joking, it is basically some sort of Think but used to calculate stuff, send stuff to the client etc…

Use TakeDamage() or TakeDamageInfo(). Using SetHealth() completely bypasses every damage event in the engine. EntityTakeDamage, etc won’t be called.

Try this

[lua]
hook.Add(“Think”,“CheckWaterDamage”,function()
for _,v in ipairs(player.GetAll()) do
if not v.hurtlastsecond then
if v:WaterLevel() > 0 then
v:TakeDamage(5,v,v)
v.hurtlastsecond = true
timer.Simple(1, function()
v.hurtlastsecond = false
end)
end
end
end
end)
[/lua]

EDIT - My tabbing is aweful.

Your spelling is too.