AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Pause plugin (https://forums.alliedmods.net/showthread.php?t=335819)

SmokieCS 01-06-2022 08:34

Pause plugin
 
Hello!

I have created a plugin that makes the handles !pause !unpause available with small extra versions of it (!p, !up etc).

There is 1 problem and a thing I would like to add, but do not really know how to.
  1. The Problem - I made translations available, but it prints out 2 times when entering !pause.
  2. I would like to add the solution of only being available 4 times of 30 seconds per team per map. When the map switches or the server is restartet it resets the limit.


Code can be found here: https://github.com/ksgoescoding/PausePlugin

Thank you in advance!

SmokieCS 01-06-2022 09:51

Re: Pause plugin
 
Kinda like this: https://forums.alliedmods.net/showth...=225768&page=2

Just with a more updated syntax and also fitting my current script.

I am trying to add it myself on the fly and share experiences and failures. (So far I just cleaned and copied the code from the link above, and I will try to implement it in my own coding)

https://github.com/ksgoescoding/Paus...ee/development

Bacardi 01-06-2022 18:15

Re: Pause plugin
 
Quote:

Originally Posted by SmokieCS (Post 2767779)
Hello!
...
  1. The Problem - I made translations available, but it prints out 2 times when entering !pause.
    ...


Code can be found here: https://github.com/ksgoescoding/PausePlugin
...![/B]

https://github.com/ksgoescoding/Paus...ePlugin.sp#L33
Code:

    RegConsoleCmd("sm_pause", Command_Pause, "Requests a pause");
https://github.com/ksgoescoding/Paus...ePlugin.sp#L51
Code:

    AddAliasedCommand("pause", Command_Pause, "Pauses the game");
https://github.com/ksgoescoding/Paus...n.sp#L153-L163
Code:

/** Add Aliased Command callback **/
public void AddAliasedCommand(const char[] command, ConCmd callback, const char[] description) {
  char smCommandBuffer[COMMAND_LENGTH];
  Format(smCommandBuffer, sizeof(smCommandBuffer), "sm_%s", command);
  RegConsoleCmd(smCommandBuffer, callback, description);


  char dotCommandBuffer[ALIAS_LENGTH];
  Format(dotCommandBuffer, sizeof(dotCommandBuffer), ".%s", command);
  AddChatAlias(dotCommandBuffer, smCommandBuffer);
}

*edit
When someone want add more "chat triggers" for one specific command callback, I would recommend to use some kind custom KeyValue file rather than
hard code lot of reg console commands or check say command arguments in plugin code.
With custom KeyValue txt file:
- User, who want use plugin, can modified or remove these unnecessary thing in they own server.
- Not need edit plugin code and recompile
- Not need look every console commands for override them from admin configures.

This is just my opinion.

PC Gamer 01-06-2022 19:36

Re: Pause plugin
 
To help translate a bit...

Your code is checking for the word "pause" in two different ways. As a result, it is executing the code twice whenever it sees the word "pause". The first, and best use of "pause" is with:
PHP Code:

RegConsoleCmd("sm_pause"Command_Pause"Requests a pause"); 

Since you've already registered the word "pause" as a command there is no need for the aliased command "pause" which was created with this line of code:
PHP Code:

AddAliasedCommand("pause"Command_Pause"Pauses the game"); 

Your code isn't just that it is printing the translation twice, it is actually executing the code twice.

As Bacardi stated, the RegConsole Cmd is the best way to use the command because it allows server operators to change who has access to the command without having to rewrite your code.

The fix is to remove this line entirely:
PHP Code:

AddAliasedCommand("pause"Command_Pause"Pauses the game"); 

While you're at it, remove the other duplicates you have such as "forcepause", "forceunpause", "tech", and others. In fact, get rid of all of them and instead create multiple RegConsole commands like Bacardi stated. For example, your 'pause' commands would look like this:
PHP Code:

RegConsoleCmd("sm_pause"Command_Pause"Requests a pause");
RegConsoleCmd("sm_tac"Command_Pause"Pauses the game");
RegConsoleCmd("sm_p"Command_Pause"Pauses the game");
RegConsoleCmd("sm_tactical"Command_Pause"Pauses the game"); 


SmokieCS 01-07-2022 02:33

Re: Pause plugin
 
Quote:

Originally Posted by PC Gamer (Post 2767823)
To help translate a bit...

Your code is checking for the word "pause" in two different ways. As a result, it is executing the code twice whenever it sees the word "pause". The first, and best use of "pause" is with:
PHP Code:

RegConsoleCmd("sm_pause"Command_Pause"Requests a pause"); 

Since you've already registered the word "pause" as a command there is no need for the aliased command "pause" which was created with this line of code:
PHP Code:

AddAliasedCommand("pause"Command_Pause"Pauses the game"); 

Your code isn't just that it is printing the translation twice, it is actually executing the code twice.

As Bacardi stated, the RegConsole Cmd is the best way to use the command because it allows server operators to change who has access to the command without having to rewrite your code.

The fix is to remove this line entirely:
PHP Code:

AddAliasedCommand("pause"Command_Pause"Pauses the game"); 

While you're at it, remove the other duplicates you have such as "forcepause", "forceunpause", "tech", and others. In fact, get rid of all of them and instead create multiple RegConsole commands like Bacardi stated. For example, your 'pause' commands would look like this:
PHP Code:

RegConsoleCmd("sm_pause"Command_Pause"Requests a pause");
RegConsoleCmd("sm_tac"Command_Pause"Pauses the game");
RegConsoleCmd("sm_p"Command_Pause"Pauses the game");
RegConsoleCmd("sm_tactical"Command_Pause"Pauses the game"); 


Thanks a lot both of you!

Code looks like this now:
PHP Code:

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");



Bacardi 01-07-2022 04:37

Re: Pause plugin
 
here is just example for problem two.

So, do not just "copy/paste" like lazy people do.

PHP Code:


// macros
#define max_usage 4
#define timer_delay 30.0


// global variables
int global_variable_count[4]; // array, but we use team index as array index
Handle global_variable_track_timer;


public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}


