two keypress activates ability, how to disable keypress/activation after?
2 replies, posted
Code:
cool = 0
hook.Add("KeyPress", "speedability", function(ply, key)
if key != IN_USE and !ply:KeyDown(IN_SPEED) then return end
if key == IN_USE and ply:KeyDown(IN_SPEED) and ply:Team() == TEAM_LS and cool == 0 then
timer.Simple(0.1, function()
ply:SetWalkSpeed(640)
ply:SetRunSpeed(960)
cool = 1 end) end
if cool == 1 then
timer.Create("resetAbility"..ply:EntIndex(), 8, 1, function()
ply:SetWalkSpeed(160)
ply:SetRunSpeed(240)
cool = 0
end) end
end)
I know this isn't correct but I'm having a brainfart - how do I stop the function from running if the player presses Shift+E again - so that they can't infinitely trigger the speed ability?
hook.Remove("KeyPress", "speedability") after triggering it ?
I believe I've already tried this and ply returned nil by DarkRP, so I switched to setting the state of "cool" instead but because the whole thing is called every keypress (the and cool == 0 statement seems to have no effect) I'm assuming it's overriding the check?
I was under the impression that the state of "cool" would do the same thing as storing the variable in the player entity (behavior wise).
Sorry, you need to Log In to post a reply to this thread.