So I needed a server pause command for my for my updated warmod plugin. Located here:
https://forums.alliedmods.net/showthread.php?t=225474
There is a built in pause command in CS:GO which is "rcon pause". This will pause the server if you have rcon. What I'm trying to do is make it possible for teams to execute this command.
What the Pause function needs to do:
- Option to pause at freeze time only
- Option to limit teams to certain amount of pauses per half
- Auto unpause after certain amount of time
- Option that pause will only work with both teams typing !pause
- Unpause with both teams typing !unpause
Slowly working through creating it here. Just working on the /pause command first and then adding the unpause after that. [learning how to code for sourcemod]
PHP Code:
#include <sourcemod>
new bool:g_pause_freezetime = false;
new bool:g_pause_offered_t = false;
new bool:g_pause_offered_ct = false;
new bool:g_paused = false;
new Handle:sv_pausable;
new Handle:g_h_auto_unpause = INVALID_HANDLE;
new Handle:g_h_auto_unpause_delay = INVALID_HANDLE;
new Handle:g_h_pause_freezetime = INVALID_HANDLE;
new Handle:g_h_pause_comfirm = INVALID_HANDLE;
new Handle:g_h_pause_limit = INVALID_HANDLE;
new Handle:g_h_t_pause_count = INVALID_HANDLE;
new Handle:g_h_ct_pause_count = INVALID_HANDLE;
new Handle:g_h_stored_timer = INVALID_HANDLE;
public OnPluginStart()
{
// Add your own code here...
sv_pausable = FindConVar ("sv_pausable");
g_h_pause_comfirm = CreateConVar("wm_pause_comfirm", "1", "Wait for other team to comfirm pause: 0 = off, 1 = on", FCVAR_NOTIFY);
g_h_auto_unpause = CreateConVar("wm_auto_unpause", "0", "Sets auto unpause: 0 = off, 1 = on", FCVAR_NOTIFY);
g_h_pause_freezetime = CreateConVar("wm_pause_freezetime", "1", "Wait for freeze time to pause: 0 = off, 1 = on", FCVAR_NOTIFY);
g_h_auto_unpause_delay = CreateConVar("wm_auto_unpause_delay", "180", "Sets the seconds to wait before auto unpause", FCVAR_NOTIFY, true, 0.0);
g_h_pause_limit = CreateConVar("wm_pause_limit", "1", "Sets max pause count per team per half", FCVAR_NOTIFY);
g_h_t_pause_count = CreateConVar("wm_t_pause_count", "0", "WarMod automatically updates this value to the Terrorist's total pause count", FCVAR_NOTIFY);
g_h_ct_pause_count = CreateConVar("wm_ct_pause_count", "0", "WarMod automatically updates this value to the Counter-Terrorist's total pause count", FCVAR_NOTIFY);
HookEvent("round_start", Event_round_start);
}
public Event_round_start(Handle: event , const String: name[] , bool: dontBroadcast)
{
if (g_pause_freezetime == true)
{
g_pause_freezetime = false;
if(GetConVarBool(g_h_auto_unpause))
{
PrintToChatAll("Game will auto unpause after %s seconds", g_h_auto_unpause_delay);
g_h_stored_timer = CreateTimer(GetConVarFloat(g_h_auto_unpause_delay), UnPauseTimer);
}
g_paused = true;
ServerCommand("pause");
}
}
//thanks to xf117 for this =D
stock PrintToConsoleAll(const String:message[]) {
for (new i = 1; i <= MaxClients; i++) {
PrintToConsole(i, message);
}
}
public Action:Pause(client, args)
{
if (GetConVarBool(sv_pausable))
{
if (GetConVarBool(g_h_pause_comfirm))
{
if (GetClientTeam(client) == 3 && g_h_ct_pause_count != g_h_pause_limit)
{
g_pause_offered_ct = true;
PrintToChatAll("CT have asked for a Pause. Please type !pause to pause the match.");
g_h_stored_timer = CreateTimer(30.0, PauseTimeout);
}
if (GetClientTeam(client) == 2 && g_h_ct_pause_count != g_h_pause_limit)
{
g_pause_offered_t = true;
PrintToChatAll("T have asked for a Pause. Please type !pause to pause the match.");
g_h_stored_timer = CreateTimer(30.0, PauseTimeout);
}
if (GetClientTeam(client) == 2 && g_pause_offered_ct == true)
{
if(g_h_stored_timer != INVALID_HANDLE)
{
KillTimer(g_h_stored_timer);
g_h_stored_timer = INVALID_HANDLE;
}
g_pause_offered_ct = false;
g_h_ct_pause_count++;
if (GetConVarBool(g_h_pause_freezetime))
{
PrintToChatAll("Game will pause at the end of the round");
g_pause_freezetime = true;
}
else
{
PrintToChatAll("Game is Paused. Please type !unpause to unpause the game.");
if (GetConVarBool(g_h_auto_unpause))
{
PrintToChatAll("Game will auto unpause after %s seconds", g_h_auto_unpause_delay);
g_h_stored_timer = CreateTimer(GetConVarFloat(g_h_auto_unpause_delay), UnPauseTimer);
}
g_paused = true;
ServerCommand("pause");
}
}
if (GetClientTeam(client) == 3 && g_pause_offered_t == true)
{
if(g_h_stored_timer != INVALID_HANDLE)
{
KillTimer(g_h_stored_timer);
g_h_stored_timer = INVALID_HANDLE;
}
g_pause_offered_t = false;
g_h_t_pause_count++;
if (GetConVarBool(g_h_pause_freezetime))
{
PrintToChatAll("Game will pause at the end of the round");
g_pause_freezetime = true;
}
else
{
PrintToChatAll("Game is Paused. Please type !unpause to unpause the game.");
if (GetConVarBool(g_h_auto_unpause))
{
PrintToChatAll("Game will auto unpause after %s seconds", g_h_auto_unpause_delay);
g_h_stored_timer = CreateTimer(GetConVarFloat(g_h_auto_unpause_delay), UnPauseTimer);
}
g_paused = true;
ServerCommand("pause");
}
}
if (GetClientTeam(client) == 2 && g_h_t_pause_count == g_h_pause_limit)
{
PrintToChat(client, "You have used your pause limit already");
}
if (GetClientTeam(client) == 3 && g_h_ct_pause_count == g_h_pause_limit)
{
PrintToChat(client, "You have used your pause limit already");
}
if (GetClientTeam(client) < 2 )
{
PrintToChat(client, "You must be on T or CT to enable !pause");
}
}
if (GetClientTeam(client) == 3 && g_h_ct_pause_count != g_h_pause_limit && !GetConVarBool(g_h_pause_comfirm))
{
g_h_ct_pause_count++;
if (GetConVarBool(g_h_pause_freezetime))
{
PrintToChatAll("Game will pause at the end of the round");
g_pause_freezetime = true;
}
else
{
PrintToChatAll("Game is Paused. Please type !unpause to unpause the game.");
if(GetConVarBool(g_h_auto_unpause))
{
PrintToChatAll("Game will auto unpause after %s seconds", g_h_auto_unpause_delay);
g_h_stored_timer = CreateTimer(GetConVarFloat(g_h_auto_unpause_delay), UnPauseTimer);
}
g_paused = true;
ServerCommand("pause");
}
}
if (GetClientTeam(client) == 2 && g_h_t_pause_count != g_h_pause_limit && !GetConVarBool(g_h_pause_comfirm))
{
g_h_t_pause_count++;
if (GetConVarBool(g_h_pause_freezetime))
{
PrintToChatAll("Game will pause at the end of the round");
g_pause_freezetime = true;
}
else
{
PrintToChatAll("Game is Paused. Please type !unpause to unpause the game.");
if(GetConVarBool(g_h_auto_unpause))
{
PrintToChatAll("Game will auto unpause after %s seconds", g_h_auto_unpause_delay);
g_h_stored_timer = CreateTimer(GetConVarFloat(g_h_auto_unpause_delay), UnPauseTimer);
}
g_paused = true;
ServerCommand("pause");
}
}
if (GetClientTeam(client) == 2 && g_h_t_pause_count == g_h_pause_limit)
{
PrintToChat(client, "You have used your pause limit already");
}
if (GetClientTeam(client) == 3 && g_h_ct_pause_count == g_h_pause_limit)
{
PrintToChat(client, "You have used your pause limit already");
}
if (GetClientTeam(client) < 2)
{
PrintToChat(client, "must be on T or CT to enable !pause");
}
}
else
{
PrintToChatAll("sv_pauseable is set to 0. Pause fuction not enabled");
}
}
public Action:UnPause(client, args)
{
if (g_paused)
{
if (GetConVarBool(g_h_pause_comfirm))
{
if (GetClientTeam(client) == 3 && g_pause_offered_ct == false && g_pause_offered_t == false)
{
g_pause_offered_ct = true;
PrintToConsoleAll("CT have asked to unpause the game. Please type /unpause to unpause the match.");
}
if (GetClientTeam(client) == 2 && g_pause_offered_t == false && g_pause_offered_ct == false)
{
g_pause_offered_t = true;
PrintToConsoleAll("T have asked to unpause the game. Please type /unpause to unpause the match.");
}
if (GetClientTeam(client) == 2 && g_pause_offered_ct == true)
{
g_pause_offered_ct = false;
g_paused = false;
ServerCommand("unpause");
}
if (GetClientTeam(client) == 3 && g_pause_offered_t == true)
{
g_pause_offered_t = false;
g_paused = false;
ServerCommand("unpause");
}
if (GetClientTeam(client) < 2 )
{
PrintToConsole(client, "You must be on T or CT to enable /unpause");
}
}
else
{
if (GetClientTeam(client) == 2)
{
PrintToChatAll("T have unpaused the match");
g_paused = false;
ServerCommand("unpause");
}
if (GetClientTeam(client) == 3)
{
PrintToChatAll("T have unpaused the match");
g_paused = false;
ServerCommand("unpause");
}
if (GetClientTeam(client) < 2 )
{
PrintToConsole(client, "You must be on T or CT to enable /unpause");
}
}
}
else
{
PrintToChat(client,"Server is not paused or was paused via rcon.");
PrintToConsole(client,"Server is not paused or was paused via rcon.");
}
}
//thanks to thetwistedpanda for the timers help =D
public Action:PauseTimeout(Handle:timer)
{
g_h_stored_timer = INVALID_HANDLE;
PrintToChatAll("!pause offer was not comfirmed by the other team.");
g_pause_offered_ct = false;
g_pause_offered_t = false;
}
public Action:UnPauseTimer(Handle:timer)
{
g_h_stored_timer = INVALID_HANDLE;
PrintToChatAll("Auto Unpaused!");
ServerCommand("unpause");
g_pause_offered_ct = false;
g_pause_offered_t = false;
}
__________________