Skip to content

Commit

Permalink
TTT: New attempt at propspec fix
Browse files Browse the repository at this point in the history
Seems there were still problematic cases created by 6aaed73 (see #610),
so this replaces it with a different fix.

The original issue was that players who propspec during prep remained
linked to that entity if they became spectator later during the round.
Rather than trying to clear that linkage for all players when the round
starts, we now clear it in a safer way whenever a player spawns.
  • Loading branch information
svdm committed Feb 23, 2014
1 parent 6aaed73 commit 497a796
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
14 changes: 0 additions & 14 deletions garrysmod/gamemodes/terrortown/gamemode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,6 @@ function FixSpectators()
end
end

-- Calls PROPSPEC.End on all players who currently have a propspec
-- Normally this is handled by the gamemode because the entity is no longer valid
-- But in our case the props were not removed
local function FixPropSpectators()
for _, ply in pairs(player.GetAll()) do
if ply.propspec then
PROPSPEC.End(ply)
end
end
end

-- Used to be in think, now a timer
local function WinChecker()
if GetRoundState() == ROUND_ACTIVE then
Expand Down Expand Up @@ -656,9 +645,6 @@ function BeginRound()

InitRoundEndTime()

-- Unspectate players who were spectating during prep
FixPropSpectators()

if CheckForAbort() then return end

-- Respawn dumb people who died during prep
Expand Down
3 changes: 3 additions & 0 deletions garrysmod/gamemodes/terrortown/gamemode/player_ext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ function plymeta:SpawnForRound(dead_only)

if not self:ShouldSpawn() then return false end

-- reset propspec state that they may have gotten during prep
PROPSPEC.Clear(self)

-- respawn anyone else
if self:Team() == TEAM_SPEC then
self:UnSpectate()
Expand Down
10 changes: 8 additions & 2 deletions garrysmod/gamemodes/terrortown/gamemode/propspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ function PROPSPEC.Target(ply, ent)
PROPSPEC.Start(ply, ent)
end

function PROPSPEC.End(ply)
local ent = ply.propspec.ent or ply:GetObserverTarget()
-- Clear any propspec state a player has. Safe even if player is not currently
-- spectating.
function PROPSPEC.Clear(ply)
local ent = (ply.propspec and ply.propspec.ent) or ply:GetObserverTarget()
if IsValid(ent) then
ent:SetNWEntity("spec_owner", nil)
end

ply.propspec = nil
ply:SpectateEntity(nil)
end

function PROPSPEC.End(ply)
PROPSPEC.Clear(ply)
ply:Spectate(OBS_MODE_ROAMING)
ply:ResetViewRoll()

Expand Down

0 comments on commit 497a796

Please sign in to comment.