creating a concommand keybind

I don’t care much for how this parachute enters skydiving mode when shift is pressed, since it means I can’t use it for running. How can I change the code to either make it activate with a different key (I prefer capslock/suit zoom), or to create a concommand or something that I can bind a key to to activate the parachute. Here’s the part of the code I think is relevant:


hook.Add("KeyPress","Openandreleasechute",
function(ply,key)
	if (key==131072) then 
		if not ply.HasChute then return end
		if not ply.ChuteThink then ply.ChuteThink=CurTime() end
		if not (ply.ChuteThink<CurTime()) then return end
		ply.ChuteThink=CurTime()+1
		if not ply.chuteragdoll then
			--Make Ragdoll
			
			local phys=ply:GetPhysicsObject()
			local cvel=phys:GetVelocity()
			local ragdoll = ents.Create( "prop_ragdoll" ) --Thanks Ulyssus for showing me how to mimic the ulx ragdoll command.
			ragdoll:SetPos( ply:GetPos() )
			ragdoll:SetModel( ply:GetModel() )
			ragdoll:SetAngles(Angle(90,ply:GetAngles().y,0))
			ragdoll:Spawn()
			ragdoll:Activate()
			ragdoll.IsChuteDoll=true
			local curweps={}
			for k, v in pairs(ply:GetWeapons()) do
				table.insert(curweps,v:GetClass())
			end
			ply.CurWeaponsP=curweps
			ply:SetParent( ragdoll )
			ply:StripWeapons()
			ply:Spectate( OBS_MODE_CHASE )
			ply:SpectateEntity( ragdoll )
			ply.chuteragdoll = ragdoll
			ragdoll:GetPhysicsObject():ApplyForceCenter(cvel*500000)
		else
			if ply.ChuteOpen then
				--cut the line
				chute_make_Normal(ply)
				return
			end
		
			local chute=ents.Create("prop_physics")
			chute:SetPos(ply:GetPos()+Vector(0,0,100))
			chute:SetAngles(Angle(0,ply:GetAngles().y,0))
			chute:SetModel("models/parachute/chute.mdl")
			chute.IsChute=true
			chute:Spawn()
			ply.ChuteOpen=true
			ply.Chute=chute
			ply.chuteragdoll:EmitSound(Sound("ambient/fire/mtov_flame2.wav"),100,100)
			local chutelocal, chutelocal2 = chute:GetRight()*40+chute:GetLocalPos(), chute:GetRight()*-40+chute:GetLocalPos()
			constraint.Rope( ply.chuteragdoll, chute, 7, 0, Vector(0,0,0), Vector(100,0,-20), 200, 0, 0, 2, "cable/rope", 0 )
			constraint.Rope( ply.chuteragdoll, chute, 5, 0, Vector(0,0,0), Vector(-100,0, -20), 200, 0, 0, 2, "cable/rope", 0 )
		end
	end
end)


"if (key==131072) then " find the key value to capslock, shift is 131072, and change that to the caps lock value



SHARED | 0000000000000001 | 00000000000000000000000001 | ATTACK
SHARED | 0000000000000002 | 00000000000000000000000010 | JUMP
SHARED | 0000000000000004 | 00000000000000000000000100 | DUCK
SHARED | 0000000000000008 | 00000000000000000000001000 | FORWARD
SHARED | 0000000000000016 | 00000000000000000000010000 | BACK
SHARED | 0000000000000032 | 00000000000000000000100000 | USE
SHARED | 0000000000000064 | 00000000000000000001000000 | CANCEL
SHARED | 0000000000000128 | 00000000000000000010000000 | LEFT
SHARED | 0000000000000256 | 00000000000000000100000000 | RIGHT
SHARED | 0000000000000512 | 00000000000000001000000000 | MOVELEFT
SHARED | 0000000000001024 | 00000000000000010000000000 | MOVERIGHT
SHARED | 0000000000002048 | 00000000000000100000000000 | ATTACK2
SHARED | 0000000000004096 | 00000000000001000000000000 | RUN
SHARED | 0000000000008192 | 00000000000010000000000000 | RELOAD
SHARED | 0000000000016384 | 00000000000100000000000000 | ALT1
SHARED | 0000000000032768 | 00000000001000000000000000 | ALT2
SHARED | 0000000000065536 | 00000000010000000000000000 | SCORE
SHARED | 0000000000131072 | 00000000100000000000000000 | SPEED
SHARED | 0000000000262144 | 00000001000000000000000000 | WALK
SHARED | 0000000000524288 | 00000010000000000000000000 | ZOOM
SHARED | 0000000001048576 | 00000100000000000000000000 | WEAPON1
SHARED | 0000000002097152 | 00001000000000000000000000 | WEAPON2
SHARED | 0000000004194304 | 00010000000000000000000000 | BULLRUSH
SHARED | 0000000008388608 | 00100000000000000000000000 | GRENADE1
SHARED | 0000000016777216 | 01000000000000000000000000 | GRENADE2


