Raised This Month: $51 Target: $400
 12% 

I can't get my plugin to work


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Reel mafioso
Member
Join Date: Oct 2014
Location: wouldn't you like to kno
Old 02-04-2015 , 15:31   I can't get my plugin to work
Reply With Quote #1

So hey, it's me again (If you don' know me, be glad) I attempted to make a plugin that changes cvars based on player amount, and failed yet again.
I've tried dozens of combinations, some loops cause immediate server crash, while others increase ping massively.
Here's the code I hope someone could rewrite or help me with :
Code:
/*************************Dynamic cvar changer by Reel Mafioso (Cpl.-ChAoS-)***************************/
/*----------------------------------------------------------------------------------------------------*/
/*****************YOU MAY DISTRIBUTE AND MODIFY AS LONG AS YOU DO NOT MODIFIY THE AUTHOR***************/
#include <amxmodx> 
#include <cstrike> 
public plugin_init()
{
	register_plugin("Change cvars", "1.01", "Reel Mafioso")
	register_event("enforcer", "enforc","a")//Same	
}
public enforcer()
{
	reset:
	get_playersnum()
	if (get_playersnum() == 0)
	{
		goto reset
	}
	else 
	{
		goto switx
	}
	switx:
	switch (get_playersnum())//A switch loop which fires a set of operations based on the returned value from our previous function
	{
		case 1: //In our case, when there is 1 player, execute these operations:
		{
		set_cvar_num("z_health", 400);
		set_cvar_num("z_speed", 290);
		server_cmd("bot_quota 7");
		server_cmd("mp_limitteams 7");
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		server_exec();
		goto reset //Once the cvars are changed, proceed back to begining, in order to continually scan for changes
		}
		case 2: //For 2 players etc.
		{
		set_cvar_num("z_health", 450);
		set_cvar_num("z_speed", 300);
		server_cmd("bot_quota 8");
		server_cmd("mp_limitteams 8");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 3:
		{
		set_cvar_num("z_health", 450);
		set_cvar_num("z_speed", 300);
		server_cmd("bot_quota 9");
		server_cmd("mp_limitteams 9");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 4:
		{
		set_cvar_num("z_health", 500);
		set_cvar_num("z_speed", 310);
		server_cmd("bot_quota 10");
		server_cmd("mp_limitteams 10");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 5:
		{
		set_cvar_num("z_health", 550);
		set_cvar_num("z_speed", 310);
		server_cmd("bot_quota 11");
		server_cmd("mp_limitteams 11");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 6:
		{
		set_cvar_num("z_health", 600);
		set_cvar_num("z_speed", 320);
		server_cmd("bot_quota 12");
		server_cmd("mp_limitteams 12");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 7:
		{
		set_cvar_num("z_health", 650);
		set_cvar_num("z_speed", 320);
		server_cmd("bot_quota 13");
		server_cmd("mp_limitteams 13");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 8:
		{
		set_cvar_num("z_health", 700);
		set_cvar_num("z_speed", 330);
		server_cmd("bot_quota 14");
		server_cmd("mp_limitteams 14");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 9:
		{
		set_cvar_num("z_health", 750);
		set_cvar_num("z_speed", 330);
		server_cmd("bot_quota 15");
		server_cmd("mp_limitteams 15");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 10:
		{
		set_cvar_num("z_health", 700);
		set_cvar_num("z_speed", 350);
		server_cmd("bot_quota 16");
		server_cmd("mp_limitteams 16");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		case 11:
		{
		set_cvar_num("z_health", 700);
		set_cvar_num("z_speed", 360);
		server_cmd("bot_quota 17");
		server_cmd("mp_limitteams 17");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
		default: //When no other cases match, this one is used
		{
		set_cvar_num("z_health", 1100);
		set_cvar_num("z_speed", 380);
		server_cmd("bot_quota 6");
		server_cmd("mp_limitteams 6");
		server_exec();
		client_cmd(0, "gamma", "0.1");
		client_cmd(0, "brightness", "0.1");
		goto reset
		}
	}
}
The brutal use of goto is there because any indefinite loop would crash the server. set_task would heavily lag, then cause a crash.
EDIT: Second code i wrote, which also doesn't work :<

Code:
#include <amxmodx> 
#include <cstrike> 
public plugin_init()
{
	register_plugin("Change cvars", "1.01", "Reel Mafioso")
}
public counter()
{
get_playersnum()
}
public enforcer()
{
	get_playersnum();
	if(get_playersnum()==0)
	{
		counter();
	}
	else if(get_playersnum()==1)
	{
		do
		{
			console_print(0, "Level 1 difficulty loaded")
			set_cvar_num("z_health", 400);
			set_cvar_num("z_speed", 290);
			server_cmd("bot_quota 7");
			server_cmd("mp_limitteams 7");
			engclient_cmd(0, "gamma", "0.1");
			engclient_cmd(0, "brightness", "0.1");
		}
		while(get_playersnum() == 1)
	}
	else 
	{
		do 
		{
			console_print(0, "Level 2 difficulty loaded")
			set_cvar_num("z_health", 450);
			set_cvar_num("z_speed", 300);
			server_cmd("bot_quota 8");
			server_cmd("mp_limitteams 8");
			engclient_cmd(0, "gamma", "0.1");
			engclient_cmd(0, "brightness", "0.1");
		}
		while (get_playersnum() != 1)
	}
}

Last edited by Reel mafioso; 02-05-2015 at 13:57. Reason: more info n stuff
Reel mafioso is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 02-04-2015 , 18:40   Re: I can't get my plugin to work
Reply With Quote #2

1-lol remove the goto ( batch file please ? )
2-You didn't set 'all' client_cmd correctly ' client_cmd( 0 , "brightness ^"0.1^"") ' ...
Code:
client_cmd(0, "brightness", "0.1");
3-remove this event 'register_event("enforcer", "enforc","a")' just put your check in client_connect ... or Spawn , you have a lot of choice
4-remove server_exec()
5-add a case default for a default ... you know
Freezo Begin is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-04-2015 , 18:45   Re: I can't get my plugin to work
Reply With Quote #3

Slowhacking is not supported here and should be removed (i.e. remove all client_cmd functions).
__________________
fysiks is offline
Reel mafioso
Member
Join Date: Oct 2014
Location: wouldn't you like to kno
Old 02-05-2015 , 10:23   Re: I can't get my plugin to work
Reply With Quote #4

-Why should I remove goto? It should work if I did it properly (I'm not so experienced with C++)

Quote:
Slowhacking is not supported here and should be removed (i.e. remove all client_cmd functions).
-I don't know why it's a big deal to use client_cmd, if it's such a problem, then what should I use?
-Do I already not have a default case? It's right there.
-I think server_exec is needed for server_cmd to be executed immediately. I don't exactly know what a "next frame " is maybe a frame related to the server tickrate/fps?
Freezo, you aren't really being helpfull by what you wrote. You just told me remove this and that. I remove all goto and do what with the if else loop? I remove all client_cmd, then how do I executed commands on players? What do you mean with client_connect? What's that supposed to mean?

Last edited by Reel mafioso; 02-05-2015 at 10:27. Reason: k
Reel mafioso is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 02-05-2015 , 14:04   Re: I can't get my plugin to work
Reply With Quote #5

didn't test it

Code:
#include <amxmodx> #include <cstrike> #define DELAY  5.0 public plugin_init() {     register_plugin("Change cvars", "1.01", "Reel Mafioso")     set_task( DELAY , "Check_Player", _, _, _, "b") } public Check_Player( ) {     switch ( get_playersnum() ){         case 1 : Exec_server( 400 , 290 , 7 , 7 )         case 2 : Exec_server( 450 , 300 , 8 , 8 )         case 3 : Exec_server( 450 , 300 , 9 , 9 )         case 4 : Exec_server( 500 , 310 , 10 , 10 )         case 5 : Exec_server( 550 , 310 , 11 , 11 )         case 6 : Exec_server( 650 , 320 , 13 , 13 )         case 7 : Exec_server( 500 , 320 , 14 , 14 )         case 8 : Exec_server( 500 , 330 , 15 , 15 )         case 9 : Exec_server( 500 , 330 , 15 , 15 )         case 10 :Exec_server( 500 , 330 , 16  , 16 )         case 11 :Exec_server( 700 , 360 , 17 , 17 )         default  :Exec_server( 1100 , 380 , 6 , 6 )             } } stock Exec_server( health , speed , bot_quota , teamlimits  ) {     set_cvar_num("z_health", health)     set_cvar_num("z_speed", speed )         //client_cmd(0, "gamma ^"0.1^"")     //client_cmd(0, "brightness ^"0.1^"")         server_cmd("bot_quota %d" , bot_quota)     server_cmd("mp_limitteams %d",teamlimits)     server_exec() }

Last edited by Freezo Begin; 02-05-2015 at 14:40.
Freezo Begin is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-05-2015 , 14:21   Re: I can't get my plugin to work
Reply With Quote #6

In your second code enforcer is never called.
__________________

Last edited by HamletEagle; 02-06-2015 at 06:03.
HamletEagle is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 02-05-2015 , 14:40   Re: I can't get my plugin to work
Reply With Quote #7

This is all available events
Here you can found it
Freezo Begin is offline
Reel mafioso
Member
Join Date: Oct 2014
Location: wouldn't you like to kno
Old 02-05-2015 , 15:11   Re: I can't get my plugin to work
Reply With Quote #8

Quote:
Originally Posted by Freezo Begin View Post
didn't test it

Code:
#include <amxmodx> #include <cstrike> #define DELAY  5.0 public plugin_init() {     register_plugin("Change cvars", "1.01", "Reel Mafioso")     set_task( DELAY , "Check_Player", _, _, _, "b") } public Check_Player( ) {     switch ( get_playersnum() ){         case 1 : Exec_server( 400 , 290 , 7 , 7 )         case 2 : Exec_server( 450 , 300 , 8 , 8 )         case 3 : Exec_server( 450 , 300 , 9 , 9 )         case 4 : Exec_server( 500 , 310 , 10 , 10 )         case 5 : Exec_server( 550 , 310 , 11 , 11 )         case 6 : Exec_server( 650 , 320 , 13 , 13 )         case 7 : Exec_server( 500 , 320 , 14 , 14 )         case 8 : Exec_server( 500 , 330 , 15 , 15 )         case 9 : Exec_server( 500 , 330 , 15 , 15 )         case 10 :Exec_server( 500 , 330 , 16  , 16 )         case 11 :Exec_server( 700 , 360 , 17 , 17 )         default  :Exec_server( 1100 , 380 , 6 , 6 )             } } stock Exec_server( health , speed , bot_quota , teamlimits  ) {     set_cvar_num("z_health", health)     set_cvar_num("z_speed", speed )         //client_cmd(0, "gamma ^"0.1^"")     //client_cmd(0, "brightness ^"0.1^"")         server_cmd("bot_quota %d" , bot_quota)     server_cmd("mp_limitteams %d",teamlimits)     server_exec() }
Okay, thank you for trying. I tested it with results similar to mine. Mine after I discovered the colossal mistake I made at
Code:
public enforcer()
, which i replaced to
Code:
public client_connect()
(HamletEagle pointed it out too, I made a function which I never called, so I replaced the name with client_connect)
Here's what happened with the plugin you provided: Bots join in, everything looks fine. 5 seconds later more bots join in. I decided to go in. I enter the game, every 5 seconds the bot amount changes. I join a team and bot count goes back to 6. After a second or two it increases by 1, then after (unmeasured) time of 5 seconds or more another 7 bots join in, as soon as 14 is reached it drops down to 12, stays a while then drops back to 6. Repeat indefinitely
My code that I managed to work follows similar symptoms, except after I join the bot count goes up to 12 and loops "kick 1 bot, add 1 bot", an oscillation of the count from 11 to 12 every with a 2Hz frequency (2 times per second).

I don't really know what's going on. All other methods of the same plugin i created earlier failed the same way. It could be a plugin that was perhaps never meant to be?
Reel mafioso is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 02-05-2015 , 19:07   Re: I can't get my plugin to work
Reply With Quote #9

Hmm ... maybe the problem come from get_playersnum() !
Well add a Global variable in the connect it will add ++ / += 1 and if the player disconnect it will -- / -= 1 and make !is_user_bot(id) ... you know ... then make a switch
Freezo Begin is offline
Reel mafioso
Member
Join Date: Oct 2014
Location: wouldn't you like to kno
Old 02-06-2015 , 03:57   Re: I can't get my plugin to work
Reply With Quote #10

Quote:
Originally Posted by Freezo Begin View Post
Hmm ... maybe the problem come from get_playersnum() !
Well add a Global variable in the connect it will add ++ / += 1 and if the player disconnect it will -- / -= 1 and make !is_user_bot(id) ... you know ... then make a switch
I tried to add a an IF ELSE loop, a switch and a Do while loop, they all give me this same error:

Quote:
Number of argument's does not match definition
I did it like so:

Code:
public Check_Bot( )
{
	if(is_user_bot() != 1)
	{
		Check_Player( )
	}
	else
	{
		Check_Bot( )
	}
}
I tried some other function instead of is_user_bot and it compiles without a problem
The rest of the code is the same as you had provided earlier, with some changed numbers.

Last edited by Reel mafioso; 02-06-2015 at 03:58.
Reel mafioso 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 00:55.


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