Raised This Month: $32 Target: $400
 8% 

[CSGO] !Pause command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-08-2013 , 22:31   [CSGO] !Pause command
Reply With Quote #1

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_NOTIFYtrue0.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(Handleevent , const Stringname[] , booldontBroadcast)
{
    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 
1<= MaxClientsi++) {
        
PrintToConsole(imessage);
    }

public 
Action:Pause(clientargs)
{
    if (
GetConVarBool(sv_pausable))
    {
        if (
GetConVarBool(g_h_pause_comfirm))
        {
            if (
GetClientTeam(client) == && 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.0PauseTimeout);
            }
            if (
GetClientTeam(client) == && 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.0PauseTimeout);
            }
            if (
GetClientTeam(client) == && 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) == && 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) == && g_h_t_pause_count == g_h_pause_limit)
            {
                
PrintToChat(client"You have used your pause limit already");
            }
            if (
GetClientTeam(client) == && g_h_ct_pause_count == g_h_pause_limit)
            {
                
PrintToChat(client"You have used your pause limit already");
            }
            if (
GetClientTeam(client) < )
            {
                
PrintToChat(client"You must be on T or CT to enable !pause");
            }
        }
        if (
GetClientTeam(client) == && 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) == &&  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) == && g_h_t_pause_count == g_h_pause_limit)
        {
            
PrintToChat(client"You have used your pause limit already");
        }
        if (
GetClientTeam(client) == && 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(clientargs)
{
    if (
g_paused)
    {
        if (
GetConVarBool(g_h_pause_comfirm))
        {
            if (
GetClientTeam(client) == && 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) == && 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) == && g_pause_offered_ct == true)
            {
                
g_pause_offered_ct false;
                
g_paused false;
                
ServerCommand("unpause");
            }
            if (
GetClientTeam(client) == && g_pause_offered_t == true)
            {
                
g_pause_offered_t false;
                
g_paused false;
                
ServerCommand("unpause");
            }
            if (
GetClientTeam(client) < )
            {
                
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) < )
            {
                
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;

__________________

Last edited by versatile_bfg; 09-22-2013 at 21:47.
versatile_bfg is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-10-2013 , 22:01   Re: [Paid] [CSGO] !Pause command
Reply With Quote #2

How would you execute a command when freeze time starts? Would you do it by adding a switch like set g_pause_freezetime = 1. Then on the event have something like:

Couldn't find the event when freeze time starts so end of round will do.

PHP Code:
public Event_round_end(Handleevent , const Stringname[] , booldontBroadcast)
{
    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);
            
CreateTimer(30.0UnPauseTimer);
        }
        
ServerCommand("pause");
    }

__________________

Last edited by versatile_bfg; 09-18-2013 at 00:51.
versatile_bfg is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-18-2013 , 00:55   Re: [CSGO] !Pause command
Reply With Quote #3

I'm getting a warning for the two "KillTimer(PauseTimeout);" Warning 213: tag mismatch

Not sure how to use the kill timer command works. I haven't added the unpause part yet but it is looking good to me at the moment. Only these 2 warnings popping up at the moment.

Oh and for the timers how do you make the time in the timer different via a cvar?
__________________

Last edited by versatile_bfg; 09-18-2013 at 00:58.
versatile_bfg is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 09-18-2013 , 01:00   Re: [CSGO] !Pause command
Reply With Quote #4

CreateTimer() returns a Handle, that's what you save and use CloseHandle/KillTimer on. g_hDatTimerHandle = CreateTimer(...); KillTimer(g_hDatTimerHandle).

And you can only change the time of the timer when calling it, so if you want it to be variable, something like this would suffice:
CreateTimer(GetRandomFloat(1.0, 30.0), Timer_DatTimer);
DatTimer(Handle:timer)
{
CreateTimer(GetRandomFloat(1.0, 30.0), Timer_DatTimer);
}
__________________
thetwistedpanda is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-18-2013 , 01:33   Re: [CSGO] !Pause command
Reply With Quote #5

This handle will have the stored time. Will I need to change it to something else if I want to be able to kill it?

PHP Code:
public OnPluginStart()
{
g_h_auto_unpause_delay CreateConVar("wm_auto_unpause_delay""180""Sets the seconds to wait before auto unpause"FCVAR_NOTIFYtrue0.0);
}

public 
Action:Pause(clientargs)
{
   if (
blah blah)
   {
        
g_h_auto_unpause_delay CreateTimer(GetRandomFloat(1.0,30.0), UnPauseTimer);
// where would "wm_auto_unpause_delay or g_h_auto_unpause_delay" go? Should it have a different handle at the front other than g_h_auto_unpause_delay?
    
}
    if (
blah blah blah)
    {
        
KillTimer(g_h_auto_unpause_delay);
    }
}

//so this shouldn't be a public Action:? well looking at it now seems it shouldn't be. 
UnPauseTimer(Handle:timer)
{
    
CreateTimer(GetRandomFloat(1.0,30.0), UnPauseTimer);
//dont think this should be here but what I get from your example it looks like it is?

//other commands to execute with timer
    
PrintToChatAll("Auto Unpaused!");
    
ServerCommand("unpause");
    
g_pause_offered_ct false;
    
g_pause_offered_t false;

__________________
versatile_bfg is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 09-18-2013 , 01:38   Re: [CSGO] !Pause command
Reply With Quote #6

You'd want something like:
PHP Code:
new Handle:g_hStoredTimer INVALID_HANDLE;

public 
Action:Pause(clientargs

if(
blah blah)
g_hStoredTimer CreateTimer(GetConVarFloat(g_h_auto_unpause_delay), UnPauseTimer);
if(
blah blah blah && g_hStoredTimer != INVALID_HANDLE)
KillTimer(g_hStoredTimer);
g_hStoredTimer INVALID_HANDLE;
}

public 
Action:UnPauseTimer(Handle:timer)
{
g_hStoredTimer INVALID_HANDLE;
//You're unpausing so you won't need to re-call the pause.

return Plugin_Continue;

__________________

Last edited by thetwistedpanda; 09-18-2013 at 02:16. Reason: updated
thetwistedpanda is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-18-2013 , 02:15   Re: [CSGO] !Pause command
Reply With Quote #7

alright sweet. edited op with new code. Now I just need to add unpause code. =D Thanks heaps @thetwistedpanda
__________________
versatile_bfg is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 09-18-2013 , 02:17   Re: [CSGO] !Pause command
Reply With Quote #8

I derped; you'd want to set g_hStoredTimer back to INVALID_HANDLE after you Kill/Close it.
__________________
thetwistedpanda is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-18-2013 , 02:18   Re: [CSGO] !Pause command
Reply With Quote #9

true that. haha will add now cheers
__________________
versatile_bfg is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-19-2013 , 07:19   Re: [CSGO] !Pause command
Reply With Quote #10

One last thing. How do you print to console. I want to print to everyone's console that is in the game. Not when they join but when someone says /unpause.

PrintToConsole("T have asked to unpause the game. Please type /unpause to unpause the match.");
This wont work and PrintToConsoleAll() doesnt work either =( It needs to come to console as the server is paused and will not show in chat.
__________________
versatile_bfg 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 17:29.


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