public 
void OnMapStart()
{
    
// team 0 = none, 1 = spect, 2 = terrorist, 3 = ct
    
global_variable_count[0] = max_usage;
    
global_variable_count[1] = max_usage;
    
global_variable_count[2] = 0;
    
global_variable_count[3] = 0;

    
// kill running timer if it exist
    
if(global_variable_track_timer != null)
    {
        
delete global_variable_track_timer;
    }
}



public 
Action test(int clientint args)
{
    if(
global_variable_track_timer != null)
    {
        
// Timer is still running
        
return Plugin_Handled;
    }

    if(
client == || !IsClientInGame(client))
    {
        
// Not valid command user
        
return Plugin_Handled;
    }

    
int team_index GetClientTeam(client);

    if(
global_variable_count[team_index] >= max_usage)
    {
        
ReplyToCommand(client"[SM] Command usage exeed limit (%i)"max_usage);
        return 
Plugin_Handled;
    }

    
global_variable_count[team_index] = global_variable_count[team_index] + 1;

    
global_variable_track_timer CreateTimer(timer_delaytimer_callback);

    
PrintToChatAll("\n[SM] %N used timer %i!\n"clientglobal_variable_count[team_index]);


    
// Do code here

    
return Plugin_Handled;
}


public 
Action timer_callback(Handle timer)
{
    
global_variable_track_timer null;

    
PrintToChatAll("\n[SM]Timer have finished!\n");

    
// Do code here

    
return Plugin_Continue;



SmokieCS 01-07-2022 06:23

Re: Pause plugin
 
Quote:

Originally Posted by Bacardi (Post 2767850)
here is just example for problem two.

So, do not just "copy/paste" like lazy people do.

PHP Code:


// macros
#define max_usage 4
#define timer_delay 30.0


// global variables
int global_variable_count[4]; // array, but we use team index as array index
Handle global_variable_track_timer;


public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}


public 
void OnMapStart()
{
    
// team 0 = none, 1 = spect, 2 = terrorist, 3 = ct
    
global_variable_count[0] = max_usage;
    
global_variable_count[1] = max_usage;
    
global_variable_count[2] = 0;
    
global_variable_count[3] = 0;

    
// kill running timer if it exist
    
if(global_variable_track_timer != null)
    {
        
delete global_variable_track_timer;
    }
}



