TTT Weighted Traitor Selection

http://files.1337upload.net/f838b72b685e7b2f169be64700ebed63-dec061.png

So a while ago I made a TTT Weighted Traitor Selection and placed it onto ScriptFodder. After a while I didn’t feel like paying the subscription fee anymore (and I made my money back and paid for 3 months of eharmony, no luck yet!) but I decided to release it for free instead of letting it waste away as another project of mine.

Description
Weighted Traitor Selection allows players to be fairly selected to become traitors and have more people become traitors rather then not getting traitor 5 maps in a row. The longer you go with out being traitor the higher chance you have at becoming traitor. Now that might sound like you could determine who the traitor is; However the algorithm is non-deterministic, making it practically impossible to deduce the current traitors (with the exception with only 2 people playing)

Once you become traitor, your weight gets reset down to a default weight.

Configuration/Requirements

  1. Copy the folder “tttweightsystem” into your addons folder.

  2. Mysqloo (MySql) - system uses database to keep persistent weights for all the players. The weights are persistent across maps so if you have a 90% chance to become traitor next round and the map changes you will still have the 90% chance in the next map (as long as no one joins who has a higher weight), It also deletes any records any 3 weeks old (to prevent it from getting cluttered)
    Run server once and it will generate a database-template.txt in garrysmod/data/weightsystem copy and rename it to database.txt and edit the settings inside to use your database settings. (keep it in the same folder)

  3. Once the database settings are configured it will create the table and make sure everything that is needed is there.

Commands
ttt_traitor_chance_command: Sets the command players can use to see their traitor chance. If ttt_show_traitor_chance is set to 0 this will not work. (default !TC)

ttt_karma_increase_weight: If you want people to get a slight increase in weight (0-2 weight) for good karma you have to enable this command. (Default 0)

ttt_karma_increase_weight_threshold: This is the minimum amount of karma needed to get the increased weight buff. If they are below it they will just get regular weight. (default 950 based off of the default max karma.)

ttt_show_traitor_chance: At the beginning of every round it sends out a message stating what your chance is to become traitor in the next round.

ttt_weight_system_fun_mode: Allows the players weight to be portrayed onto their model. (default 0) would not suggest this to be on 24/7 more of a fun mode to have on every now and then (0% chance is normal model, 100% chance is much fatter model, everything else is in between)

http://files.1337upload.net/ss__2015-06-07_at_04.31.35_-91b25c.jpg

Admin Commands
ttt_weightlogs: (just typed into console) This allows admins to view all players weight and their chance to become traitor. As well as see the count of how many times each player has been a specific role. In the weight menu you can also get the players SteamID and set their weight back to default or set the weight to what ever you want, giving the player a higher chance or lower chance at becoming traitor in next round.

There is “groupperms.txt” in data/weightsystem that is created, it default makes it so admins and superadmins can access the ttt_weightlogs command. Make sure you add in any groups that you would like to have permissions to use the command.

Group Extra Weight
A feature that was requested was to be able to give people some extra weight based on the group they are in. You can now do this by running the addon on the server at least once and you will see a new file get added into “~/Data/tttweightsystem/” on the server called groupweight-template.txt which looks like the following:


{ "1":{ "MaxWeight":10, "GroupName":"[GroupName]", "MinWeight":0 }, "2":{ "MaxWeight":10, "GroupName":"[AnotherGroupName]", "MinWeight":5 } }

If you want to use this extra weight system you will need to copy the template and rename it to groupweight.txt and update the json mentioned above. (if you do not want to use this feature just don’t bother creating a groupweight.txt file in the folder the addon looks for that specific file):

You will be able to enter the min and max weight (the addon selects a random number between the min and max) and the group name such as “superadmin” or “regular” or “donator”. The JSON in the file will be minified but you can bring it into a JSON formatter (http://jsonformatter.curiousconcept.com/) to be able to read it easier. Users will also have it printed out to them that they were given extra weight because they were in a group. I will probably make that optional or remove it in another version.

http://files.1337upload.net/ss__2015-06-06_at_02.55.09_-034dbb.png

http://files.1337upload.net/ss__2015-06-06_at_02.55.18_-27bff8.png

Hope this can help some communities and people can make good use of it.

Download - GitHub

(if the icon is wrong for the thread I tried fixing it to addon but it wouldn’t change)

-snip I’m silly

How would you configure the database.txt if you are on a listen client (server created in client) and not on the dedicated server?

Looks like an awesome add-on though :slight_smile:

Only issue I see with this is “X hasn’t been a traitor for a long time… Let’s stare at him intently and ruin his traitor round.” As shitty as the current system can be you can at least guarantee it’s pseudo random.

This system is still random. Just the other day I was watching the weight logs I had 15 and had just been traitor like 2 rounds ago. There were some that were around 50-60 weight and I was selected. It doesn’t automatically choose those with higher weights it just gives them a higher chance.

Yea I get that. Which is why it’s “weighted.” Issue still stands, might not matter to everyone.

Hello. I tried using this and it just makes the round never start. It goes to a 5 minute preround. I tried looking through the code, but I can’t tell what the issue is.

Does anyone know anything about this? I have it setup with a database, but nothing happens.

Edit: I figured it out. I turned external connections on, but forgot to save it. :stuck_out_tongue:

Really late on this lmao. My start round is at 5 mins. In console it says I’m connected to the database.

[TTT Spectator Deathmatch] addons/tttweightsystem/lua/weightsystem/sv_init.lua:174: attempt to index global ‘selectedPlayer’ (a nil value)

  1. SelectRoles - addons/tttweightsystem/lua/weightsystem/sv_init.lua:174
  2. old_BeginRound - gamemodes/terrortown/gamemode/init.lua:655
  3. unknown - lua/sv_specdm_overrides.lua:205

Timer Failed! [prep2begin][@gamemodes/terrortown/gamemode/init.lua (line 490)]