• Print

Author Topic: Traitor amount at round start  (Read 5850 times)

0 Members and 1 Guest are viewing this topic.

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Traitor amount at round start
« on: April 01, 2017, 11:25:49 am »
Hello guys. I was just send here from an over 2 year old thread from Off-Topic. My problem/question what ever... is that i would like to have a script that posts in chat how many traitors, Detectives and innocents are spawned in the round. A nice to have would be that the text is colored with the role specific color. How i said i found something familiar but it is rather old. I am pretty new so a litte advice would be really appreciated.

Here the link to the thread
/index.php/topic,7901.0.html

Thx 4 the help and sorry for the bad English  ::)

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Traitor amount at round start
« Reply #1 on: April 02, 2017, 09:53:35 am »
There was one I used from the workshop for a while before it stopped working all of a sudden for me. I've written up my own since then and it's actually very simply. I don't know for sure if any else exist but if you're looking to make your own it's very simple. You could have 3 variables, ICount, TCount, and DCount, then loop through all the players checking
Code: Lua
  1. if Player:Alive() and Player:IsTraitor() then
  2.   TCount = TCount + 1
  3. end

And then add a couple elseifs to it to check if they are alive and IsDetective() and finally if they are JUST alive. Then have a ULib.tsayColor() to say how many are of each.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Traitor amount at round start
« Reply #2 on: April 02, 2017, 11:55:08 am »
Thanks for the explenation. but one does the script go in lua/autostart/server or one of the ulx folders?

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Traitor amount at round start
« Reply #3 on: April 03, 2017, 02:22:49 am »
This is my curent script
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)

function ULib.tsayColor( 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 )

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Traitor amount at round start
« Reply #4 on: April 03, 2017, 05:05:59 pm »
There's no need to put 'function' before the ULib.tsayColor() statement.

That can be placed anywhere where's it's autorun, but I personally have mine under
Code: [Select]
/garrysmod/addons/VCommands/lua/ulib/modules/server
Other than that, though, it should work.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Traitor amount at round start
« Reply #5 on: April 04, 2017, 05:01:26 am »
This is what i get. i put it in lua/autostart/server

Code: [Select]
[ERROR] addons/ulib/lua/ulib/shared/messages.lua:160: attempt to call method 'IsValid' (a nil value)
1. tsayColor - addons/ulib/lua/ulib/shared/messages.lua:160
2. fn - lua/autorun/server/traitorcount.lua:23
3. Call - addons/ulib/lua/ulib/shared/hook.lua:110
4. unknown - gamemodes/terrortown/gamemode/init.lua:686
Timer Failed! [prep2begin][@gamemodes/terrortown/gamemode/init.lua (line 490)]

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Traitor amount at round start
« Reply #6 on: April 04, 2017, 07:08:10 am »
This is what i get. i put it in lua/autostart/server

Code: [Select]
[ERROR] addons/ulib/lua/ulib/shared/messages.lua:160: attempt to call method 'IsValid' (a nil value)
1. tsayColor - addons/ulib/lua/ulib/shared/messages.lua:160
2. fn - lua/autorun/server/traitorcount.lua:23
3. Call - addons/ulib/lua/ulib/shared/hook.lua:110
4. unknown - gamemodes/terrortown/gamemode/init.lua:686
Timer Failed! [prep2begin][@gamemodes/terrortown/gamemode/init.lua (line 490)]

If I'm not mistaken, you placing it in /lua/server/autorun means that it loads before ULX and ULib do. So that may be causing an issue.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Traitor amount at round start
« Reply #7 on: April 04, 2017, 11:18:34 am »
Not necessarily, they're both autorun but this was just being loaded before. Best to put it in a custom ulib modules to guarantee it isn't.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Traitor amount at round start
« Reply #8 on: April 04, 2017, 01:51:34 pm »
done it but still the same

Code: [Select]
[ERROR] addons/ulib/lua/ulib/shared/messages.lua:160: attempt to call method 'IsValid' (a nil value)
1. tsayColor - addons/ulib/lua/ulib/shared/messages.lua:160
2. fn - lua/autorun/server/traitorcount.lua:23
3. Call - addons/ulib/lua/ulib/shared/hook.lua:110
4. unknown - gamemodes/terrortown/gamemode/init.lua:686
Timer Failed! [prep2begin][@gamemodes/terrortown/gamemode/init.lua (line 490)]

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Traitor amount at round start
« Reply #9 on: April 04, 2017, 01:54:44 pm »
oh no sorry it worked but it says 0 traitors... the rest is correct

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Traitor amount at round start
« Reply #10 on: April 05, 2017, 01:55:35 am »
maybe the script is to fast and dont find any traitor at the begining.. is there a wait/sleep command? or is it because the game dont allow such "cheaty" interaction?

Offline mirron

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Traitor amount at round start
« Reply #11 on: April 05, 2017, 04:15:35 am »
is there a option to make the script this sort of calculation: spawned players - detectives - innos = Traitors ? is there such function as ActivePlayers?

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Traitor amount at round start
« Reply #12 on: April 13, 2017, 07:56:21 am »
Or just make a timer that waits a second or two then counts them all.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Gr0m3r

  • Newbie
  • *
  • Posts: 33
  • Karma: 1
Re: Traitor amount at round start
« Reply #13 on: April 14, 2017, 05:21:11 am »
I'm using this addon on my server, and it's work very good.
Just add it to your server collection:
http://steamcommunity.com/sharedfiles/filedetails/?id=649273679

  • Print