Simple Script: Double-Press Ducking

Good afternoon, Facepunch!

I was wondering if someone were up to the task of creating a script.

The script should be as follows:

Double-Tap the Duck Key (S in my case), and it will toggle crouching.

If you were to just hold the Duck Key, it won’t toggle.

Thank you in advance.



I would also appreciate a concommand for the delay between keypresses.

Just saying.

…S is your duck key? What’s your backwards key?

are you mentally retarded? He’s saying he wants a script so that if you double tap S it makes you crouch and stay crouched

What? How the hell does asking a question make him retarded?

Not to start a flamewar, but did you actually read the fucking post.

o. im the retard :fuckyou:

how can you be retarded other than mentally?

Retarded Ejaculation.
Retardant Fire Blanket.

Did I say Retarded Ejaculation?

Your post is retarded.

Well, I’m gonna go ahead and help you so…
pressedbackrecently = 0
function GM:KeyPress( ply, key )
if key == IN_DUCK and ply:OnGround() and ply:Alive() then
pressedbackrecently = pressedbackrecently + 1
if pressedbackrecently == 2 then
if ply:Crouching() then // Because everyone start posting about me adding == true…
ply:ConCommand( “+duck” )
ply:ConCommand( “-duck” )
timer.Simple( 1, function()
pressedbackrecently = 0

Why if key == IN_BACK ?
His post clearly asks for the DUCK key, he just has his MAPPED TO S, which is normally back for everyone else.

local last_press = 0

local function KeyPress( pl, key )
  if key == IN_DUCK then
    if CurTime( ) - last_press < .25 then
      RunConsoleCommand( "toggle_duck" )
    last_press = CurTime( )

hook.Add( "KeyPress", "ToggleDuck.KeyPress", KeyPress )

Although it seems to not work on all servers, toggle_duck makes you duck until you jump I believe.

[lua]hook.Add(“KeyPress”, “backwards”, function(ply, key)
if key != IN_DUCK then return end

if ply.lastPress then
	if ply.lastPress + 0.5 &gt; CurTime() then

		ply.lastPress = nil
		ply.lastPress = CurTime()
	ply.lastPress = CurTime()


Ralle made the code, I just edited for this.

Lawl what im confused why the hell is his back key crouch, is his crouch key back? or is it x or z or something? My troll senses are tingling

I edited to code to use IN_DUCK

[editline]26th December 2010[/editline]

That seems hard to understand

if the last press and the new press are within 0.5 seconds of each other, +duck else, -duck