OK, I've found out that it's the chat.Add command which seems to work wrong here, I've tested it like this:
hook.Add( "TTTBeginRound", "NumberOfTypes", function()
local TCount = 0
local DCount = 0
local ICount = 0
for k, v in pairs( player.GetAll() ) do
if v:IsTraitor() and v:Alive() then
TCount=TCount+1
elseif v:IsDetective() and v:Alive() then
DCount=DCount+1
elseif v:Alive() then
ICount=ICount+1;
end
end
--Test
print(TCount)
local traitor = tostring(TCount)
local detectives = tostring(DCount)
local innocents = tostring(ICount)
PrintMessage( HUD_PRINTTALK, "Traitor: "..traitor)
chat.AddText( color_white , "Diese Runde gibt es " , Color(255,7,0), traitor, " Traitor, " , Color(0,0,235), detectives, " Detectives", color_white, " und " , Color(0,235,0), innocents , " Innocents.")
end )
The PrintMessage prints that there are 3 traitors also for Innocents, so the variable itself is finde. I wonder why chat.Add seems to change even the string variable for the innocents so they can't see the number of traitors (i think because they just can't see the traitors, but isn't the for function which counts the traitors a 'golbal' one, so from the view of the server and not of the players)?
I thought chat.Add would only print down a text but it seems like it would really change even a string value. I can't really imagine why or how to fix it.
Any Ideas? I would be glad to get a reply to that question
P.S. : I also tried your version to get it into a line or a sentence, but it doesn't even print out the message (but there is no error?)
if (SERVER) then
util.AddNetworkString( "SendClientSCount" ) --S stands for Special (T and D)
util.AddNetworkString( "SendClientICount" ) --I (obviously) stands for Innocent
hook.Add( "TTTBeginRound", "NumberOfTypes", function()
local TCount = 0
local DCount = 0
local ICount = 0
for k, v in pairs( player.GetAll() ) do
if v:IsTraitor() and v:Alive() then
TCount=TCount+1
elseif v:IsDetective() and v:Alive() then
DCount=DCount+1
elseif v:Alive() then
ICount=ICount+1;
end
end
for k, v in pairs( player.GetAll() ) do
net.Start( "SendClientSCount" )
net.WriteInt(TCount, 32)
net.WriteUInt(DCount, 32)
net.Send(v)
net.Start( "SendClientICount" )
net.WriteInt(ICount, 32)
net.Send(v)
end
end )
end
if (CLIENT) then
net.Receive( "SendClientSCount", function(len)
local traitor = ("Traitors: "..net.ReadInt(32))
local detecitves = ("Detectives: "..net.ReadUInt(32))
end )
net.Receive( "SendClientICount", function(len)
local innocents = ("Innocents: "..net.ReadInt(32))
end )
chat.AddText( color_white , "Diese Runde gibt es " , Color(255,7,0), traitor, " Traitor, " , Color(0,0,235), detectives, " Detectives", color_white, " und " , Color(0,235,0), innocents , " Innocents.")
end