• Print

Author Topic: [TTT] Show Number of Traitors/Innocents at the begin of the Round  (Read 28880 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 #15 on: January 13, 2015, 03:06:47 pm »
Thx for your answer :) I know the commands, but I want to get such a message automaticly at the begin of every round.
Yes, thats what I'm looking for. You use something like that for your server? Would be great if you could share it. :)

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #16 on: January 13, 2015, 03:59:27 pm »
Thx for your answer :) I know the commands, but I want to get such a message automaticly at the begin of every round.
Yes, thats what I'm looking for. You use something like that for your server? Would be great if you could share it. :)

Nah I just made it earlier today for fun
Fairly simple actually

Code: Lua
  1. if (SERVER) then
  2.         hook.Add( "TTTBeginRound", "NumberOfTypes", function()
  3.                 local TCount = 0
  4.                 local DCount = 0
  5.                 local ICount = 0
  6.                 for k, v in pairs( player.GetAll() ) do
  7.                         if v:IsTraitor() and v:Alive() then
  8.                                 TCount=TCount+1
  9.                         elseif v:IsDetective() and v:Alive() then
  10.                                 DCount=DCount+1
  11.                         elseif v:Alive() then
  12.                                 ICount=ICount+1;
  13.                         end
  14.                 end
  15.                 timer.Simple( .5, function()
  16.                         PrintMessage( HUD_PRINTTALK, "Traitors: "..TCount )
  17.                         PrintMessage( HUD_PRINTTALK, "Detectives: "..DCount )
  18.                         PrintMessage( HUD_PRINTTALK, "Innocents: ".. ICount )
  19.                 end )
  20.         end )
  21. end

I put a timer with my PrintMessages out of habit, completely unnecessary though and you can remove it if you feel like it
« Last Edit: January 13, 2015, 04:01:15 pm by Zmaster »

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #17 on: January 14, 2015, 12:13:12 am »
Thx for the code, yeah now it looks really simple :D I just didn't know the specific ttt functions like Player:IsTraitor (even if it sounds pretty logical now :D ). Is there somewhere something like a list of these ttt specific functions? Would be good to know :)
Thanks for your help!

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #18 on: January 14, 2015, 03:50:39 am »
I found it by going through the files on the TTT github here: https://github.com/Nomad923/newprimettt/blob/master/addons/TTT_KillFeed/lua/autorun/server/tttkillfeed.lua
That one showed me IsTraitor() and IsDetective()

The TTT website has some documentation on TTT hooks, but not really anything else code-wise http://ttt.badking.net/guides/hooks

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #19 on: January 14, 2015, 06:07:44 am »
Yes i've read the hooks but as you said, sadly there is no list of these functions.  :(
Maybe someone else has an idea?

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #20 on: January 15, 2015, 08:01:37 am »
Another question: I tried to add some colours to the chat message (which is obviously not that important, but I'll need it for some further things I'm going to script) and as this is not possible with PrintMessage (tell me if I'm wrong) I tried to use Add.Chat as it's also used for example in the killreval. But it does not work. In the console there appears the Error: attempt to call global ’chat’ (a nil Value). So he thinks Chat.Add is a function and not the TTT method. I've searched after it and found serval answers, but everyone was different and nothing really worked for me. Anyone here who could give me a tip? :)

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #21 on: January 15, 2015, 08:17:18 am »
chat.AddText is a function? - http://wiki.garrysmod.com/page/chat/AddText
Also, it's client side code, so if you're trying to use it inside of the server if statement, it won't work
You could use a net message to tell all clients to put that message in their chat

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #22 on: January 15, 2015, 08:42:40 am »
Sorry, I think 'function' and 'method' are different in german :D My Bad.
I tried it in the client folder, and now no error appears any more, but also no message in the chat. I tried to add a chat.Add function right after the start of the function, but it didn't work too. But no error in the console. Really strange.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #23 on: January 15, 2015, 08:47:38 am »
Do you know how to use net messages?
I'll do this for you when I get home from school if nobody beats me to it

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #24 on: January 15, 2015, 08:57:46 am »
Yeah that would be great :)

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #25 on: January 15, 2015, 02:08:41 pm »
Is there any specific colors you want

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #26 on: January 15, 2015, 02:13:18 pm »
Best would be in this case red for traitors, blue for detectives and green for innocents :)

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #27 on: January 15, 2015, 06:55:59 pm »
My first time working with net.WriteInt plz no judge (lol)

It seems to work fine though



Code: Lua
  1. if (SERVER) then
  2.         util.AddNetworkString( "SendClientSCount" ) //S stands for Special (T and D)
  3.         util.AddNetworkString( "SendClientICount" ) //I (obviously) stands for Innocent
  4.         hook.Add( "TTTBeginRound", "NumberOfTypes", function()
  5.                 local TCount = 0
  6.                 local DCount = 0
  7.                 local ICount = 0
  8.                 for k, v in pairs( player.GetAll() ) do
  9.                         if v:IsTraitor() and v:Alive() then
  10.                                 TCount=TCount+1
  11.                         elseif v:IsDetective() and v:Alive() then
  12.                                 DCount=DCount+1
  13.                         elseif v:Alive() then
  14.                                 ICount=ICount+1;
  15.                         end
  16.                 end
  17.                 for k, v in pairs( player.GetAll() ) do
  18.                         net.Start( "SendClientSCount" )
  19.                                 net.WriteInt(TCount, 32)
  20.                                 net.WriteUInt(DCount, 32)
  21.                         net.Send(v)
  22.                         net.Start( "SendClientICount" )
  23.                                 net.WriteInt(ICount, 32)
  24.                         net.Send(v)
  25.                 end
  26.         end )
  27. end
  28.  
  29. if (CLIENT) then
  30.         net.Receive( "SendClientSCount", function(len)
  31.                 chat.AddText( Color( 255, 0, 0, 255 ), "Traitors: "..net.ReadInt(32))
  32.                 chat.AddText( Color( 0, 0, 255, 255), "Detectives: "..net.ReadUInt(32))
  33.         end )
  34.         net.Receive( "SendClientICount", function(len)
  35.                 chat.AddText( Color( 0, 255, 0, 255), "Innocents: "..net.ReadInt(32))
  36.         end )
  37. end

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #28 on: January 16, 2015, 05:18:35 am »
Thanks again for your answers. I will test it as soon as my server works again :(

Offline DH1806

  • Newbie
  • *
  • Posts: 38
  • Karma: 0
Re: [TTT] Show Number of Traitors/Innocents at the begin of the Round
« Reply #29 on: January 16, 2015, 08:39:26 am »
Okay, thank you very much for your solution. I think I found a little shorter one because I wanted to have the whole message in one line. I also found out why Add.Chat didn't work.

Code: [Select]
hook.Add( "TTTBeginRound", "NumberOfTypes", function()
   
local TCount = 0
    local DCount = 0
    local ICount = 0
local traitor = ""
local detectives = ""
local innocents = ""
   
for k, v in pairs( player.GetAll() ) do
if v:IsActiveTraitor() then
TCount=TCount+1
elseif v:IsActiveDetective() then
DCount=DCount+1
elseif v:Alive() then
ICount=ICount+1;
end
    end
traitor = tostring(TCount)
detectives = tostring(DCount)
innocents = tostring(ICount)

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 )

Don't worry about the german :D It sinmply means "In this round there are ..." The problem is that the traitor does not get count for innocents or detectives. For them every traitor gets count as an innocent too, only for the traitors is the Number of traitors visible. Does anyone know how to fix it?





  • Print