Hi guys, I've tried making a delayed pause system where the initial pause command is rejected by the server but I can't find a way to do that. This is the code I have and the problem is that the code calls itself back since I am hooking onto that event.
Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>
#pragma semicolon 1
public Plugin:myinfo =
{
name = "Kei Improved Pause",
author = "Kei and Rubiksguy890",
description = "Improved Pause",
version = "1.0.0.0",
}
new pauseCount;
new String:pauseState[32];
new Handle:g_currentCounter = INVALID_HANDLE;
new maxPauseCount = 3;
public OnPluginStart()
{
pauseState = "live";
AddCommandListener(Listener_Pause, "pause");
LoadTranslations("common.phrases");
}
public OnMapStart()
{
pauseCount = 0;
}
public Action:Listener_Pause(client, const String:command[], args)
{
new String:client_name[32];
GetClientName(client, client_name, sizeof(client_name));
if (StrEqual(pauseState, "unpausing") || pauseCount == maxPauseCount)
{
PrintToChat(client, "\x04[\x01R890\x04]\x01 Cannot Pause.");
return Plugin_Handled;
}
else if (StrEqual(pauseState, "live") && pauseCount < maxPauseCount)
{
PrintToChatAll("\x04[\x01R890\x04] %s \x01has paused the game", client_name);
pauseState = "paused";
pauseCount += 1;
FakeClientCommand(client,"pause");
return Plugin_Handled;
}
else if (StrEqual(pauseState,"paused"))
{
PrintToChatAll("\x04[\x01R890\x04] %s \x01is unpausing the game", client_name);
pauseState = "unpausing";
//ServerCommand("sm_start");
if (g_currentCounter != INVALID_HANDLE)
{
return Plugin_Handled;
}
g_currentCounter = CreateTimer(1.0, CountdownTimer, client, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
pauseState = "live";
return Plugin_Handled;
}
return Plugin_Handled;
}
public Action:CountdownTimer(Handle:timer, any:client)
{
static timePassed;
new timeRemaining = 5 - timePassed;
PrintToChatAll("\x04[\x01R890\x04] %d \x01seconds till unpause", timeRemaining);
if (timePassed++ >= 5)
{
g_currentCounter = INVALID_HANDLE;
timePassed = 0;
FakeClientCommand(client, "pause");
return Plugin_Handled;
}
return Plugin_Handled;
}