TTT - Player/Traitor count in chat

Hello guys! Is there an addon that displays a chat message that states how many players/traitors/innocents/detectives in the current round there are? For instance, just as the round begins:
There are <num> players. There are <num> traitors and <num> innocents.

I’ve searched around the workshop, but couldn’t find anything.

-- Run serverside
hook.Add( "TTTBeginRound", "NumRole", function() 

local TNum, INum, DNum = 0, 0, 0

for _, ply in pairs( player.GetAll() ) do
  if ply:GetRole() == ROLE_INNOCENT then INum = INum + 1
  elseif ply:GetRole() == ROLE_TRAITOR then TNum = TNum + 1
  elseif ply:GetRole() == ROLE_DETECTIVE then DNum = DNum + 1

local PNum = TNum + INum + DNum

for _, ply in pairs( player.GetAll() ) do
   ply:ChatPrint( "Players: " .. PNum .. "
Traitors: " .. TNum .. "
Innocents: " .. INum .. "
Detectives: " .. DNum )


Sorry for the indention mistakes; had to do this on my phone.

hook.Add( “TTTBeginRound”, “player_count”, function()

local plys = player.GetAll()

local t, d, i = 0, 0, 0
for k,v in ipairs( plys ) do

	local role = v:GetRole()
	if role == ROLE_TRAITOR then

	 	t = t + 1

	elseif role == ROLE_DETECTIVE then 

		d= d + 1

	elseif role == ROLE_INNOCENT then

		i = i + 1



    local total = t + d + i

local str = Format( "There is a total of %i players this round with %i traitors, %i detectives and %i innocents.", total, t, d, i )

for k,v in ipairs( plys ) do
	v:ChatPrint( str )



there you go :slight_smile: put this in lua/autorun/server and restart your server for it to work.

edit: wow ninja’d GG
edit2: actually use my code, his code is clientside and won’t work properly

That will always return 0 for traitors from my knowledge, other clients don’t know who the traitor’s are clientside, as it’s not networked until the traitor is dead or a third party does it.

Then run it serverside and put the ChatPrint in a for loop; updating code now.

One step ahead of you dawg

That’s fine, but I’m not going to leave code broken :v:

Thanks guys! I used CallMePyro’s code and it works! How can I change the colors though? For instance having the word ‘innocents’ in green, and ‘traitors’ in red and so on.

Read this thread here: