Skip to content

Commit

Permalink
Add team name to max pause/pause time used.
Browse files Browse the repository at this point in the history
Add backup pause type hint
Add stop commadn not enabled translation
Don't allow stop command during admin pause
Move pause time inside PauseGame function
Automatically unpause if max pauses get set to a lower value than already consumed while a pause is active
  • Loading branch information
nickdnk committed Jul 25, 2022
1 parent c3539d7 commit 003c5a6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
7 changes: 7 additions & 0 deletions scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ public Action Command_DumpStats(int client, int args) {

public Action Command_Stop(int client, int args) {
if (!g_StopCommandEnabledCvar.BoolValue) {
Get5_MessageToAll("%t", "StopCommandNotEnabled");
return Plugin_Handled;
}

Expand All @@ -1043,6 +1044,12 @@ public Action Command_Stop(int client, int args) {
// Let the server/rcon always force restore.
if (client == 0) {
RestoreLastRound(client);
return Plugin_Handled;
}

if (g_PauseType == Get5PauseType_Admin) {
// Don't let teams restore backups while an admin has paused the game.
return Plugin_Handled;
}

Get5Team team = GetClientMatchTeam(client);
Expand Down
4 changes: 0 additions & 4 deletions scripting/get5/goinglive.sp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public Action MatchLive(Handle timer) {
return Plugin_Handled;
}

if (IsPaused()) {
UnpauseGame(Get5Team_None);
}

// Reset match config cvars. The problem is that when they are first
// set in StartGoingLive is that setting them right after executing the
// live config causes the live config values to get used for some reason
Expand Down
50 changes: 35 additions & 15 deletions scripting/get5/pausing.sp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ stock void PauseGame(Get5Team team, Get5PauseType type) {

EventLogger_LogAndDeleteEvent(event);

// Only create a pause timer if a pause is not already ongoing.
if (g_PauseType == Get5PauseType_None) {
CreateTimer(1.0, Timer_PauseTimeCheck, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}

g_PauseType = type;
g_PausingTeam = team;
g_IsChangingPauseState = true;
Expand Down Expand Up @@ -109,7 +114,6 @@ public Action Command_TechPause(int client, int args) {

g_TechnicalPausesUsed[team]++;
PauseGame(team, Get5PauseType_Tech);
CreateTimer(1.0, Timer_PauseTimeCheck, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);

Get5_MessageToAll("%t", "MatchTechPausedByTeamMessage", client);
if (maxTechPauses > 0) {
Expand All @@ -120,11 +124,6 @@ public Action Command_TechPause(int client, int args) {

public Action Command_Pause(int client, int args) {
if (client == 0) {
if (g_PauseType == Get5PauseType_None) {
// Since admin pauses can override any other pause that might already be running, we do only start a timer if one
// is not already running.
CreateTimer(1.0, Timer_PauseTimeCheck, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
PauseGame(Get5Team_None, Get5PauseType_Admin);
Get5_MessageToAll("%t", "AdminForcePauseInfoMessage");
return Plugin_Handled;
Expand All @@ -151,22 +150,20 @@ public Action Command_Pause(int client, int args) {
if (!g_FixedPauseTimeCvar.BoolValue) {
int maxPauseTime = g_MaxPauseTimeCvar.IntValue;
if (maxPauseTime > 0 && g_TacticalPauseTimeUsed[team] >= maxPauseTime) {

char maxPauseTimeFormatted[16];
convertSecondsToMinutesAndSeconds(maxPauseTime, maxPauseTimeFormatted, sizeof(maxPauseTimeFormatted));
Get5_Message(client, "%t", "MaxPausesTimeUsedInfoMessage", maxPauseTimeFormatted);
Get5_Message(client, "%t", "MaxPausesTimeUsedInfoMessage", maxPauseTimeFormatted, g_FormattedTeamNames[team]);
return Plugin_Handled;
}
}

if (maxPauses > 0 && g_TacticalPausesUsed[team] >= maxPauses) {
Get5_Message(client, "%t", "MaxPausesUsedInfoMessage", maxPauses);
Get5_Message(client, "%t", "MaxPausesUsedInfoMessage", maxPauses, g_FormattedTeamNames[team]);
return Plugin_Handled;
}

g_TacticalPausesUsed[team]++;
PauseGame(team, Get5PauseType_Tactical);
CreateTimer(1.0, Timer_PauseTimeCheck, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);

if (IsPlayer(client)) {
Get5_MessageToAll("%t", "MatchPausedByTeamMessage", client);
Expand Down Expand Up @@ -208,11 +205,14 @@ public Action Command_Unpause(int client, int args) {
}

g_TeamReadyForUnpause[team] = true;
if (g_PauseType == Get5PauseType_Tech) {
int maxTechPauseDuration = g_MaxTechPauseDurationCvar.IntValue;
int maxTechPauses = g_MaxTechPausesCvar.IntValue;
int techPausesUsed = g_TechnicalPausesUsed[g_PausingTeam];

int maxTechPauseDuration = g_MaxTechPauseDurationCvar.IntValue;

if (g_PauseType == Get5PauseType_Tech && maxTechPauseDuration > 0) {
if (g_LatestPauseDuration >= maxTechPauseDuration) {
if ((maxTechPauseDuration > 0 && g_LatestPauseDuration >= maxTechPauseDuration) ||
(maxTechPauses > 0 && techPausesUsed > maxTechPauses)
) {
UnpauseGame(team);
if (IsPlayer(client)) {
Get5_MessageToAll("%t", "MatchUnpauseInfoMessage", client);
Expand Down Expand Up @@ -278,6 +278,12 @@ public Action Timer_PauseTimeCheck(Handle timer) {
UnpauseGame(team);
return Plugin_Stop;
}
} else if (maxTacticalPauses > 0 && tacticalPausesUsed > maxTacticalPauses) {
// The game gets unpaused if the number of maximum pauses changes to below the number of used pauses while a
// pause is active. Kind of a weird edge-case, but it should be handled gracefully.
Get5_MessageToAll("%t", "MaxPausesUsedInfoMessage", maxTacticalPauses, g_FormattedTeamNames[g_PausingTeam]);
UnpauseGame(team);
return Plugin_Stop;
} else if (!g_TeamReadyForUnpause[team]) {
// If the team that called the pause has indicated they are ready, no more time should be subtracted from their
// maximum pause time, but the timer must keep running as they could go back to not-ready-for-unpause before the
Expand Down Expand Up @@ -348,7 +354,9 @@ public Action Timer_PauseTimeCheck(Handle timer) {
// -1 assumes unlimited.
int timeLeft = -1;

if (!g_TeamReadyForUnpause[team]) {
// If tech pause max is reduced to below what is used, we don't want to print remaining time, as anyone can unpause.
// We achieve this by simply skipping the time calculation if max tech pauses have been exceeded.
if (!g_TeamReadyForUnpause[team] && (maxTechPauses == 0 || techPausesUsed <= maxTechPauses)) {
if (maxTechPauseDuration > 0) {
timeLeft = maxTechPauseDuration - g_LatestPauseDuration;
if (timeLeft == 0) {
Expand All @@ -369,14 +377,18 @@ public Action Timer_PauseTimeCheck(Handle timer) {
if (IsPlayer(i)) {
if (timeLeft >= 0) {
if (maxTechPauses > 0) {
// Team A (CT) technical pause (3/4): Time remaining before anyone can unpause: 1:30
PrintHintText(i, "%s (%s) %t (%d/%d).\n%t: %s", g_TeamNames[team], teamString, "TechnicalPauseMidSentence", techPausesUsed, maxTechPauses, "TimeRemainingBeforeAnyoneCanUnpausePrefix", timeLeftFormatted);
} else {
// Team A (CT) technical pause. Time remaining before anyone can unpause: 1:30
PrintHintText(i, "%s (%s) %t.\n%t: %s", g_TeamNames[team], teamString, "TechnicalPauseMidSentence", "TimeRemainingBeforeAnyoneCanUnpausePrefix", timeLeftFormatted);
}
} else {
if (maxTechPauses > 0) {
// Team A (CT) technical pause (3/4). Awaiting unpause.
PrintHintText(i, "%s (%s) %t (%d/%d).\n%t.", g_TeamNames[team], teamString, "TechnicalPauseMidSentence", techPausesUsed, maxTechPauses, "AwaitingUnpause");
} else {
// Team A (CT) technical pause. Awaiting unpause.
PrintHintText(i, "%s (%s) %t.\n%t.", g_TeamNames[team], teamString, "TechnicalPauseMidSentence", "AwaitingUnpause");
}
}
Expand All @@ -391,6 +403,14 @@ public Action Timer_PauseTimeCheck(Handle timer) {
}
}

} else if (g_PauseType == Get5PauseType_Backup) {

LOOP_CLIENTS(i) {
if (IsPlayer(i)) {
PrintHintText(i, "%t", "PausedForBackup");
}
}

}
return Plugin_Continue;
}
18 changes: 13 additions & 5 deletions translations/get5.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@
}
"MaxPausesUsedInfoMessage"
{
"#format" "{1:d}"
"en" "Your team has already used all tactical pauses ({1})."
"#format" "{1:d},{2:s}"
"en" "{2} has used all their tactical pauses ({1})."
}
"MaxPausesTimeUsedInfoMessage"
{
"#format" "{1:s}"
"en" "Your team has already used all tactical pause time ({1})."
"#format" "{1:s},{2:s}"
"en" "{2} has used all their tactical pause time ({1})."
}
"MatchPausedByTeamMessage"
{
"#format" "{1:N}"
"en" "{1} paused the match."
"en" "{1} has called for a tactical pause."
}
"MatchTechPausedByTeamMessage"
{
Expand Down Expand Up @@ -126,6 +126,10 @@
{
"en" "An administrator has paused the match."
}
"PausedForBackup"
{
"en" "The game was restored from a backup. Both teams must unpause to continue."
}
"PauseNotAvailable"
{
"en" "You cannot pause until the game has gone live, and only if the pausing system has been enabled."
Expand Down Expand Up @@ -282,6 +286,10 @@
"#format" "{1:s},{2:d},{3:d},{4:s}"
"en" "{LIGHT_GREEN}{1} {GREEN}{2} {NORMAL}- {GREEN}{3} {LIGHT_GREEN}{4}"
}
"StopCommandNotEnabled"
{
"en" "The stop command is not enabled."
}
"BackupLoadedInfoMessage"
{
"#format" "{1:s}"
Expand Down

0 comments on commit 003c5a6

Please sign in to comment.