Corrected "player" => "ply" and made some hooks pass down to base properly. Fixes #8.
NOTE: This will disable proper blood rendering. Gotta test it out on multiplayer though.master
parent
6c636543ad
commit
1ab7c74f9a
|
@ -27,31 +27,33 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
hook.Add("CalcView", "Disguiser.ThirdPersonCalcView", function(player, pos, angles, fov)
|
hook.Add("CalcView", "Disguiser.ThirdPersonCalcView", function(ply, pos, angles, fov)
|
||||||
local smoothscale = 1
|
smoothscale = 1
|
||||||
|
|
||||||
if !IsValid(player) then return end
|
if IsValid(ply) && ply:Alive() && ply:GetNetworkedBool("thirdperson") then
|
||||||
|
av = ply:GetAimVector()
|
||||||
if player:GetNetworkedBool("thirdperson") then
|
|
||||||
angles = player:GetAimVector():Angle()
|
if !av then return end
|
||||||
|
|
||||||
|
angles = av:Angle()
|
||||||
|
|
||||||
local targetpos = Vector(0, 0, player:OBBMaxs().z)
|
local targetpos = Vector(0, 0, ply:OBBMaxs().z)
|
||||||
if player:KeyDown(IN_DUCK) then
|
if ply:KeyDown(IN_DUCK) then
|
||||||
if player:GetVelocity():Length() > 0 then
|
if ply:GetVelocity():Length() > 0 then
|
||||||
targetpos.z = targetpos.z / 1.33
|
targetpos.z = targetpos.z / 1.33
|
||||||
else
|
else
|
||||||
targetpos.z = targetpos.z / 2
|
targetpos.z = targetpos.z / 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
player:SetAngles(angles)
|
ply:SetAngles(angles)
|
||||||
|
|
||||||
local targetfov = fov
|
local targetfov = fov
|
||||||
if player:GetVelocity():DotProduct(player:GetForward()) > 10 then
|
if ply:GetVelocity():DotProduct(ply:GetForward()) > 10 then
|
||||||
if player:KeyDown(IN_SPEED) then
|
if ply:KeyDown(IN_SPEED) then
|
||||||
targetpos = targetpos + player:GetForward() * -10
|
targetpos = targetpos + ply:GetForward() * -10
|
||||||
else
|
else
|
||||||
targetpos = targetpos + player:GetForward() * -5
|
targetpos = targetpos + ply:GetForward() * -5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,16 +66,16 @@ hook.Add("CalcView", "Disguiser.ThirdPersonCalcView", function(player, pos, angl
|
||||||
|
|
||||||
// offset it by the stored amounts, but trace so it stays outside walls
|
// offset it by the stored amounts, but trace so it stays outside walls
|
||||||
// we don't smooth this so the camera feels like its tightly following the mouse
|
// we don't smooth this so the camera feels like its tightly following the mouse
|
||||||
local offset = Vector(50 + (player:OBBMaxs().z - player:OBBMins().z), 0, 10)
|
local offset = Vector(50 + (ply:OBBMaxs().z - ply:OBBMins().z), 0, 10)
|
||||||
local t = {
|
local t = {
|
||||||
start = player:GetPos() + pos,
|
start = ply:GetPos() + pos,
|
||||||
endpos = (player:GetPos() + pos)
|
endpos = (ply:GetPos() + pos)
|
||||||
+ (angles:Forward() * -offset.x)
|
+ (angles:Forward() * -offset.x)
|
||||||
+ (angles:Right() * offset.y)
|
+ (angles:Right() * offset.y)
|
||||||
+ (angles:Up() * offset.z),
|
+ (angles:Up() * offset.z),
|
||||||
filter = player
|
filter = ply
|
||||||
}
|
}
|
||||||
if player:GetVehicle():IsValid() then
|
if ply:GetVehicle():IsValid() then
|
||||||
pos = t.endpos
|
pos = t.endpos
|
||||||
else
|
else
|
||||||
local tr = util.TraceLine(t)
|
local tr = util.TraceLine(t)
|
||||||
|
@ -87,22 +89,19 @@ hook.Add("CalcView", "Disguiser.ThirdPersonCalcView", function(player, pos, angl
|
||||||
fov = targetfov
|
fov = targetfov
|
||||||
fov = math.Approach(fov, targetfov, math.abs(targetfov - fov) * smoothscale)
|
fov = math.Approach(fov, targetfov, math.abs(targetfov - fov) * smoothscale)
|
||||||
|
|
||||||
return GAMEMODE:CalcView(player, pos, angles, fov)
|
return GAMEMODE:CalcView(ply, pos, angles, fov)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hook.Add("HUDPaint", "Disguiser.ThirdPersonHUDPaint", function()
|
hook.Add("HUDPaint", "Disguiser.ThirdPersonHUDPaint", function()
|
||||||
local player = LocalPlayer()
|
local ply = LocalPlayer()
|
||||||
if !IsValid(player) then
|
|
||||||
return
|
if IsValid(ply) && ply:Alive() && ply:GetNetworkedBool("thirdperson") then
|
||||||
end
|
|
||||||
|
|
||||||
if player:GetNetworkedBool("thirdperson") && player:Alive() then
|
|
||||||
// trace from muzzle to hit pos
|
// trace from muzzle to hit pos
|
||||||
local t = {}
|
local t = {}
|
||||||
t.start = player:GetShootPos()
|
t.start = ply:GetShootPos()
|
||||||
t.endpos = t.start + player:GetAimVector() * 9000
|
t.endpos = t.start + ply:GetAimVector() * 9000
|
||||||
t.filter = player
|
t.filter = ply
|
||||||
local tr = util.TraceLine(t)
|
local tr = util.TraceLine(t)
|
||||||
local pos = tr.HitPos:ToScreen()
|
local pos = tr.HitPos:ToScreen()
|
||||||
local fraction = math.min((tr.HitPos - t.start):Length(), 1024) / 1024
|
local fraction = math.min((tr.HitPos - t.start):Length(), 1024) / 1024
|
||||||
|
@ -113,9 +112,9 @@ hook.Add("HUDPaint", "Disguiser.ThirdPersonHUDPaint", function()
|
||||||
|
|
||||||
// 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 = ply:GetPos(),
|
||||||
endpos = tr.HitPos + tr.HitNormal * 5,
|
endpos = tr.HitPos + tr.HitNormal * 5,
|
||||||
filter = player,
|
filter = ply,
|
||||||
mask = MASK_SHOT
|
mask = MASK_SHOT
|
||||||
})
|
})
|
||||||
surface.SetDrawColor(255, 255, 255, 255)
|
surface.SetDrawColor(255, 255, 255, 255)
|
||||||
|
@ -132,7 +131,7 @@ hook.Add("HUDPaint", "Disguiser.ThirdPersonHUDPaint", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
hook.Add("HUDShouldDraw", "Disguiser.ThirdPersonHUDShouldDraw", function(name)
|
hook.Add("HUDShouldDraw", "Disguiser.ThirdPersonHUDShouldDraw", function(name)
|
||||||
if name == "CHudCrosshair" and LocalPlayer():GetNetworkedInt("thirdperson") == 1 then
|
if name == "CHudCrosshair" and IsValid(LocalPlayer()) and LocalPlayer():Alive() and LocalPlayer():GetNetworkedBool("thirdperson") then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end)
|
end)
|
|
@ -332,18 +332,16 @@ function SWEP:EnableThirdPerson(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
hook.Add("PlayerDeath", "Disguiser.ThirdPersonDeath", function(victim, inflictor, killer)
|
hook.Add("PlayerDeath", "Disguiser.ThirdPersonDeath", function(victim, inflictor, killer)
|
||||||
|
|
||||||
victim:SetNetworkedBool("thirdperson", false)
|
|
||||||
victim:SetNetworkedBool("isDisguised", false)
|
|
||||||
local ventity = victim:GetViewEntity()
|
|
||||||
|
|
||||||
// Escape third-person mode
|
// Escape third-person mode
|
||||||
if (IsValid(ventity)) then
|
if victim:GetNWBool("thirdperson") || victim:GetNWBool("isDisguised") then
|
||||||
ventity:Remove()
|
local ventity = victim:GetViewEntity()
|
||||||
victim:SetViewEntity(victim)
|
if (IsValid(ventity)) then
|
||||||
end
|
victim:SetViewEntity(victim)
|
||||||
|
ventity:Remove()
|
||||||
if (!!victim.Disguised) then
|
end
|
||||||
|
victim:SetNetworkedBool("thirdperson", false)
|
||||||
|
victim:SetNetworkedBool("isDisguised", false)
|
||||||
|
|
||||||
// fake entity for spectacular death!
|
// fake entity for spectacular death!
|
||||||
local dentity = ents.Create("prop_physics")
|
local dentity = ents.Create("prop_physics")
|
||||||
dentity:SetModel(victim:GetModel())
|
dentity:SetModel(victim:GetModel())
|
||||||
|
@ -366,6 +364,7 @@ hook.Add("PlayerDeath", "Disguiser.ThirdPersonDeath", function(victim, inflictor
|
||||||
dentity:Fire("kill", "", 2)
|
dentity:Fire("kill", "", 2)
|
||||||
dentity:Fire("enablemotion","",0)
|
dentity:Fire("enablemotion","",0)
|
||||||
|
|
||||||
|
/*
|
||||||
// Manually draw additional blood (for some reason setting the blood color has no effect)
|
// Manually draw additional blood (for some reason setting the blood color has no effect)
|
||||||
local traceworld = {}
|
local traceworld = {}
|
||||||
traceworld.start = victim:GetPos() + Vector(0, 0, 20)
|
traceworld.start = victim:GetPos() + Vector(0, 0, 20)
|
||||||
|
@ -378,6 +377,8 @@ hook.Add("PlayerDeath", "Disguiser.ThirdPersonDeath", function(victim, inflictor
|
||||||
edata:SetEntity(dentity)
|
edata:SetEntity(dentity)
|
||||||
util.Effect("BloodImpact", edata)
|
util.Effect("BloodImpact", edata)
|
||||||
util.Decal("Splash.Large", trw.HitPos + trw.HitNormal, trw.HitPos - trw.HitNormal)
|
util.Decal("Splash.Large", trw.HitPos + trw.HitNormal, trw.HitPos - trw.HitNormal)
|
||||||
|
|
||||||
|
*/
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue