Author Topic: [TTT] Show Number of Traitors/Innocents at the begin of the Round  (Read 14074 times)

0 Members and 1 Guest are viewing this topic.

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #30 on: January 17, 2015, 05:42:13 PM »
OK, I've found out that it's the chat.Add command which seems to work wrong here, I've tested it like this:
Code: [Select]
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?)
Code: [Select]
    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
« Last Edit: January 17, 2015, 05:44:09 PM by DH1806 »

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #31 on: January 19, 2015, 04:50:25 AM »
Finally I found a solution! :) Thanks for everyone who has helped me.


Wrong :/
« Last Edit: January 19, 2015, 07:22:38 AM by DH1806 »

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #32 on: March 31, 2017, 08:47:14 AM »
Hey guys. i tryed some of your code but it dosen't work with no errors or the "simple" code gives me this :

[ERROR] lua/autorun/server/traitorcount.lua:23: attempt to index global 'chat' (a nil value)
1. fn - lua/autorun/server/traitorcount.lua:23
2. Call - addons/ulib/lua/ulib/shared/hook.lua:110
3. unknown - gamemodes/terrortown/gamemode/init.lua:686
Timer Failed! [prep2begin][@gamemodes/terrortown/gamemode/init.lua (line 490)]

after puting it in lua/autorun/server. maybe some update? :D

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #33 on: March 31, 2017, 12:51:33 PM »
Mirron, please be careful about posting in 2 year old threads.
The discussion here started in 2014, and last post was in Jan 2015.
Original poster apparently never seemed to get fully working code from the extremely quick review I did of the past few pages.
That being said, if you have questions or code you are working on and need assistance, please ask for help in the Developers corner topic area of the forum. Our community will need to know your purpose, what code you're using and what you've tried, and questions about what you need assistance with and / or don't understand.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming