Coder Social home page Coder Social logo

lzinga / tttweightedtraitorselection Goto Github PK

View Code? Open in Web Editor NEW
12.0 5.0 6.0 48 KB

A Garrys Mod TTT addon that improves the traitor selection process

License: Other

Lua 100.00%
garrysmod garrysmod-addon trouble-in-terroristtown ttt trouble in terrorist town

tttweightedtraitorselection's Introduction

TTT Weighted Traitor Selection

  • Latest Version: 1.2.0
  • Originally Created By: Lzinga
  • Contributors: View

Description

This addon allows players to become traitors fairly and allow the entire server to enjoy being traitor more often. With this addon the longer you go with out being a traitor the higher chance you have at becoming traitor, this also includes between map changes. This may sound like you could determine who the traitor is; however, the algorithm is non-deterministic making it practically impossible to deduce who the current traitors may be.

To read more on how this addon works you can read the How does this work? in the wiki.

Prerequisites

Depending on your preferred server saving method, you may need additional libraries installed on your server in order for this to properly function. If you are planning on using one of the two SQL methods, you will need Mysqloo (https://github.com/FredyH/MySQLOO). The installation process has instructions for all.

Installation

  1. Copy the folder tttweightsystem into your addons folder.
  2. Open the file lua/autorun/weightsystem_autorun.lua, at the top of the file there is a variable named WeightSystem.StorageType, set this to mysql, sqlite, or json based on your preferred saving method.
  3. Setup
    • SQL - Complete the installation of MySQLoo, and set up a database on your server.
    • JSON - No setup needed.
  4. Starting your Server
    • SQL - Run your 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 with your database connection info.
    • JSON - Run your server and start a round of TTT (Set minplayers to 1), the round will auto-complete and you are all set.

Console 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 in regular TTT)

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, or in the next map.

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)

Image of fat person

Admin Console Commands

ttt_weightlogs: (just typed into console) This allows admins to view all players weight and their chance to become traitor. Admins are also able to see a 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.

To gives users permission to ttt_weightlogs they must be in an allowed group. Any group you want to have access must be added to the data/weightsystem/groupperms.txt file which gets generated on first load of the script.

Admin menu

Group Extra Weight

This feature was requested by a user, with it you have the ability to give certain groups extra weight. For example you can have donators get 1 or 2 extra weight every round to increase their chances of being traitor more often. Like the database.txt file a groupweight-template.txt will be generated with an example (like below) that you can use. You can also just create the file yourself and name it groupweight.txt and make sure it is in /data/weightsystem/ folder.

As of 1.2.0, you can now also use this system to cap a player's percentage of being a traitor when assigned to a group as well.

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

In the above example, the first entry would grant a random weight gain of 0 to 10 each round, but the player would never be allowed to gain weight allowing them to go above a 10% chance to be a traitor in a round. In the second example, the weight gain is 5 to 10 points, but the player can go up to 100% chance.

If you would like to not have bonus weight gain, set both MinWeight and MaxWeight to 0.

If you do not want to use this feature simply don't have a file named groupweight.txt in the /data/weightsystem/ folder with a proper configuration.

The settings for the groupweight.txt are as follows -

Group Weight Settings

MinWeight: The minimum amount of weight you would want added to users in the group.

MaxWeight: The maximum amount of weight you would want added to users in the group.

GroupName: The group you wish for a random amount between MinWeight and MaxWeight to be added.

cappedWeight: The highest percentage chance a player in the group is allowed to attain for traitor chance.

As a note, users who are in a group and receive extra weight will be told they are getting extra weight because they are in said group.

Change Log

  • 1.1.0 => 1.2.0
    • Added the ability to store information locally in .json format, set the StorageType to json.
    • Addressed the bug where players can randomly "lose weight", this was due to the system incorrectly trying to save on the final round of a map during the map change.
    • Re-did the weight reset algorithm to be a bit more random in nature, this will prevent the issue with groups of players being traitor together frequently.
    • Added an algorithm to count the number of rounds you have not gotten traitor and exponentially increase weight gain once you pass a threshold.
    • Added round statistics to the beginning of a round.
    • Added the ability to cap the traitor chance percentage of a player based on their assigned group.

