TTT Random traitor ammount

Hello, I was wondering if anyone could tell me how I can make it so there is a random amount of traitors each round.
Thanks

Well, one way you could do it is change the cvar each endround, thus making it effectively “random”.

Is there no way to make it automatically random? or at least a simple way, I cant do anything complicated.

The way I gave was relatively easy.

[lua]hook.Add(“TTTEndRound”, “tttrandom.roles”, function()
RunConsoleCommand(“ttt_traitor_pct”, math.random(0, 1))
end)[/lua]

That’ll change your cvar each round, thus creating a “random” amount of traitors. If you want more, change 0 to any number leading up to 1.

Sorry, I missunderstood. Thanks for the help.

Hey guys, sorry for the noob question but, where am I meant to put that code you gave me? I have it in my server config file, but I dont thing that is where it is meant to go, and I cant test it right now. I’m assuming its meant to go in one of the lua files but I have no idea which one. Sorry but I really know nothing about coding.

Serverside

(begins with sv_)

Or shared, under

if SERVER then

Adding onto Nookyava’s post, you can create an empty Lua file in autorun like “lua/autorun/server/sv_traitor_chances.lua” and place the code in there.

Generally this is better than editing the gamemode itself where all changes can be lost after an update.

does math.random(0, 1) give me a random number between 0 and 1? so this means I could do math.random(0.2, 0.6) for a random number between those 2?

Yes.

I could use some help with this, I have this saved in the Lua/autorun/server folder as the name shown, but it doesn’t seem to change anything in game, is there something I have to do to activate it?

Make sure server is restarted, also, remember it’s random. So it may appear not to be working, but it is, an easy way to test if it actually is, is to add a print like



print("Randomizing T's ")


Then check the console.

Or, every round, check what value the ttt pct is set to, if it’s different to the one last round then it worked.

Ok, I will give that a go, I only asked here cause I tried maybe 15 rounds with 4 players and it was always 1 Traitor