Skip to content

Commit

Permalink
Ensure unpausing when loading a match
Browse files Browse the repository at this point in the history
Create timer for displaying admin pause info
Refactored translations and removed redundant chat-text
  • Loading branch information
nickdnk committed Jul 25, 2022
1 parent 275d4ab commit 90e3f6c
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 329 deletions.
4 changes: 4 additions & 0 deletions scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ stock bool LoadMatchConfig(const char[] config, bool restoreBackup = false) {
ExecuteMatchConfigCvars();
LoadPlayerNames();
EnsureIndefiniteWarmup();
if (IsPaused()) {
LogDebug("Match was paused when loading match config. Unpausing.");
UnpauseGame(Get5Team_None);
}

Stats_InitSeries();

Expand Down
117 changes: 65 additions & 52 deletions scripting/get5/pausing.sp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public Action Command_TechPause(int client, int args) {
}

if (g_PausingTeam != Get5Team_None) {
LogDebug("Ignoring technical pause request as game is already paused.");
if (g_PauseType == Get5PauseType_Tech) {
g_TeamReadyForUnpause[team] = false;
LogDebug("Ignoring tech pause request as game is already tech paused; setting team to not ready to unpause.");
}
return Plugin_Handled;
}

Expand All @@ -110,7 +113,7 @@ public Action Command_TechPause(int client, int args) {

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

Get5_MessageToAll("%t", "MatchTechPausedByTeamMessage", client);
if (maxTechPauses > 0) {
Expand All @@ -126,6 +129,11 @@ 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 @@ -137,55 +145,43 @@ public Action Command_Pause(int client, int args) {
}

if (g_PausingTeam != Get5Team_None) {
// A team has already requested a pause, so in this case we just indicate that this team is not ready to unpause
// on its own.
g_TeamReadyForUnpause[team] = false;
LogDebug("Ignoring tactical pause request as game is already paused; setting team to not ready to unpause.");
if (g_PauseType == Get5PauseType_Tactical) {
g_TeamReadyForUnpause[team] = false;
LogDebug("Ignoring tactical pause request as game is already tactically paused; setting team to not ready to unpause.");
}
return Plugin_Handled;
}

int maxPauses = g_MaxTacticalPausesCvar.IntValue;
char pausePeriodString[32];
if (g_ResetPausesEachHalfCvar.BoolValue) {
Format(pausePeriodString, sizeof(pausePeriodString), " %t", "PausePeriodSuffix");
}

if (!g_FixedPauseTimeCvar.BoolValue) {
int maxPauseTime = g_MaxPauseTimeCvar.IntValue;
if (maxPauseTime > 0 && g_TacticalPauseTimeUsed[team] >= maxPauseTime && IsPlayerTeam(team)) {
Get5_Message(client, "%t", "MaxPausesTimeUsedInfoMessage", maxPauseTime, pausePeriodString);

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

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

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

if (IsPlayer(client)) {
Get5_MessageToAll("%t", "MatchPausedByTeamMessage", client);
}

pausePeriodString = "";
if (g_ResetPausesEachHalfCvar.BoolValue) {
Format(pausePeriodString, sizeof(pausePeriodString), " %t", "PausePeriodSuffix");
}

if (maxPauses > 0) {
int pausesLeft = maxPauses - g_TacticalPausesUsed[team];
if (pausesLeft >= 0) {
if (pausesLeft == 1) {
Get5_MessageToAll("%t", "OnePauseLeftInfoMessage", g_FormattedTeamNames[team], pausesLeft,
pausePeriodString);
} else {
Get5_MessageToAll("%t", "PausesLeftInfoMessage", g_FormattedTeamNames[team], pausesLeft,
pausePeriodString);
}
Get5_MessageToAll("%t", "PausesLeftInfoMessage", g_FormattedTeamNames[team], pausesLeft);
}
}
return Plugin_Handled;
Expand Down Expand Up @@ -247,7 +243,15 @@ public Action Command_Unpause(int client, int args) {
return Plugin_Handled;
}

public Action Timer_PauseTimeCheck(Handle timer, Get5Team team) {
public Action Timer_PauseTimeCheck(Handle timer) {
if (g_PauseType == Get5PauseType_None) {
LogDebug("Stopping pause timer as pause type was none.");
return Plugin_Stop;
}

// Shorter local variable because g_PausingTeam for the rest of the code was just too much.
Get5Team team = g_PausingTeam;

if (!Pauseable() || !IsPaused()) {
// Pause time is max per pause, so we reset that timer every time a pause ends.
g_TechnicalPauseTimeUsed[team] = 0;
Expand Down Expand Up @@ -276,11 +280,6 @@ public Action Timer_PauseTimeCheck(Handle timer, Get5Team team) {
// -1 assumes unlimited.
int timeLeft = -1;

char pausePeriodString[32];
if (g_ResetPausesEachHalfCvar.BoolValue) {
Format(pausePeriodString, sizeof(pausePeriodString), " %t", "PausePeriodSuffix");
}

if (fixedPauseTime > 0) {
g_LatestFixedPauseDuration++;
LogDebug("Incrementing fixed-time tactical pause timer. Now: %d", g_LatestFixedPauseDuration);
Expand All @@ -301,11 +300,6 @@ public Action Timer_PauseTimeCheck(Handle timer, Get5Team team) {
Get5_MessageToAll("%t", "PauseRunoutInfoMessage", g_FormattedTeamNames[team]);
UnpauseGame(team);
return Plugin_Stop;
} else if (timeLeft == 10) {
Get5_MessageToAll("%t", "PauseTimeExpiration10SecInfoMessage", g_FormattedTeamNames[team]);
} else if (timeLeft % 30 == 0) {
Get5_MessageToAll("%t", "PauseTimeExpirationInfoMessage", g_FormattedTeamNames[team],
timeLeft, pausePeriodString);
}
}
}
Expand All @@ -316,25 +310,40 @@ public Action Timer_PauseTimeCheck(Handle timer, Get5Team team) {
convertSecondsToMinutesAndSeconds(timeLeft, timeLeftFormatted, sizeof(timeLeftFormatted));
}

char pauseTimeMaxFormatted[16] = "";
if (timeLeft >= 0) {
convertSecondsToMinutesAndSeconds(maxTacticalPauseTime, pauseTimeMaxFormatted, sizeof(pauseTimeMaxFormatted));
}

LOOP_CLIENTS(i) {
if (IsPlayer(i)) {
if (fixedPauseTime) { // If fixed pause; takes precedence over total time and reuses timeLeft for simplicity
if (maxTacticalPauses > 0) {
PrintHintText(i, "%t", "TacticalFixedPauseTimeWithCountStatus", g_TeamNames[team], teamString, tacticalPausesUsed, maxTacticalPauses, timeLeftFormatted);
// Team A (CT) tactical pause (2/4): 0:45
PrintHintText(i, "%s (%s) %t (%d/%d): %s", g_TeamNames[team], teamString, "TacticalPauseMidSentence", tacticalPausesUsed, maxTacticalPauses, timeLeftFormatted);
} else {
PrintHintText(i, "%t", "TacticalFixedPauseTimeStatus", g_TeamNames[team], teamString, timeLeftFormatted);
// Team A (CT) tactical pause: 0:45
PrintHintText(i, "%s (%s) %t: %s", g_TeamNames[team], teamString, "TacticalPauseMidSentence", timeLeftFormatted);
}
} else if (timeLeft >= 0) { // If total time restriction
if (maxTacticalPauses > 0) {
PrintHintText(i, "%t", "TacticalPauseTimeRemainingWithCountStatus", g_TeamNames[team], teamString, tacticalPausesUsed, maxTacticalPauses, timeLeftFormatted);
// Team A (CT) tactical pause (2/4).
// Remaining pause time: 0:45 / 3:00
PrintHintText(i, "%s (%s) %t (%d/%d).\n%t: %s / %s", g_TeamNames[team], teamString, "TacticalPauseMidSentence", tacticalPausesUsed, maxTacticalPauses, "PauseTimeRemainingPrefix", timeLeftFormatted, pauseTimeMaxFormatted);
} else {
PrintHintText(i, "%t", "TacticalPauseTimeRemainingStatus", g_TeamNames[team], teamString, timeLeftFormatted);
// Team A (CT) tactical pause.
// Remaining pause time: 0:45 / 3:00
PrintHintText(i, "%s (%s) %t.\n%t: %s / %s", g_TeamNames[team], teamString, "TacticalPauseMidSentence", "PauseTimeRemainingPrefix", timeLeftFormatted, pauseTimeMaxFormatted);
}
} else { // if no time restriction
} else { // if no time restriction or awaiting unpause
if (maxTacticalPauses > 0) {
PrintHintText(i, "%t", "TacticalPauseUnlimitedWithCountStatus", g_TeamNames[team], teamString, tacticalPausesUsed, maxTacticalPauses);
// Team A (CT) tactical pause (2/4).
// Awaiting unpause.
PrintHintText(i, "%s (%s) %t (%d/%d).\n%t.", g_TeamNames[team], teamString, "TacticalPauseMidSentence", tacticalPausesUsed, maxTacticalPauses, "AwaitingUnpause");
} else {
PrintHintText(i, "%t", "TacticalPauseUnlimitedStatus", g_TeamNames[team], teamString);
// Team A (CT) tactical pause.
// Awaiting unpause.
PrintHintText(i, "%s (%s) %t.\n%t.", g_TeamNames[team], teamString, "TacticalPauseMidSentence", "AwaitingUnpause");
}
}
}
Expand All @@ -358,11 +367,6 @@ public Action Timer_PauseTimeCheck(Handle timer, Get5Team team) {
// Tech pauses don't unpause on their own. They just let anyone unpause after the time expires.
Get5_MessageToAll("%t", "TechPauseRunoutInfoMessage");
return Plugin_Stop;
} else if (timeLeft >= 60 && timeLeft % 60 == 0) {
timeLeft = timeLeft / 60;
Get5_MessageToAll("%t", "TechPauseTimeRemainingMinutes", timeLeft);
} else if (timeLeft <= 30 && (timeLeft % 30 == 0 || timeLeft == 10)) {
Get5_MessageToAll("%t", "TechPauseTimeRemaining", timeLeft);
}
}
}
Expand All @@ -377,19 +381,28 @@ public Action Timer_PauseTimeCheck(Handle timer, Get5Team team) {
if (IsPlayer(i)) {
if (timeLeft >= 0) {
if (maxTechPauses > 0) {
PrintHintText(i, "%t", "TechnicalPauseTimeRemainingWithCountStatus", g_TeamNames[team], teamString, techPausesUsed, maxTechPauses, timeLeftFormatted);
PrintHintText(i, "%s (%s) %t (%d/%d).\n%t: %s", g_TeamNames[team], teamString, "TechnicalPauseMidSentence", techPausesUsed, maxTechPauses, "TimeRemainingBeforeAnyoneCanUnpausePrefix", timeLeftFormatted);
} else {
PrintHintText(i, "%t", "TechnicalPauseTimeRemainingStatus", g_TeamNames[team], teamString, timeLeftFormatted);
PrintHintText(i, "%s (%s) %t.\n%t: %s", g_TeamNames[team], teamString, "TechnicalPauseMidSentence", "TimeRemainingBeforeAnyoneCanUnpausePrefix", timeLeftFormatted);
}
} else {
if (maxTechPauses > 0) {
PrintHintText(i, "%t", "TechnicalPauseUnlimitedWithCountStatus", g_TeamNames[team], teamString, techPausesUsed, maxTechPauses);
PrintHintText(i, "%s (%s) %t (%d/%d).\n%t.", g_TeamNames[team], teamString, "TechnicalPauseMidSentence", techPausesUsed, maxTechPauses, "AwaitingUnpause");
} else {
PrintHintText(i, "%t", "TechnicalPauseUnlimitedStatus", g_TeamNames[team], teamString);
PrintHintText(i, "%s (%s) %t.\n%t.", g_TeamNames[team], teamString, "TechnicalPauseMidSentence", "AwaitingUnpause");
}
}
}
}

} else if (g_PauseType == Get5PauseType_Admin) {

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

}
return Plugin_Continue;
}
22 changes: 3 additions & 19 deletions translations/chi/get5.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,13 @@
{
"chi" "{1}有10秒的时间来准备就绪,否则将被视为放弃比赛。"
}
"PausePeriodSuffix"
{
"chi" "于这个半场"
}
"MaxPausesUsedInfoMessage"
{
"chi" "您的队伍已经使用了最大为{1}次的暂停次数{2}。"
"chi" "您的队伍已经使用了最大为{1}次的暂停次数。"
}
"MaxPausesTimeUsedInfoMessage"
{
"chi" "您的队伍已经使用了最大为{1}秒的暂停时间{2}。"
"chi" "您的队伍已经使用了最大为{1}秒的暂停时间。"
}
"MatchPausedByTeamMessage"
{
Expand All @@ -84,14 +80,6 @@
{
"chi" "{1}要求发起一个技术暂停。"
}
"PauseTimeExpiration10SecInfoMessage"
{
"chi" "{1}的暂停时间即将耗尽,将在10秒后解除暂停。"
}
"PauseTimeExpirationInfoMessage"
{
"chi" "{1}剩余{2}秒的暂停时间{3}。"
}
"PauseRunoutInfoMessage"
{
"chi" "{1}的暂停时间已经耗尽,已解除比赛的暂停。"
Expand All @@ -106,11 +94,7 @@
}
"PausesLeftInfoMessage"
{
"chi" "{1}剩余{2}次pauses暂停次数{3}。"
}
"OnePauseLeftInfoMessage"
{
"chi" "{1}剩余{2}次pauses暂停次数{3}。"
"chi" "{1}剩余{2}次pauses暂停次数。"
}
"TeamFailToReadyMinPlayerCheck"
{
Expand Down
Loading

0 comments on commit 90e3f6c

Please sign in to comment.