Contributors

The following users have helped this project with bug fixes and feature additions.

  • LaurenceKaye
  • MinIsMin
  • janesth
  • monster010
  • Phantom139

tttweightedtraitorselection's People

Contributors

herrmannmax avatar janesth avatar laurencekaye avatar lzinga avatar minismin avatar monster010 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tttweightedtraitorselection's Issues

Using the script with other gamemodes

Apparently the script makes the preparation phase stuck for any other gamemode rather that TTT. Because of that I have to remove the autorun file for the weight system every time I want to change the gamemode on the server.
Is it possible to add a gamemode check to the script so it doesn't start if the gamemode is not TTT?

Failing "GetTraintorCount' Function

Greetings,

I want to use my TTT Server with the TTTWeightedTraitorSelection Add-On becaus I think the current traitor selection is not really random and we have the feeling that often the same players are always traitors while some are alyways innocents.

Sadly i get the following error message after the prerair round:

[TTT2] addons/tttweightsystem/lua/weightsystem/sv_init.lua:178: attempt to call global 'GetTraitorCount' (a nil value)

  1. SelectRoles - addons/tttweightsystem/lua/weightsystem/sv_init.lua:178
  2. unknown - gamemodes/terrortown/gamemode/server/sv_main.lua:1132

Timer Failed! [prep2begin][@gamemodes/terrortown/gamemode/server/sv_main.lua (line 923)]

It seems like its the same error as mentioned in the #18 Issue

Rounds not starting due to the addon

Hey, some days ago I had this addon and this ERROR appeared sometimes and it wouldn't let the rounds start unless an admin forced it to do so (through ULX and stuff). I had to remove the addon because I couldn't keep it like that but I'm really interested in having it since many people complain about base TTT's unfair way to select players' roles (one can get traitor 5 rounds in a row, another can get innocent 15 maps in a row if you get me).

Anyway I managed to get the error through my server's console (ignore the players' chat, it's the first three errors).
ss 2016-11-21 at 08 16 26

Round will not start.

As the title says, rounds will not start while I am running this addon. I am running the original version of TTT (so not TTT 2). Any help fixing this will be greatly appreciated.

LocalPlayer a nil value when trying to write version info.

@KajTorvaldGrey messaged me with this error on Steam. This is for when the system checks for a new version here on github.

Link to location https://github.com/lzinga/TTTWeightedTraitorSelection/blob/master/tttweightsystem/lua/autorun/weightsystem_autorun.lua#L115

[ERROR] lua/autorun/weightsystem_autorun.lua:115: attempt to call global 'LocalPlayer' (a nil value)
1. onsuccess - lua/autorun/weightsystem_autorun.lua:115
2. unknown - lua/includes/modules/http.lua:35

Last time I was working on this addon it was working, so maybe something changed with LocalPlayer method or just need to change it so it has a nil check or loop over all players in the game and write it instead of using LocalPlayer.

Less traitors than expected

Hello,
the script is very nice but there is one bug:
Sometimes only 1 traitor is selected instead of 2 (also detective). It would be nice if you could fix it. :)

Maksimo007

Addon is not working with TTT2

I'm using the json method.
The list of add-ons can also be provided.

Currently hosting a Linux server via the host nitrado.net.
Since I don't know where the logs are I can't provide them, but I'm able to get them.

Get a script error when opening the game.

When I open the game, a message pops up telling that there's been some king of script error.
Inspecting the console for further information this error report is shown:
ttt error

NOTE: I'm not playing on a server. I use the "begin a game and use connect (my ip) on the console" to play with my friends via Hamachi. Not sure if that is a problem.

Syntax error @sv_init.lua

Greetings,

