How i can add a Cooldown? you can spam the command. But i want, that the User must wait 3 seconds before use bind again.
hook.Add( "KeyPress", "lichtschwertthirdperson", function( ply, key )
if ( key == KEY_I ) then
ply:ConCommand( "wos_togglefirstperson" )
end
end )
Aang you should should use something like this:
for k,v in pairs (player.GetAll()) do
if (v.NextCommand || 0 ) < CurTime() then
v.NextCommand = CurTime() +10
end
end
just look to this and maybe try to modify for your needings
I dont check it.
local delay = 3
local shouldOccur = true
hook.Add("Think", "lichtschwertthirdperson", function()
if shouldOccur then
if input.IsKeyDown(KEY_I) then
ply:ConCommand( "wos_togglefirstperson" )
shouldOccur = false
timer.Simple( delay, function() shouldOccur = true end )
end
end
end)
Probably not the most effective solution but it should work.
it dont work?
https://files.facepunch.com/forum/upload/328642/9631d915-11a5-41d7-b479-d038496ff3f8/grafik.png
-- http://wiki.garrysmod.com/page/GM/PlayerButtonDown
PlayerButtonDown hook = function(ply, button)
if (
button equals KEY_ENUM or -- http://wiki.garrysmod.com/page/Enums/KEY
(ply.NextKeyPress or 0) is smaller than or equal to curtime -- http://wiki.garrysmod.com/page/Global/CurTime
) then
ply:runconcommand("wos_togglefirstperson") -- http://wiki.garrysmod.com/page/Player/ConCommand
ply.NextKeyPress = curtime + delay
end
end)
local CoolDown = 0
hook.Add( "KeyPress", "lichtschwertthirdperson", function( ply, key )
if CoolDown > CurTime() then return end
if ( key == KEY_I ) then
ply:ConCommand( "wos_togglefirstperson" )
CoolDown = CurTime() + 3
end
end )
That gives a cooldown of 3 seconds.
It worked thanks.
Sorry, you need to Log In to post a reply to this thread.