Raised This Month: $12 Target: $400
 3% 

Delayed "pause" on competitive


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kevin_i
New Member
Join Date: Jul 2014
Old 07-28-2014 , 09:24   Delayed "pause" on competitive
Reply With Quote #1

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;
}
Kevin_i is offline
sinsic
Senior Member
Join Date: May 2012
Old 07-29-2014 , 01:07   Re: Delayed "pause" on competitive
Reply With Quote #2

Maybe something like this?
I'm very sleepy so there might be typos but search for "g_bLetItPause" to see what I changed.
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;
new bool:g_bLetItPause = false;

public OnPluginStart()
{
    pauseState = "live";
    AddCommandListener(Listener_Pause, "pause");
    LoadTranslations("common.phrases");
    
}

public OnMapStart()
{    
    pauseCount = 0;
}


public Action:Listener_Pause(client, const String:command[], args)
{
    if (!g_bLetItPause)
    {
        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;
        }
    } else {
        Plugin_Continue
    }
    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;
        
        g_bLetItPause = true;
        FakeClientCommand(client, "pause");
        g_bLetItPause = false;
        return Plugin_Handled;
    }
    
    return Plugin_Handled;
}
__________________

Last edited by sinsic; 07-29-2014 at 01:09.
sinsic is offline
Kevin_i
New Member
Join Date: Jul 2014
Old 07-29-2014 , 07:40   Re: Delayed "pause" on competitive
Reply With Quote #3

I made it such that the timer automatically

Code:
FakeClientCommand(client,pause)
but the thing is that this makes the command listener call itself again. Should I remove the command listener and readd it?
Kevin_i is offline
psychonic

BAFFLED
Join Date: May 2008
Old 07-29-2014 , 08:51   Re: Delayed "pause" on competitive
Reply With Quote #4

Part of your problem is that timers don't tick while the game is paused. No frames are processed.

Last edited by psychonic; 07-29-2014 at 08:52.
psychonic is offline
Kevin_i
New Member
Join Date: Jul 2014
Old 07-30-2014 , 07:57   Re: Delayed "pause" on competitive
Reply With Quote #5

ESEA has a countdown timer before the unpause actually occurs
Kevin_i is offline
psychonic

BAFFLED
Join Date: May 2008
Old 07-30-2014 , 09:29   Re: Delayed "pause" on competitive
Reply With Quote #6

I didn't say that it wasn't possible. SM timers are just bound to game frames, rather than the game's Think function. It's something that I'm looking at changing for the next major SM release.
psychonic is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode