• TTT - Player/Traitor count in chat
    8 replies, posted
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.
[code]-- 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 end end local PNum = TNum + INum + DNum for _, ply in pairs( player.GetAll() ) do ply:ChatPrint( "Players: " .. PNum .. "\nTraitors: " .. TNum .. "\nInnocents: " .. INum .. "\nDetectives: " .. DNum ) end end)[/code] Sorry for the indention mistakes; had to do this on my phone.
[LUA] 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 end end 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 ) end end) [/LUA] there you go :) 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
[QUOTE=code_gs;45309941][code]-- Run clientside 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 end end local PNum = TNum + INum + DNum LocalPlayer():ChatPrint( "Players: " .. PNum .. "\nTraitors: " .. TNum .. "\nInnocents: " .. INum .. "\nDetectives: " .. DNum ) end)[/code] Sorry for the indention mistakes; had to do this on my phone.[/QUOTE] 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.
[QUOTE=Phoenixf129;45309976]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.[/QUOTE] Then run it serverside and put the ChatPrint in a for loop; updating code now.
[QUOTE=code_gs;45310056]Then run it serverside and put the ChatPrint in a for loop; updating code now.[/QUOTE] One step ahead of you dawg
[QUOTE=CallMePyro;45310068]One step ahead of you dawg[/QUOTE] 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: [url]http://facepunch.com/showthread.php?t=1407258[/url]
Sorry, you need to Log In to post a reply to this thread.