Skip to content

Commit

Permalink
TTT: fixed colour issues if not all players have same model
Browse files Browse the repository at this point in the history
If the random model for a round was a colourable model, any players with
their own custom special rainbow seahorse models would also get a colour
applied.

Fixed by applying colour to a player only if their specific model is
allowed to have it. To prevent overrides of PlayerSetModel from
overriding this colouring behaviour, it has been moved to a
TTTPlayerSetColor hook, which is always called after PlayerSetModel.
  • Loading branch information
svdm committed Feb 26, 2014
1 parent f889c07 commit 8e2dd3a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion garrysmod/gamemodes/terrortown/gamemode/player.lua
Expand Up @@ -84,6 +84,7 @@ function GM:PlayerSpawn(ply)
-- ye olde hooks
hook.Call("PlayerLoadout", GAMEMODE, ply)
hook.Call("PlayerSetModel", GAMEMODE, ply)
hook.Call("TTTPlayerSetColor", GAMEMODE, ply)

local oldhands = ply:GetHands()
if IsValid(oldhands) then oldhands:Remove() end
Expand Down Expand Up @@ -253,9 +254,24 @@ function GM:PlayerSetModel(ply)
util.PrecacheModel(mdl)
ply:SetModel(mdl)

ply:SetColor(GAMEMODE.playercolor or COLOR_WHITE)
-- Always clear color state, may later be changed in TTTPlayerSetColor
ply:SetColor(COLOR_WHITE)
end


function GM:TTTPlayerSetColor(ply)
local clr = COLOR_WHITE
local should_color = hook.Call("TTTShouldColorModel", GAMEMODE, ply:GetModel())
if GAMEMODE.playercolor and should_color then
-- If this player has a colorable model, always use the same color as all
-- other colorable players, so color will never be the factor that lets
-- you tell players apart.
clr = GAMEMODE.playercolor
end
ply:SetColor(clr)
end


-- Only active players can use kill cmd
function GM:CanPlayerSuicide(ply)
return ply:IsTerror()
Expand Down
1 change: 1 addition & 0 deletions garrysmod/gamemodes/terrortown/gamemode/player_ext.lua
Expand Up @@ -270,6 +270,7 @@ end
-- true, only spawns if player is dead, else just makes sure he is healed.
function plymeta:SpawnForRound(dead_only)
hook.Call("PlayerSetModel", GAMEMODE, self)
hook.Call("TTTPlayerSetColor", GAMEMODE, self)

-- wrong alive status and not a willing spec who unforced after prep started
-- (and will therefore be "alive")
Expand Down
2 changes: 1 addition & 1 deletion garrysmod/gamemodes/terrortown/gamemode/shared.lua
Expand Up @@ -3,7 +3,7 @@ GM.Author = "Bad King Urgrain"
GM.Email = "thegreenbunny@gmail.com"
GM.Website = "ttt.badking.net"
-- Date of latest changes (YYYY-MM-DD)
GM.Version = "2014-02-23"
GM.Version = "2014-02-26"


GM.Customized = false
Expand Down

0 comments on commit 8e2dd3a

Please sign in to comment.