Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function EnableDiabloView(b)
- if not b then
- hook.Remove("CalcView", "diablo")
- hook.Remove("ShouldDrawLocalPlayer", "diablo")
- hook.Remove("CreateMove", "diablo")
- hook.Remove("PreDrawOpaqueRenderables", "diablo")
- if vgui.CursorVisible() then
- gui.EnableScreenClicker(false)
- end
- return
- end
- local params = {origin = Vector(), angles = Angle(), fov = 1}
- hook.Add("CalcView", "diablo", function(ply, pos, ang, fov)
- local size = ply:GetModelScale() or 1
- pos = ply:GetPos() + Vector(0, 0, size * 72)
- local origin = pos + Vector(1, 1, 1) * 500
- local dir = (pos - origin)
- params.origin = origin
- params.angles = dir:Angle()
- params.znear = 100
- params.zfar = 10000
- params.fov = 30
- local normal = Vector(0, 0, -1)
- local distance = normal:Dot(Vector(pos.x, pos.y, ply:GetPos().z + (72 * size)))
- render.EnableClipping(true)
- render.PushCustomClipPlane(normal, distance)
- return params
- end)
- hook.Add("CreateMove", "diablo", function(cmd)
- local ply = LocalPlayer()
- -- this tries to trace from the player to camera and then use the hitpos as origin
- -- but when the trace hits the aim angles become wrong
- --[[
- local pos = ply:EyePos()
- local origin = params.origin
- local data = util.TraceLine({start = pos, endpos = origin, filter = {ply}})
- if data.Hit then
- origin = data.HitPos
- end
- --local dir = util.AimVector(params.angles, params.fov, gui.MouseX(), gui.MouseY(), ScrW(), ScrH())
- local dir = pace.LPCameraScreenToVector(gui.MouseX(), gui.MouseY(), ScrW(), ScrH(), params.angles, math.rad(params.fov))
- pos = util.TraceLine({start = origin, endpos = origin + (dir * 32000)}).HitPos]]
- local dir = pace.LPCameraScreenToVector(gui.MouseX(), gui.MouseY(), ScrW(), ScrH(), params.angles, math.rad(params.fov))
- local pos = util.IntersectRayWithPlane(params.origin, dir * 32000, util.TraceLine({start = ply:GetPos(), endpos = ply:GetPos() + physenv.GetGravity() * 32000}).HitPos, Vector(0, 0, 1))
- gui.EnableScreenClicker(true)
- if pos then
- local angles = (pos - ply:EyePos()):Angle()
- if ply:KeyDown(IN_FORWARD) then
- angles.p = 0
- end
- if input.IsMouseDown(MOUSE_LEFT) then
- cmd:SetButtons(bit.bor(cmd:GetButtons(), IN_ATTACK))
- end
- if input.IsMouseDown(MOUSE_RIGHT) then
- cmd:SetButtons(bit.bor(cmd:GetButtons(), IN_ATTACK2))
- end
- cmd:SetViewAngles(angles)
- end
- end)
- hook.Add("PreDrawOpaqueRenderables", "diablo", function()
- render.PopCustomClipPlane()
- render.EnableClipping(false)
- end)
- hook.Add("ShouldDrawLocalPlayer", "diablo", function()
- return true
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement