Skip to content

Commit

Permalink
Refactor PrintQueue function to optimize player requeue logic and imp…
Browse files Browse the repository at this point in the history
…rove readability
  • Loading branch information
altair-sossai committed Oct 21, 2024
1 parent 47692bb commit 40f5175
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Binary file modified addons/sourcemod/plugins/optional/l4d2_queue.smx
Binary file not shown.
31 changes: 22 additions & 9 deletions addons/sourcemod/scripting/l4d2_queue.sp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ void Enqueue(int client)

void RequeuePlayers()
{
if (IsNewGame())
return;

Player player;

bool survivorsAreWinning = SurvivorsAreWinning();
Expand All @@ -105,17 +108,27 @@ void RequeuePlayers()
continue;

int team = GetClientTeam(client);
if (team != L4D2_TEAM_SURVIVOR && team != L4D2_TEAM_INFECTED)

if (team == L4D2_TEAM_SURVIVOR)
{
player.priority = survivorsAreWinning ? 0.0 : GetEngineTime();
h_Queue.SetArray(i, player);
continue;
}

if (team == L4D2_TEAM_INFECTED)
{
player.priority = infectedAreWinning ? 0.0 : GetEngineTime();
h_Queue.SetArray(i, player);
continue;
}

if (survivorsAreWinning && team == L4D2_TEAM_SURVIVOR)
player.priority = 0.0;
else if (infectedAreWinning && team == L4D2_TEAM_INFECTED)
player.priority = 0.0;
else
if (player.priority == 0.0)
{
player.priority = GetEngineTime();

h_Queue.SetArray(i, player);
h_Queue.SetArray(i, player);
continue;
}
}

SortQueue();
Expand Down Expand Up @@ -224,7 +237,7 @@ void PrintQueue(int target)
else
CPrintToChat(target, output);

output[0] = '\0';
output = "";
}
}

Expand Down

0 comments on commit 40f5175

Please sign in to comment.