can someone make a script where if you swim for say 40 seconds you die from drowning due to lack of swimming energy?
I made this in 10 mins hope it helps!
[lua]
local ply = LocalPlayer()
local tired = 0
timer.Create("CheckWaterLevel", 1, 0, function()
if ply:WaterLevel() > 1 and ply:Alive() then
tired = tired + 1
end
if tired >= 10 then // change the 10 to the time you want in Seconds
ply:ConCommand("kill")
tired = 0
end
end)
hook.Add("HUDPaint", "PaintHUD", function()
if !ply:Alive() then return end
draw.SimpleTextOutlined(tostring(tired), "TargetID", 10,0, Color(255,255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, Color(0,0,0,255) ) // Do whatever you want to this
end)
/* Do whatever you want to this it was for testing
concommand.Add("DestroyTimer", function()
timer.Destroy("CheckWaterLevel")
end)
*/
[/lua]
Well I do seem to be noobish enough on lua to not know how to install it :P (im used to CSS eventscripts) But I tried putting the lua file in lua/autorun/server and it wont work?
This is a clientside code so you would place it inside of lua/autorun/client and it should work :P
[QUOTE=Killklli;35759818]Well I do seem to be noobish enough on lua to not know how to install it :P (im used to CSS eventscripts) But I tried putting the lua file in lua/autorun/server and it wont work?[/QUOTE]
The use of the 'LocalPlayer' function is an indicator that this script is clientside. Put it in /lua/autorun/client and you should be set.
[QUOTE=wizardsbane;35759943]The use of the 'LocalPlayer' function is an indicator that this script is clientside. Put it in /lua/autorun/client and you should be set.[/QUOTE]
:D
its not working. :(
[QUOTE=Killklli;35760736]its not working. :([/QUOTE]
It has to be in a file type called ".lua" then you have to place in lua/autorun/client.
I got that correct from the start at least. So thats not the problem..... Its named waterdamage with the extention .lua
[lua]
local tired = 0
timer.Create("CheckWaterLevel", 1, 0, function()
local ply = LocalPlayer()
if ply:WaterLevel() > 1 and ply:Alive() then
tired = tired + 1
end
if tired >= 10 then // change the 10 to the time you want in Seconds
ply:ConCommand("kill")
tired = 0
end
end)
hook.Add("HUDPaint", "PaintHUD", function()
if !LocalPlayer():Alive() then return end
draw.SimpleTextOutlined(tostring(tired), "TargetID", 10,0, Color(255,255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, Color(0,0,0,255) ) // Do whatever you want to this
end)
/* Do whatever you want to this it was for testing
concommand.Add("DestroyTimer", function()
timer.Destroy("CheckWaterLevel")
end)
*/
[/lua]
Fixed it.
nope. still didnt work.
You arn't placing it correctly. I just put mine inside of lua/autorun/client and it works perfectly.
I have it exactly as you say. [url]http://imageshack.us/f/835/installv.png/[/url]
Here's a simpler one if you like:
[lua]
local water_start_time = 0
local water_drown_time = 40 --Time till drown
hook.Add("Think", "water_drown_think", function()
if LocalPlayer():Alive() and LocalPlayer():WaterLevel() >= 2 then
if water_start_time == 0 then
water_start_time = CurTime()
end
if CurTime() - water_start_time >= water_drown_time then
LocalPlayer():ConCommand("kill") --Only way to kill on clienside I think?
end
else
water_start_time = 0
end
end)
[/lua]
If that doesn't work, it must be something on your side.
[lua]local tm = nil
local ply = nil
local plys = nil
function GM:Tick()
-- three cheers for micro-optimizations
plys = player.GetAll()
for i= 1, #plys do
ply = plys[i]
tm = ply:Team()
if tm == TEAM_GAME and ply:Alive() then --TEAM_GAME is the players, i have another team (TEAM_SPEC) for spectators
-- Drowning
if ply:WaterLevel() == 3 then
if ply:IsOnFire() then
ply:Extinguish()
end
if ply.drowning then
if ply.drowning < CurTime() then
local dmginfo = DamageInfo()
dmginfo:SetDamage(15)
dmginfo:SetDamageType(DMG_DROWN)
dmginfo:SetAttacker(GetWorldEntity())
dmginfo:SetInflictor(GetWorldEntity())
dmginfo:SetDamageForce(Vector(0,0,1))
ply:TakeDamageInfo(dmginfo)
-- have started drowning properly
ply.drowning = CurTime() + 1
end
else
-- will start drowning soon
ply.drowning = CurTime() + 8
end
else
ply.drowning = nil
end
end
end
end[/lua]
the only thing that makes sense is that it would be something on my side then cause its still not working I even tried making it an addon.
[editline]29th April 2012[/editline]
I was able to come up with something that worked by looking around. Is there anyway I can make it so it dosent apply when you are in a vehicle.
[CODE]hook.Add( "Think", "LimitedBreath", function()
for k, v in pairs( player.GetAll() ) do
if v:Alive() then
if v:WaterLevel() >= 1 then
if v.NextHurt < CurTime() then
v:TakeDamage( 100 )
v:EmitSound( Sound( "player/pl_drown" .. math.random( 1, 3 ) .. ".wav" ) )
v:ViewPunch( Vector( math.Rand( -5, 5 ), math.Rand( -5, 5 ), math.Rand( -10,
10 ) ) )
v.NextHurt = CurTime() + 1
end
else
v.NextHurt = CurTime() + 10
end
end
end
end )[/CODE]
Sorry, you need to Log In to post a reply to this thread.