Pretty sure caps lock isnt in that list, and the function he is using is for IN_KEYS which the above list is of, to use any of these change the number to say, IN_ZOOM.

Edit:

You can also make a clientside hook and edit that script, theres a clientside function that allows basically every key to be used, say a clientside Think hook with **[Input.IsKeyDown

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Input.IsKeyDown)** in it. I’ll do an example

Im going to use a think hook, which is probably wrong but will work.
Clientside
[lua]
local last = 0 – This is so the command only happens once per second

hook.Add(“Think”, “uniquezor”, function()
if( CurTime() > last + 1 and input.IsKeyDown(KEY_CAPSLOCK)) then
last = CurTime()
RunConsoleCommand(“parachute”)
end
end)
[/lua]

So i suppose you could make a serverside consolecommand for deploying parachute and change the LocalPlayer():ChatPrint() to a line that runs a console command.

** If you use the above change the original code you gave us to, this is all untested so backup the old code first **

Server side or wherever the code you gave us came from
[lua]concommand.Add(“parachute”,
function(ply)
if not ply.HasChute then return end
if not ply.ChuteThink then ply.ChuteThink=CurTime() end
if not (ply.ChuteThink<CurTime()) then return end
ply.ChuteThink=CurTime()+1
if not ply.chuteragdoll then
–Make Ragdoll

		local phys=ply:GetPhysicsObject()
		local cvel=phys:GetVelocity()
		local ragdoll = ents.Create( "prop_ragdoll" ) --Thanks Ulyssus for showing me how to mimic the ulx ragdoll command.
		ragdoll:SetPos( ply:GetPos() )
		ragdoll:SetModel( ply:GetModel() )
		ragdoll:SetAngles(Angle(90,ply:GetAngles().y,0))
		ragdoll:Spawn()
		ragdoll:Activate()
		ragdoll.IsChuteDoll=true
		local curweps={}
		for k, v in pairs(ply:GetWeapons()) do
			table.insert(curweps,v:GetClass())
		end
		ply.CurWeaponsP=curweps
		ply:SetParent( ragdoll )
		ply:StripWeapons()
		ply:Spectate( OBS_MODE_CHASE )
		ply:SpectateEntity( ragdoll )
		ply.chuteragdoll = ragdoll
		ragdoll:GetPhysicsObject():ApplyForceCenter(cvel*500000)
	else
		if ply.ChuteOpen then
			--cut the line
			chute_make_Normal(ply)
			return
		end
	
		local chute=ents.Create("prop_physics")
		chute:SetPos(ply:GetPos()+Vector(0,0,100))
		chute:SetAngles(Angle(0,ply:GetAngles().y,0))
		chute:SetModel("models/parachute/chute.mdl")
		chute.IsChute=true
		chute:Spawn()
		ply.ChuteOpen=true
		ply.Chute=chute
		ply.chuteragdoll:EmitSound(Sound("ambient/fire/mtov_flame2.wav"),100,100)
		local chutelocal, chutelocal2 = chute:GetRight()*40+chute:GetLocalPos(), chute:GetRight()*-40+chute:GetLocalPos()
		constraint.Rope( ply.chuteragdoll, chute, 7, 0, Vector(0,0,0), Vector(100,0,-20), 200, 0, 0, 2, "cable/rope", 0 )
		constraint.Rope( ply.chuteragdoll, chute, 5, 0, Vector(0,0,0), Vector(-100,0, -20), 200, 0, 0, 2, "cable/rope", 0 )
	end

end)
[/lua]

Both the serverside hook and replacing the key number 131072 with 524288 worked, but I’ll stick with the script, since rebinding a concommand in the console is simpler for me than editing the code if I want a different key.

I’m not sure whether the lua is clientside or serverside If it’s any help, it was in lua/autorun, and is called ParachuteSource.lua

It’s the parachute v2.2 made by Thegrb93.

The code you gave us was serverside