Closed janesth closed 7 years ago
fixes #9
I will make the change this time, but for future reference you should update the version number in - https://github.com/lzinga/TTTWeightedTraitorSelection/blob/master/tttweightsystem/lua/autorun/weightsystem_autorun.lua
It should let people know that there is a new version if they are using the addon.
With a high total weight and the random number to beat also being high, there was a chance that in the first round of selecting a possible T, no player could have been selected to be one, since no one was able to fulfill the first validation checkpoint.
if (r - v:GetWeight()) <= 0 then
No user could have been returned then and the function returned lastChance. But that variable wasn't set and therefore nil. This would cause an error if the program expects this function to return a player.selectedPlayer = SelectPlayerForTraitor( choices, prev_roles )
selectedPlayer:SetRole( ROLE_TRAITOR )
This would cause the following error mentioned in issue#9
[ERROR] lua/weightsystem/sv_init.lua:174: attempt to index global 'selectedPlayer' (a nil value)
1. SelectRoles - lua/weightsystem/sv_init.lua:174
2. unknown - gamemodes/terrortown/gamemode/init.lua:653
My solution is simple: I added a new variable defaultT, which every player is being set to when the loop starts. In case no lastChance is set, the last player, that went through the loop is being selected as the new T. In case lastChance is set, defaultT is ignored and lastChance will be returned, if needed.