AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   enable/disable whole plugin (https://forums.alliedmods.net/showthread.php?t=294959)

notahacker 03-12-2017 07:47

enable/disable whole plugin
 
Hello,

can anyone tell me how to add a cvar that when i put it 0, the whole plugin is disabled, and when put back 1, it starts the plugin from the start.

Thanks

edon1337 03-12-2017 08:10

Re: enable/disable whole plugin
 
Code:
#include < amxmodx > new g_Cvar ; public plugin_init( ) {     g_Cvar = register_cvar( "cvar_name", "0" )     if( ! get_pcvar_num( g_Cvar ) ) {         pause( "a" )     }         unpause( "a" ) }

notahacker 03-12-2017 08:17

Re: enable/disable whole plugin
 
Quote:

Originally Posted by edon1337 (Post 2502963)
Code:
#include < amxmodx > new g_Cvar ; public plugin_init( ) {     g_Cvar = register_cvar( "cvar_name", "0" )     if( ! get_pcvar_num( g_Cvar ) ) {         pause( "a" )     }         unpause( "a" ) }



was i supposed to replace the "a" in pause and unpause with something?

edon1337 03-12-2017 08:26

Re: enable/disable whole plugin
 
What do you mean?

notahacker 03-12-2017 08:29

Re: enable/disable whole plugin
 
Quote:

Originally Posted by edon1337 (Post 2502973)
What do you mean?

Code:

public plugin_init()
{
        register_plugin("Cholo Swap", "2", "Cholo Team");
               
        enable = register_cvar("start_match","1");
        half_rounds = register_cvar("pug_half_rounds","15");
        full_rounds = register_cvar("pug_full_rounds","16");
        live = register_cvar("pug_live","1");

        register_event("HLTV", "event_round_start", "a", "1=0", "2=0");
        register_event("TextMsg", "restart", "a", "2&#Game_C", "2&#Game_W");
        register_event("SendAudio", "event_round_end", "a", "2&%!MRAD_terwin", "2&%!MRAD_ctwin", "2&%!MRAD_rounddraw");

       
        register_logevent( "LogEvent_RoundStart", 2, "1=Round_Start" );       
        register_event( "SendAudio", "Event_SendAudio_TWin", "a", "2&%!MRAD_terwin" );
        register_event( "SendAudio", "Event_SendAudio_CTWin", "a", "2&%!MRAD_ctwin" );
        MaxPlayers = get_maxplayers( );
       
        register_logevent("round_end", 2, "1=Round_End");
        register_dictionary("Auto_Swap_Teams.txt");
       
        register_clcmd("say .score","showscore")
       
       
}

This is my plugin_init. How/Where do i add the g_Cvar in it to on and off the plugin?

Craxor 03-12-2017 09:15

Re: enable/disable whole plugin
 
1. You declare a global variables, example 'g_Cvar'
PHP Code:

new g_Cvar 

2. You register in plugin_init() and assign it's id.
PHP Code:

g_Cvar register_cvar"cvar_name""1" ); // '1' means it's value 

3. You check in a public if is On/Off using an if() condition with the native get_pcvar_num() wich return the 'value' of the cvar.
PHP Code:

if( get_pcvar_numg_Cvar ) )
{
      
// If the cvar have a pozitive value .. ( a pozitive value means bigger than 0, so 1 , 2 , 3 .. etc.
}
else
{
     
// If the cvar have a negative value ...



klippy 03-12-2017 09:53

Re: enable/disable whole plugin
 
Quote:

Originally Posted by Craxor (Post 2502982)
PHP Code:

if( get_pcvar_numg_Cvar ) )
{
      
// If the cvar have a pozitive value .. ( a pozitive value means bigger than 0, so 1 , 2 , 3 .. etc.
}
else
{
     
// If the cvar have a negative value ...



No, if(expression) checks if expression is non-zero. Only 0 is false, everything else, including negative values, is true.

edon1337 03-12-2017 10:12

Re: enable/disable whole plugin
 
Craxor what have negative values to do with this?
Code:
#include < amxmodx > new g_Cvar ; // create a global variable public plugin_init() {     register_plugin("Cholo Swap", "2", "Cholo Team");             // here you will create the cvar to check if plugin is off or on     g_Cvar = register_cvar( "cvar_name", "1" ) ; <0|1> - <OFF|ON>         if( !get_pcvar_num(g_Cvar) )     pause( "a" ) ;             enable = register_cvar("start_match","1");     half_rounds = register_cvar("pug_half_rounds","15");     full_rounds = register_cvar("pug_full_rounds","16");     live = register_cvar("pug_live","1");     register_event("HLTV", "event_round_start", "a", "1=0", "2=0");     register_event("TextMsg", "restart", "a", "2&#Game_C", "2&#Game_W");     register_event("SendAudio", "event_round_end", "a", "2&%!MRAD_terwin", "2&%!MRAD_ctwin", "2&%!MRAD_rounddraw");         register_logevent( "LogEvent_RoundStart", 2, "1=Round_Start" );     register_event( "SendAudio", "Event_SendAudio_TWin", "a", "2&%!MRAD_terwin" );     register_event( "SendAudio", "Event_SendAudio_CTWin", "a", "2&%!MRAD_ctwin" );     MaxPlayers = get_maxplayers( );         register_logevent("round_end", 2, "1=Round_End");     register_dictionary("Auto_Swap_Teams.txt");         register_clcmd("say .score","showscore")         }

OciXCrom 03-12-2017 10:14

Re: enable/disable whole plugin
 
And how do you expect a paused plugin to unpause itself? That's not possible. Either use the amx_pausecfg command, or you will need to add a bunch of checks for every piece of code inside the plugin.
@edon1337 - there's no point of using a cvar that can be changed only when the server restarts, neither would it work if you put in in plugin_init.

notahacker 03-12-2017 11:31

Re: enable/disable whole plugin
 
Quote:

Originally Posted by Craxor (Post 2502982)
1. You declare a global variables, example 'g_Cvar'
PHP Code:

new g_Cvar 

2. You register in plugin_init() and assign it's id.
PHP Code:

g_Cvar register_cvar"cvar_name""1" ); // '1' means it's value 

3. You check in a public if is On/Off using an if() condition with the native get_pcvar_num() wich return the 'value' of the cvar.
PHP Code:

if( get_pcvar_numg_Cvar ) )
{
      
// If the cvar have a pozitive value .. ( a pozitive value means bigger than 0, so 1 , 2 , 3 .. etc.
}
else
{
     
// If the cvar have a negative value ...





so i should just use an if() condition in all the publics i have in the plugin?


All times are GMT -4. The time now is 17:54.

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