Thread: [Solved] Pause plugin
View Single Post
SmokieCS
AlliedModders Donor
Join Date: Nov 2019
Location: Denmark
Old 01-07-2022 , 13:31   Re: Pause plugin
Reply With Quote #11

Solved.

With the comment above it made me look everything up and finally fix the coding to be fairly simple and use the built-in timeout feature.

Code:
PHP Code:
#pragma semicolon 1
#include <cstrike>
#include <sourcemod>
#include <sdktools>
#include <colors>

public Plugin:myinfo = {
    
name "CS:GO Pause Commands",
    
author "splewis & ^kS",
    
description "Adds simple pause/unpause commands for players",
};

public 
void OnPluginStart() {
    
/** Load Translations **/
    
LoadTranslations("pauseplugin.phrases");
    
    
/** Admin Commands **/
    
RegAdminCmd("sm_forcetechpause"Command_ForceTechPauseADMFLAG_GENERIC"Forces a technical pause");
    
RegAdminCmd("sm_forcetechnical"Command_ForceTechPauseADMFLAG_GENERIC"Forces a technical pause");
    
RegAdminCmd("sm_ftech"Command_ForceTechPauseADMFLAG_GENERIC"Forces a technical pause");
    
RegAdminCmd("sm_ftec"Command_ForceTechPauseADMFLAG_GENERIC"Forces a technical pause");
    
RegAdminCmd("sm_ft"Command_ForceTechPauseADMFLAG_GENERIC"Forces a technical pause");
    
RegAdminCmd("sm_forcepause"Command_ForcePauseADMFLAG_GENERIC"Forces a pause");
    
RegAdminCmd("sm_fp"Command_ForcePauseADMFLAG_GENERIC"Forces a pause");
    
RegAdminCmd("sm_forceunpause"Command_ForceUnpauseADMFLAG_GENERIC"Forces an unpause");
    
RegAdminCmd("sm_fup"Command_ForceUnpauseADMFLAG_GENERIC"Forces an unpause");
   
    
/** Pause Commands **/
    
RegConsoleCmd("sm_pause"Command_Pause"Requests a pause");
    
RegConsoleCmd("sm_p"Command_Pause"Requests a pause");
    
RegConsoleCmd("sm_tac"Command_Pause"Requests a pause");
    
RegConsoleCmd("sm_tactical"Command_Pause"Requests a pause");

    
/** Technical Pause Commands **/
    
RegConsoleCmd("sm_tech"Command_TechPause"Calls for a tech pause");
    
RegConsoleCmd("sm_t"Command_TechPause"Requests a pause");

    
/** Unpause Commands **/
    
RegConsoleCmd("sm_unpause"Command_Unpause"Requests an unpause");
    
RegConsoleCmd("sm_up"Command_Unpause"Requests an unpause");
}

    
/** Technical Pause Commands **/
    
RegConsoleCmd("sm_tech"Command_TechPause"Calls for a tech pause");
    
RegConsoleCmd("sm_t"Command_TechPause"Requests a pause");

    
/** Unpause Commands **/
    
RegConsoleCmd("sm_unpause"Command_TechUnpause"Requests an unpause");
    
RegConsoleCmd("sm_up"Command_TechUnpause"Requests an unpause");
}

/** Force Tech Pause **/
public Action Command_ForceTechPause(int clientint args){
    if (
IsPaused())
        return 
Plugin_Handled;

    
ServerCommand("mp_pause_match");
    
PrintToChatAll("%t""ForceTechPauseMessage"client);
    return 
Plugin_Handled;
}

/** Force Pause **/
public Action Command_ForcePause(int clientint args) {
    if (
IsPaused())
        return 
Plugin_Handled;

    
ServerCommand("mp_pause_match");
    
PrintToChatAll("%t""ForcePause"client);
    return 
Plugin_Handled;
}

/** Force Unpause **/
public Action Command_ForceUnpause(int clientint args) {
    if (!
IsPaused())
        return 
Plugin_Handled;
    
    
ServerCommand("mp_unpause_match");
    
PrintToChatAll("%t""ForceUnpause"client);
    return 
Plugin_Handled;
}

/** Technical Pause **/
public Action Command_TechPause(int clientint args){
    if (
IsPaused())
        return 
Plugin_Handled;

    
ServerCommand("mp_pause_match");
    
PrintToChatAll("%t""TechPauseMessage"clientclient);
    return 
Plugin_Handled;
}

/** Technical Unpause **/
public Action Command_TechUnpause(int clientint args){
    if (!
IsPaused())
        return 
Plugin_Handled;

    
ServerCommand("mp_unpause_match");
    
PrintToChatAll("%t""TechUnpauseMessage"clientclient);
    return 
Plugin_Handled;
}

/** Pause Command **/
public Action Command_Pause(int clientint args)
{
    if (
IsPaused() || !IsValidClient(client))
    {
        
// Is the game paused or is the client invalid? Terminate process.
        
return Plugin_Handled;
    }

    if(
GetClientTeam(client) == CS_TEAM_T)
    {
        
ServerCommand("timeout_terrorist_start");
        
PrintToChatAll("%t""Pause"client);
        
        return 
Plugin_Handled;
    }
    
    else if(
GetClientTeam(client) == CS_TEAM_CT)
    {
        
ServerCommand("timeout_ct_start");
        
PrintToChatAll("%t""Pause"client);
        
        return 
Plugin_Handled;
    }

    return 
Plugin_Continue;
}        

/** Valid client state **/
stock bool:IsValidClient(client
{
    if (
client && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
        return 
true;
    return 
false;
}

/** IsPaused state **/
stock bool:IsPaused() 
{
    return 
bool:GameRules_GetProp("m_bMatchWaitingForResume");

Thanks for the help everyone!
__________________
Server Manager & Chairman of the Board - https://esportharte.dk/
Freelance Server Support
Former Co-Owner - https://tfrag.dk/
SmokieCS is offline