Raised This Month: $ Target: $400
 0% 

enable/disable whole plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
notahacker
Member
Join Date: Jan 2015
Old 03-12-2017 , 07:47   enable/disable whole plugin
Reply With Quote #1

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
notahacker is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-12-2017 , 08:10   Re: enable/disable whole plugin
Reply With Quote #2

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" ) }
__________________
edon1337 is offline
notahacker
Member
Join Date: Jan 2015
Old 03-12-2017 , 08:17   Re: enable/disable whole plugin
Reply With Quote #3

Quote:
Originally Posted by edon1337 View Post
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?
notahacker is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-12-2017 , 08:26   Re: enable/disable whole plugin
Reply With Quote #4

What do you mean?
__________________
edon1337 is offline
notahacker
Member
Join Date: Jan 2015
Old 03-12-2017 , 08:29   Re: enable/disable whole plugin
Reply With Quote #5

Quote:
Originally Posted by edon1337 View Post
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?
notahacker is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 03-12-2017 , 09:15   Re: enable/disable whole plugin
Reply With Quote #6

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 ...

Craxor is offline
Send a message via ICQ to Craxor
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-12-2017 , 09:53   Re: enable/disable whole plugin
Reply With Quote #7

Quote:
Originally Posted by Craxor View Post
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.

Last edited by klippy; 03-12-2017 at 09:54.
klippy is offline
notahacker
Member
Join Date: Jan 2015
Old 03-12-2017 , 11:31   Re: enable/disable whole plugin
Reply With Quote #8

Quote:
Originally Posted by Craxor View Post
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?
notahacker is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-12-2017 , 10:12   Re: enable/disable whole plugin
Reply With Quote #9

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")         }
__________________
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-12-2017 , 10:14   Re: enable/disable whole plugin
Reply With Quote #10

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.
__________________

Last edited by OciXCrom; 03-12-2017 at 10:15.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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:54.


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