Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit 8d926a5

Browse files
MinIsMinmcNuggets1
andcommitted
performance fix for util.TraceLine overwrite
Co-Authored-By: David <[email protected]>
1 parent 022ae84 commit 8d926a5

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

lua/cl_spectator_deathmatch.lua

+42-15
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ include("vgui/spec_dm_loadout.lua")
44
include("cl_stats.lua")
55
include("cl_quakesounds.lua")
66

7+
local ghosttable = {}
8+
local livingtable = {}
9+
710
local showalive = CreateClientConVar("ttt_specdm_showaliveplayers", 1, FCVAR_ARCHIVE)
811

912
function SpecDM.UpdatePartDrawing(enabled)
1013
if pac then
11-
for _, v in ipairs(player.GetHumans()) do
12-
if not v:IsGhost() then
13-
if enabled and not showalive:GetBool() then
14+
for _, v in ipairs(player.GetHumans()) do
15+
if not v:IsGhost() then
16+
if enabled and not showalive:GetBool() then
1417
pac.TogglePartDrawing(v, false)
15-
continue
16-
end
17-
end
18-
pac.TogglePartDrawing(v, true)
19-
end
20-
end
18+
continue
19+
end
20+
end
21+
pac.TogglePartDrawing(v, true)
22+
end
23+
end
2124
end
2225

2326
if pac then
@@ -50,8 +53,18 @@ net.Receive("SpecDM_GhostJoin", function()
5053
local joined = net.ReadUInt(1) == 1
5154
local ply = net.ReadEntity()
5255

53-
if not LocalPlayer():IsSpec() or not IsValid(ply) then return end
54-
if pac and not joined then
56+
if not IsValid(ply) then return end
57+
if joined then
58+
print("inserted ghost"..ply:Nick())
59+
table.insert(ghosttable, ply)
60+
table.RemoveByValue(livingtable, ply)
61+
else
62+
print("removed ghost"..ply:Nick())
63+
table.RemoveByValue(ghosttable, ply)
64+
table.insert(livingtable, ply)
65+
end
66+
if not LocalPlayer():IsSpec() then return end
67+
if pac and not joined then
5568
pac.TogglePartDrawing(ply, false)
5669
end
5770

@@ -442,8 +455,14 @@ hook.Add("Initialize", "Initialize_Ghost", function()
442455
local filt = tbl.filter
443456
local ignoretbl = {}
444457

445-
for _, v in ipairs(player.GetAll()) do
446-
if (plyghost and not v:IsGhost()) or (not plyghost and v:IsGhost()) then
458+
if plyghost then
459+
for k, v in ipairs(livingtable) do
460+
if !IsValid(v) then livingtable[k] = nil continue end
461+
table.insert(ignoretbl, v)
462+
end
463+
else
464+
for k, v in ipairs(ghosttable) do
465+
if !IsValid(v) then ghosttable[k] = nil continue end
447466
table.insert(ignoretbl, v)
448467
end
449468
end
@@ -457,10 +476,10 @@ hook.Add("Initialize", "Initialize_Ghost", function()
457476
table.Add(tbl.filter, ignoretbl)
458477
elseif isfunction(filt) then
459478
tbl.filter = function(ent)
460-
if ignoretbl[ent] or filt() then
479+
if ignoretbl[ent] then
461480
return false
462481
end
463-
return true
482+
return filt()
464483
end
465484
end
466485
else
@@ -470,6 +489,14 @@ hook.Add("Initialize", "Initialize_Ghost", function()
470489
end
471490
end)
472491

492+
hook.Add("TTTBeginRound", "TTTBeginRound_TableGhost", function()
493+
table.Empty(ghosttable)
494+
table.Empty(livingtable)
495+
for _, v in ipairs(player.GetAll()) do
496+
table.insert(livingtable, v)
497+
end
498+
end)
499+
473500
hook.Add("HUDShouldDraw", "SpecDM_TTTPropSpec", function(name)
474501
if name == "TTTPropSpec" and LocalPlayer():IsGhost() and not showalive:GetBool() then
475502
return false

lua/sv_specdm_overrides.lua

+12-11
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ hook.Add("PlayerTraceAttack", "PlayerTraceAttack_SpecDM", function(ply, dmginfo,
4040

4141
if IsValid(wep) then
4242
local s = wep:GetHeadshotMultiplier(ply, _dmginfo) or 2
43-
if s < 1 then
44-
s = 1
43+
if s < 1 then
44+
s = 1
4545
end
46-
47-
if hit then
48-
s = s-0.2
46+
47+
if hit then
48+
s = s-0.2
4949
end
50-
50+
5151
_dmginfo:ScaleDamage(s)
5252
end
5353
elseif hg == HITGROUP_LEFTARM or hg == HITGROUP_RIGHTARM or hg == HITGROUP_LEFTLEG or hg == HITGROUP_RIGHTLEG or hg == HITGROUP_GEAR then
@@ -70,7 +70,7 @@ hook.Add("PlayerSpawn", "PlayerSpawn_SpecDM", function(ply)
7070
ply:GiveGhostWeapons()
7171

7272
hook.Call("PlayerSetModel", GAMEMODE, ply)
73-
end
73+
end
7474
end)
7575

7676
local function SpecDM_Respawn(ply)
@@ -82,7 +82,7 @@ local function SpecDM_Respawn(ply)
8282
ply:GiveGhostWeapons()
8383

8484
SpecDM:RelationShip(ply)
85-
end
85+
end
8686
end
8787

8888
hook.Add("PlayerDeath", "PlayerDeath_SpecDM", function(victim, inflictor, attacker)
@@ -191,7 +191,8 @@ hook.Add("Initialize", "Initialize_SpecDM", function()
191191
local old_SpawnForRound = meta.SpawnForRound
192192
function meta:SpawnForRound(dead_only)
193193
if self:IsGhost() then
194-
self:SetGhost(false)
194+
self:SetGhost(false)
195+
self:ManageGhost(false, false)
195196
end
196197

197198
return old_SpawnForRound(self, dead_only)
@@ -311,8 +312,8 @@ local fallsounds = {
311312

312313
hook.Add("OnPlayerHitGround", "HitGround_SpecDM", function(ply, in_water, on_floater, speed)
313314
if IsValid(ply) and ply:IsPlayer() and ply:IsGhost() then
314-
if in_water or speed < 450 or not IsValid(ply) then
315-
return true
315+
if in_water or speed < 450 or not IsValid(ply) then
316+
return true
316317
end
317318

318319
-- Everything over a threshold hurts you, rising exponentially with speed

0 commit comments

Comments
 (0)