hook.Add("InitPostEntity","overridetttroles",function() local function GetTraitorCount(ply_count) -- get number of traitors: pct of players rounded down local traitor_count = math.floor(ply_count * GetConVar("ttt_traitor_pct"):GetFloat()) -- make sure there is at least 1 traitor traitor_count = math.Clamp(traitor_count, 1, GetConVar("ttt_traitor_max"):GetInt()) return traitor_count end local function GetDetectiveCount(ply_count) if ply_count < GetConVar("ttt_detective_min_players"):GetInt() then return 0 end local det_count = math.floor(ply_count * GetConVar("ttt_detective_pct"):GetFloat()) -- limit to a max det_count = math.Clamp(det_count, 1, GetConVar("ttt_detective_max"):GetInt()) return det_count end function SelectRoles() print("THIS SHIT WAS CALLED SELECT ROLES") local choices = {} local Tforces = {} local prev_roles = { [ROLE_INNOCENT] = {}, [ROLE_TRAITOR] = {}, [ROLE_DETECTIVE] = {} }; if not GAMEMODE.LastRole then GAMEMODE.LastRole = {} end for k,v in pairs(player.GetAll()) do if IsValid(v) and (not v:IsSpec()) and v:GetNWBool("TraitorNR") then table.insert(Tforces,v) v:SetNWBool("TraitorNR",false) print(v:Nick().." has been added to the table") else print("no plys made it in the table") end end for k,v in pairs(player.GetAll()) do -- everyone on the spec team is in specmode if IsValid(v) and (not v:IsSpec()) then -- save previous role and sign up as possible traitor/detective local r = GAMEMODE.LastRole[v:UniqueID()] or v:GetRole() or ROLE_INNOCENT table.insert(prev_roles[r], v) table.insert(choices, v) end v:SetRole(ROLE_INNOCENT) end -- determine how many of each role we want local choice_count = #choices local traitor_count = GetTraitorCount(choice_count) local det_count = GetDetectiveCount(choice_count) if choice_count == 0 then return end -- first select traitors local ts = 0 for k,v in pairs(Tforces) do v:SetRole(ROLE_TRAITOR) traitor_count = traitor_count - 1 v.TraitorNR = false print(v:Nick().." has been made traitor") end table.Empty(Tforces) while ts < traitor_count do -- select random index in choices table local pick = math.random(1, #choices) -- the player we consider local pply = choices[pick] -- make this guy traitor if he was not a traitor last time, or if he makes -- a roll if IsValid(pply) and ((not table.HasValue(prev_roles[ROLE_TRAITOR], pply)) or (math.random(1, 3) == 2)) then pply:SetRole(ROLE_TRAITOR) table.remove(choices, pick) ts = ts + 1 end end -- now select detectives, explicitly choosing from players who did not get -- traitor, so becoming detective does not mean you lost a chance to be -- traitor local ds = 0 local min_karma = GetConVarNumber("ttt_detective_min_karma") or 0 while (ds < det_count) and (#choices >= 1) do -- sometimes we need all remaining choices to be detective to fill the -- roles up, this happens more often with a lot of detective-deniers if #choices <= (det_count - ds) then for k, pply in pairs(choices) do if IsValid(pply) then pply:SetRole(ROLE_DETECTIVE) end end break -- out of while end local pick = math.random(1, #choices) local pply = choices[pick] -- we are less likely to be a detective unless we were innocent last round if (IsValid(pply) and ((pply:GetBaseKarma() > min_karma and table.HasValue(prev_roles[ROLE_INNOCENT], pply)) or math.random(1,3) == 2)) then -- if a player has specified he does not want to be detective, we skip -- him here (he might still get it if we don't have enough -- alternatives) if not pply:GetAvoidDetective() then pply:SetRole(ROLE_DETECTIVE) ds = ds + 1 end table.remove(choices, pick) end end GAMEMODE.LastRole = {} for _, ply in pairs(player.GetAll()) do -- initialize credit count for everyone based on their role ply:SetDefaultCredits() -- store a uid -> role map GAMEMODE.LastRole[ply:UniqueID()] = ply:GetRole() end end print("Call after gamemode") end) function killnotice(victim,fuckdis,killer) if not killer:IsPlayer() then local msg = "You died to the world" local clr = Color(255,255,255) CustomMsg(victim,msg,clr) return end if killer == victim then local msg = "You suicided!" local clr = Color(255,220,0) CustomMsg(victim,msg,clr) return end if killer:IsRole(ROLE_TRAITOR) then role = "a traitor" clr = Color(255, 0, 0, 200) elseif killer:IsRole(ROLE_DETECTIVE) then role = "a detective" clr = Color(0, 0, 255, 200) elseif killer:IsRole(ROLE_INNOCENT) then role = "innocent" clr = Color(0, 200, 0, 200) end local msg = "You were killed by "..killer:Nick()..", he was "..role CustomMsg(victim,msg,clr) end hook.Add( "PlayerDeath", "killnotice", killnotice )