Skip to content

Instantly share code, notes, and snippets.

@Python1320
Last active December 18, 2015 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Python1320/35ac27802a31fd67d732 to your computer and use it in GitHub Desktop.
Save Python1320/35ac27802a31fd67d732 to your computer and use it in GitHub Desktop.
Try to fix crouch spazzing in gmod
-- Still spazzes
--- when pushing against roof
--- When getting off grund
local ppos = Vector()
local view = { }
if GetConVar "developer":GetInt() > 0 then
RunConsoleCommand("contimes", "55")
end
local prev = false
local waitforpressed_to_end
local waitfor_waskeydown_to_end
hook.Add("CalcView", "a", function(pl, pos, angles, fov)
local ground = pl:IsOnGround()
if pl:KeyDown(IN_WALK) then
hook.Remove("CalcView", "a")
MsgN"END"
return
end
local down = pl:KeyDown(IN_DUCK)
local pressed = pl:KeyPressed(IN_DUCK)
local waskeydown = pl:KeyDownLast(IN_DUCK)
ppos = pos
view.origin = pos
view.angles = angles
view.fov = fov
if prev ~= down then
prev = down
if down then
waitforpressed_to_end = true
else
waitfor_waskeydown_to_end = true
end
end
if waitforpressed_to_end and not pressed then
waitforpressed_to_end = false
end
if waitfor_waskeydown_to_end and not waskeydown then
waitfor_waskeydown_to_end = false
end
local situation = waitforpressed_to_end or waitfor_waskeydown_to_end
print(('%s %s %s %s %s %s %s %s %3.3f %3.3f %3.3f'):format(
pl:Crouching() and 'C' or '_',
down and 'C' or '_',
pressed and 'X' or '_',
waskeydown and 'X' or '_',
waitforpressed_to_end and 'W1' or '__',
waitfor_waskeydown_to_end and 'W2' or '__',
ground and 'G' or '_',
situation and (prev and 'U' or 'D') or '|',
pl:GetPos().z-pos.z,
pos.z,
(pos-ppos).z
))
if ground then
return
end
if situation then
if prev then
pos.z = pos.z + 36
else
pos.z = pos.z - 36
end
end
return view
end)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment