Fixing UndisguiseSilent (how did I not notice that?) and 3rd person crashing game on death.
parent
dde7e30d6d
commit
6c636543ad
|
@ -30,6 +30,8 @@
|
||||||
hook.Add("CalcView", "Disguiser.ThirdPersonCalcView", function(player, pos, angles, fov)
|
hook.Add("CalcView", "Disguiser.ThirdPersonCalcView", function(player, pos, angles, fov)
|
||||||
local smoothscale = 1
|
local smoothscale = 1
|
||||||
|
|
||||||
|
if !IsValid(player) then return end
|
||||||
|
|
||||||
if player:GetNetworkedBool("thirdperson") then
|
if player:GetNetworkedBool("thirdperson") then
|
||||||
angles = player:GetAimVector():Angle()
|
angles = player:GetAimVector():Angle()
|
||||||
|
|
||||||
|
@ -54,7 +56,6 @@ hook.Add("CalcView", "Disguiser.ThirdPersonCalcView", function(player, pos, angl
|
||||||
end
|
end
|
||||||
|
|
||||||
// smoothing - approaches a bit more slowly to the actual target position
|
// smoothing - approaches a bit more slowly to the actual target position
|
||||||
pos = targetpos
|
|
||||||
pos = Vector(
|
pos = Vector(
|
||||||
math.Approach(pos.x, targetpos.x, math.abs(targetpos.x - pos.x) * smoothscale),
|
math.Approach(pos.x, targetpos.x, math.abs(targetpos.x - pos.x) * smoothscale),
|
||||||
math.Approach(pos.y, targetpos.y, math.abs(targetpos.y - pos.y) * smoothscale),
|
math.Approach(pos.y, targetpos.y, math.abs(targetpos.y - pos.y) * smoothscale),
|
||||||
|
@ -92,40 +93,42 @@ end)
|
||||||
|
|
||||||
hook.Add("HUDPaint", "Disguiser.ThirdPersonHUDPaint", function()
|
hook.Add("HUDPaint", "Disguiser.ThirdPersonHUDPaint", function()
|
||||||
local player = LocalPlayer()
|
local player = LocalPlayer()
|
||||||
if !player:GetNetworkedBool("thirdperson") then
|
if !IsValid(player) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
// trace from muzzle to hit pos
|
if player:GetNetworkedBool("thirdperson") && player:Alive() then
|
||||||
local t = {}
|
// trace from muzzle to hit pos
|
||||||
t.start = player:GetShootPos()
|
local t = {}
|
||||||
t.endpos = t.start + player:GetAimVector() * 9000
|
t.start = player:GetShootPos()
|
||||||
t.filter = player
|
t.endpos = t.start + player:GetAimVector() * 9000
|
||||||
local tr = util.TraceLine(t)
|
t.filter = player
|
||||||
local pos = tr.HitPos:ToScreen()
|
local tr = util.TraceLine(t)
|
||||||
local fraction = math.min((tr.HitPos - t.start):Length(), 1024) / 1024
|
local pos = tr.HitPos:ToScreen()
|
||||||
local size = 10 + 20 * (1.0 - fraction)
|
local fraction = math.min((tr.HitPos - t.start):Length(), 1024) / 1024
|
||||||
local offset = size * 0.5
|
local size = 10 + 20 * (1.0 - fraction)
|
||||||
local offset2 = offset - (size * 0.1)
|
local offset = size * 0.5
|
||||||
local hit = tr.HitNonWorld
|
local offset2 = offset - (size * 0.1)
|
||||||
|
local hit = tr.HitNonWorld
|
||||||
|
|
||||||
// trace from camera to hit pos, if blocked, red crosshair
|
// trace from camera to hit pos, if blocked, red crosshair
|
||||||
local tr = util.TraceLine({
|
local tr = util.TraceLine({
|
||||||
start = player:GetPos(),
|
start = player:GetPos(),
|
||||||
endpos = tr.HitPos + tr.HitNormal * 5,
|
endpos = tr.HitPos + tr.HitNormal * 5,
|
||||||
filter = player,
|
filter = player,
|
||||||
mask = MASK_SHOT
|
mask = MASK_SHOT
|
||||||
})
|
})
|
||||||
surface.SetDrawColor(255, 255, 255, 255)
|
surface.SetDrawColor(255, 255, 255, 255)
|
||||||
if (hit) then
|
if (hit) then
|
||||||
surface.SetDrawColor(0, 192, 24, 255)
|
surface.SetDrawColor(0, 192, 24, 255)
|
||||||
|
end
|
||||||
|
surface.DrawLine(pos.x - offset, pos.y, pos.x - offset2, pos.y)
|
||||||
|
surface.DrawLine(pos.x + offset, pos.y, pos.x + offset2, pos.y)
|
||||||
|
surface.DrawLine(pos.x, pos.y - offset, pos.x, pos.y - offset2)
|
||||||
|
surface.DrawLine(pos.x, pos.y + offset, pos.x, pos.y + offset2)
|
||||||
|
surface.DrawLine(pos.x - 1, pos.y, pos.x + 1, pos.y)
|
||||||
|
surface.DrawLine(pos.x, pos.y - 1, pos.x, pos.y + 1)
|
||||||
end
|
end
|
||||||
surface.DrawLine(pos.x - offset, pos.y, pos.x - offset2, pos.y)
|
|
||||||
surface.DrawLine(pos.x + offset, pos.y, pos.x + offset2, pos.y)
|
|
||||||
surface.DrawLine(pos.x, pos.y - offset, pos.x, pos.y - offset2)
|
|
||||||
surface.DrawLine(pos.x, pos.y + offset, pos.x, pos.y + offset2)
|
|
||||||
surface.DrawLine(pos.x - 1, pos.y, pos.x + 1, pos.y)
|
|
||||||
surface.DrawLine(pos.x, pos.y - 1, pos.x, pos.y + 1)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hook.Add("HUDShouldDraw", "Disguiser.ThirdPersonHUDShouldDraw", function(name)
|
hook.Add("HUDShouldDraw", "Disguiser.ThirdPersonHUDShouldDraw", function(name)
|
||||||
|
|
|
@ -227,7 +227,6 @@ function SWEP:Undisguise()
|
||||||
umsg.End()
|
umsg.End()
|
||||||
|
|
||||||
// Pop!
|
// Pop!
|
||||||
UndisguiseSilent()
|
|
||||||
owner:EmitSound("Disguiser.Undisguise")
|
owner:EmitSound("Disguiser.Undisguise")
|
||||||
|
|
||||||
// We're no longer disguised
|
// We're no longer disguised
|
||||||
|
|
Loading…
Reference in New Issue