Skip to content

Commit 2b4a7af

Browse files
committed
Add precision_align_snap_physgun
1 parent 4c4407e commit 2b4a7af

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if SERVER then
2+
local function RoundAngleAxis(SnapAngles, Angles, Axis)
3+
local Value = Angles[Axis]
4+
local NewValue = Value
5+
6+
NewValue = math.Round(Value / SnapAngles) * SnapAngles
7+
8+
Angles[Axis] = NewValue
9+
return NewValue ~= Value
10+
end
11+
12+
hook.Add("OnPhysgunFreeze", "PA_FixPhysgunRotationInaccuracy", function(_, PhysObj, _, Player)
13+
if not Player:KeyDown(IN_SPEED) then return end
14+
local ShouldSnap = Player:GetInfo("precision_align_snap_physgun")
15+
if ShouldSnap == 0 then return end
16+
17+
local SnapAngles = Player:GetInfo("gm_snapangles")
18+
local Angles = PhysObj:GetAngles()
19+
-- This was for notifications, but those got kind of annoying.
20+
-- local Changed = false
21+
--[[if]] RoundAngleAxis(SnapAngles, Angles, 1) -- then Changed = true end
22+
--[[if]] RoundAngleAxis(SnapAngles, Angles, 2) -- then Changed = true end
23+
--[[if]] RoundAngleAxis(SnapAngles, Angles, 3) -- then Changed = true end
24+
PhysObj:SetAngles(Angles)
25+
end)
26+
else
27+
CreateClientConVar("precision_align_snap_physgun", "1", true, true, "When enabled, this forces physgun snapping to always be 100% accurate to your desired gm_snapangles.", 0, 1)
28+
end

0 commit comments

Comments
 (0)