Skip to content

Commit

Permalink
Merge pull request #1 from gamemann/master
Browse files Browse the repository at this point in the history
Pull changes
  • Loading branch information
gamemann authored Sep 7, 2022
2 parents a5319b6 + c023604 commit be73362
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scripting/dynamic_slots.sp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void OnPluginStart()
g_cvVisibleMaxplayers = FindConVar("sv_visiblemaxplayers");

// If 'sv_visiblemaxplayers' isn't available, the plugin will not work.
if (g_cvVisibleMaxplayers == INVALID_HANDLE)
if (g_cvVisibleMaxplayers == null)
{
SetFailState("%s Failed to find sv_visiblemaxplayers.", TAG);
}
Expand All @@ -41,8 +41,10 @@ public void OnPluginStart()

public void OnClientPutInServer(int client)
{
// Check if we need to alter visible maxplayers.
int diff = PlayerDiff();

// If difference isn't 0, adjust (it will be a negative value to decrease and positive to increase obviously).
if (diff != 0)
{
if (g_cvDebug.BoolValue)
Expand All @@ -56,8 +58,10 @@ public void OnClientPutInServer(int client)

public void OnClientDisconnect(int client)
{
// Check if we need to alter visible maxplayers.
int diff = PlayerDiff();

// If difference isn't 0, adjust (it will be a negative value to decrease and positive to increase obviously).
if (diff != 0)
{
if (g_cvDebug.BoolValue)
Expand All @@ -71,8 +75,10 @@ public void OnClientDisconnect(int client)

stock int PlayerDiff()
{
// Get custom client count.
int cl_cnt = GetClientCountCustom();

// For code visibility, let's assign short-named variables along with making sure we have the correct max slots variable.
int min = g_cvMinSlots.IntValue;
int max = (g_cvMaxSlots.IntValue > 0) ? g_cvMaxSlots.IntValue : MaxClients;
int slot_cnt = g_cvVisibleMaxplayers.IntValue;
Expand All @@ -88,6 +94,7 @@ stock int PlayerDiff()
{
return 0;
}

int remainder = cl_cnt - min;

int multiplier = (remainder / g_cvIncreaseSlots.IntValue) + 1;
Expand Down

0 comments on commit be73362

Please sign in to comment.