public 
Action test(int clientint args)
{
    if(
global_variable_track_timer != null)
    {
        
// Timer is still running
        
return Plugin_Handled;
    }

    if(
client == || !IsClientInGame(client))
    {
        
// Not valid command user
        
return Plugin_Handled;
    }

    
int team_index GetClientTeam(client);

    if(
global_variable_count[team_index] >= max_usage)
    {
        
ReplyToCommand(client"[SM] Command usage exeed limit (%i)"max_usage);
        return 
Plugin_Handled;
    }

    
global_variable_count[team_index] = global_variable_count[team_index] + 1;

    
global_variable_track_timer CreateTimer(timer_delaytimer_callback);

    
PrintToChatAll("\n[SM] %N used timer %i!\n"clientglobal_variable_count[team_index]);


    
// Do code here

    
return Plugin_Handled;
}


public 
Action timer_callback(Handle timer)
{
    
global_variable_track_timer null;

    
PrintToChatAll("\n[SM]Timer have finished!\n");

    
// Do code here

    
return Plugin_Continue;



First of all THANKS!

I used the code for reference and read about timers from the wiki while inserting to understand the meaning of the process.

It works like a charm, but now there is two other things I am looking for.

1.

I would like to translate the text in the timer callback, as well as make it print out multiple seconds.
Meaning: I would like it to tell when there is 20 and 10 seconds left, and make those translateable.
PHP Code:

/** Timer Callback **/
public Action timer_callback(Handle timer){
    
global_variable_track_timer null;

    
ServerCommand("mp_unpause_match");
    
PrintToChatAll("\n30 second pause has ended. Resuming game!\n");
    return 
Plugin_Continue;


Only thing i found is this, but that is not quite the function i believe.

PHP Code:

Repeatable Timers
Repeatable timers execute infinitely many times
once every intervalBased on the return valuethey either continue or cancel.

For 
examplesay you want to display a message five timesonce every three seconds:

void someFunction()
{
    
CreateTimer(3.0Timer_PrintMessageFiveTimes_TIMER_REPEAT);
}
 
public 
Action Timer_PrintMessageFiveTimes(Handle timer)
{
    
// Create a global variable visible only in the local scope (this function).
    
static int numPrinted 0;
 
    if (
numPrinted >= 5
    {
        
numPrinted 0;
        return 
Plugin_Stop;
    }
 
    
PrintToServer("Warning! This is a message.");
    
numPrinted++;
 
    return 
Plugin_Continue;


2.

Is it possible to make the array do the same as the above. Every time a pause is used, it will ReplyToCommand or PrintToChat
PHP Code:

You have used 1 out of 4 timeouts

Thank you in advance, and code is updated in the Github as well.

SmokieCS 01-07-2022 10:00

Re: Pause plugin
 
At the moment i have coded this on top, with a timer that send PrintToChat on 30, 20, 10 and 3,2,1 seconds. But I am running into some errors that I do not really know how to fix yet.

Full code:
PHP Code:

#pragma semicolon 1
#include <cstrike>
#include <sourcemod>
#include <sdktools>
#include <colors>

/** Macros **/
#define max_usage 4
#define timer_delay 30.0

/** Bools **/
new bool:g_ctUnpaused false;
new 
bool:g_tUnpaused false;
new 
bool:g_bTimerEnd false;

/** Global Variables **/
int g_vcount[4]; 
Handle g_vtrack_timer;

public 
Plugin:myinfo = {
    
name "CS:GO Pause Commands",
    
author "splewis & ^kS",
    
description "Adds simple pause/unpause commands for players",
    
version "1.0.3d",
    
url "https://github.com/ksgoescoding/PausePlugin"
};

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");
}

public 
OnMapStart() {
    
g_ctUnpaused false;
    
g_tUnpaused false;

    
// Team 0 = None || Team 1 = Spectators || Team 2 = T's || Team 3 = CT's
    
g_vcount[0] = max_usage;
    
g_vcount[1] = max_usage;
    
g_vcount[2] = 0;
    
g_vcount[3] = 0;

    
// Kill the timer if it already exists
    
if(g_vtrack_timer != null)
    {
        
delete g_vtrack_timer;
    }
}

/** 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;
}

/** Pause **/
public Action Command_Pause(int clientint args) {
    if(
g_vtrack_timer != null)
    {
        
// Timer is still running. Kill the timer.
        
return Plugin_Handled;
    }
    
    if (
IsPaused() || !IsValidClient(client))
    {
        
// Is the game paused or is the client invalid? Terminate process.
        
return Plugin_Handled;
    }

    
g_ctUnpaused false;
    
g_tUnpaused false;

    
int team_index GetClientTeam(client);

    if(
g_vcount[team_index] >= max_usage)
    {
        
ReplyToCommand(client"There are no more pauses left (%i)"max_usage);
        return 
Plugin_Handled;
    }

    
g_vcount[team_index] = g_vcount[team_index] + 1;
    
g_vtrack_timer CreateTimer(timer_delaytimer_callback);

    
PrintToChatAll("%t""Pause"clientg_vcount[team_index]);
    
ServerCommand("mp_pause_match");

    return 
Plugin_Handled;
}

/** Unpause **/
public Action Command_Unpause(int clientint args) {
    if (!
IsPaused() || !IsValidClient(client))
        return 
Plugin_Handled;

    new 
team GetClientTeam(client);

    if (
team == CS_TEAM_T)
        
g_tUnpaused true;
    else if (
team == CS_TEAM_CT)
        
g_ctUnpaused true;

    if (
g_tUnpaused && g_ctUnpaused)  {
        
ServerCommand("mp_unpause_match");
    } else if (
g_tUnpaused && !g_ctUnpaused) {
        
CPrintToChatAll("%t""tUnpause"client);
    } else if (!
g_tUnpaused && g_ctUnpaused) {
        
CPrintToChatAll("%t""ctUnpause"client);
    }

    return 
Plugin_Handled;
}

/**
public Action timer_callback(Handle timer){
    if(global_variable_track_timer = null);

    ServerCommand("mp_unpause_match");
    PrintToChatAll("%t", "Auto Unpause");
    return Plugin_Continue;
}
**/

/** New Callback Timer **/
public Action timer_callback(Handle timer)
{
if (
GetConVarBool(g_bTimerEnd))
    {
            
Handle hTmp;
            
hTmp FindConVar("mp_timelimit");
            
int iTimeLimit;
            
iTimeLimit GetConVarInt(hTmp);
            if (
hTmp != null)
                
CloseHandle(hTmp);
            if (
iTimeLimit 0)
        {
                
int timeleft;
                
GetPauseTimeLeft(timeleft);
                switch (
timeleft)
                {
                        case 
30:PrintToChatAll("%t""Timeleft"timeleft);
                        case 
20:PrintToChatAll("%t""Timeleft"timeleft);
                        case 
10:PrintToChatAll("%t""Timeleft"timeleft);
                        case 
3:PrintToChatAll("%t""Timeleft"timeleft);
                        case 
2:PrintToChatAll("%t""Timeleft"timeleft);
                        case 
1:PrintToChatAll("%t""Timeleft"timeleft);    
                        case -
1:
                        {
                                if (!
g_bTimerEnd)
                                {
                                        
g_bTimerEnd true;
                                        
ServerCommand("mp_unpause_match");
                                }
                        }
                }
        }

        if (
timeleft == 30 || timeleft == 20 || timeleft == 10 || timeleft == || timeleft == || timeleft == 1)
        {
                
CPrintToChatAll("%t""Auto Unpause");
        }
     }
}
            

/** 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");


Errors i am recieving:
PHP Code:

PausePlugin.sp
PausePlugin
.sp(185) : warning 213tag mismatch
PausePlugin
.sp(196) : error 017undefined symbol "GetPauseTimeLeft"
PausePlugin.sp(216) : warning 217loose indentation
PausePlugin
.sp(216) : error 017undefined symbol "timeleft" 


BeepIsla 01-07-2022 10:28

Re: Pause plugin
 
For tactical timeouts, why not just use the built in system? "mp_team_timeout_max" and "mp_team_timeout_time". If you really want to use commands you can also just execute these commands on the server to still end up using the built in system "timeout_ct_start" and "timeout_terrorist_start"

SmokieCS 01-07-2022 12:30

Re: Pause plugin
 
Quote:

Originally Posted by BeepIsla (Post 2767872)
For tactical timeouts, why not just use the built in system? "mp_team_timeout_max" and "mp_team_timeout_time". If you really want to use commands you can also just execute these commands on the server to still end up using the built in system "timeout_ct_start" and "timeout_terrorist_start"

So just to make it clear.

You are saying if I just use these in the commandline instead i should be able to achieve the same?

Worth a try.


All times are GMT -4. The time now is 14:00.

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