I get the following error at server startup:
[ERROR] addons/tttweightsystem/lua/weightsystem/sh_weightmanager.lua:7: '=' expected near '+'

  1. unknown - addons/tttweightsystem/lua/weightsystem/sv_init.lua:6
  2. include - [C]:-1
    3. unknown - addons/tttweightsystem/lua/autorun/weightsystem_autorun.lua:83

Broken Weight System

As another user has mentioned below, the traitor chance changes throughout the rounds. Also, everyones weight is just stuck at 5. It doesn't change at all from that.

Edit: Once the weight has been set once it stays to that.

Server not starting

With this addon (latest changes) installed, my server won't start.
It stops after the include of TTT language files.
No commands or cvar can be used in the console.

Without the addon it works fine.
I looked into the code but couldn't find the error.
Last message from [TTT WeightSystem] is Loading with SQLite.

Seemingly bizzare calculations

I apologize for my lack of ability to be more clear about this, however, the weights seem to be changing midround and the percentages seem to be completely random. Each time a percentage is generated on the weight log or with the chat command, it is completely different with seemingly no order. I have used a clean install with no changes.

SetDetectiveCount not called

When being selected as detective the detective counter isn't called but round counter.

wef

print("Detective Count: " .. det_count) shows the correct detective count.

Innocent Streak Bonus Weight

While looking through the code I believe this should potentially be added into a convar to set if this should be running or not.

-- Phantom139: Added a block here to add additional weight for "streaks" of not being a traitor.
if v:GetRoundsSinceTraitorCount() >= math.random(3, 5) then
	local bonusWeight = math.floor(math.pow(1.75, v:GetRoundsSinceTraitorCount()))
	v:AddWeight( bonusWeight )
	print(v:GetName() .. " was given " .. bonusWeight .. " extra weight for being on a streak of not being the traitor. ( " .. v:GetRoundsSinceTraitorCount() .. " rounds)")
end

This gives the server owner more control of what they want their server to be instead of forcing certain settings on them.

Removing [TTT Weight System] is up to date (1.0.1)?

Hey, I've been using the addon for quite a while now, I updated it and now I can't remove that message I get everytime I connect. It's not annoying, but I just don't want it. I tried looking in the files for anything like it, but I just can't find how to remove it.

How can I remove that message? Thanks for reading.

Doesn't work with PowerRounds

If you use this plugin with the PowerRounds Plugin, the prep-time doesn't work (or it resets to 5 minutes)

Error:

)
[ERROR] addons/tttweightsystem/lua/weightsystem/sv_init.lua:169: attempt to call global 'GetTraitorCount' (a nil value)

  1. SelectRoles - addons/tttweightsystem/lua/weightsystem/sv_init.lua:169
  2. unknown - gamemodes/terrortown/gamemode/init.lua:656

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

Add Log menu to admin ttt_weightlogs

Had an idea for the admin menu
Admin Menu

Adding a "Logs" tab which gives information on how much weight was given to each user, and who was given more for group permissions. Which could help in debugging as well as see exactly what the addon is doing and how much weight people are getting. Could add the logs to the database for historical purposes. Giving admins extra information about what is happening.

This is just an idea and wondering what other peoples thoughts who have been using the addon.

Round Preparing Error

When preparing end i have this error :
[ERROR] addons/tttweightsystem/lua/weightsystem/sh_playerweight.lua:110: bad argument #1 to 'WriteUInt' (number expected, got nil)

  1. WriteUInt - [C]:-1
    1. SendWeightInfo - addons/tttweightsystem/lua/weightsystem/sh_playerweight.lua:110
    2. func - addons/tttweightsystem/lua/weightsystem/sh_playerweight.lua:92
      1. unknown - lua/includes/extensions/net.lua:32

Error when selecting players

Sometimes when starting a round, this error occurs and the round doesn't begin.

[ERROR] 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. unknown - gamemodes/terrortown/gamemode/init.lua:655

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.