Bunny Hop

From Pragma
Jump to: navigation, search

Description

Usage: Load the script and bind a key to "+bhop".

Code

local callback
local t
local function hop()
	game.set_action_input(ACTION_JUMP,true)
	t = timer.simple(0.1,function()
		game.set_action_input(ACTION_JUMP,false)
	end,TIMER_USE_REALTIME)
end

cvar.create_concommand("+bhop",function()
	if(callback ~= nil and callback:IsValid()) then return end
	callback = game.add_callback("Think",function()
		local lp = ents.get_local_player()
		if(lp == nil or not lp:IsOnGround() or (t ~= nil and t:IsValid())) then return end
		hop()
	end)
end)
cvar.create_concommand("-bhop",function()
	if(callback ~= nil and callback:IsValid()) then callback:Remove() end
	if(t ~= nil and t:IsValid()) then t:Remove() end
end)