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

Solved simple vote map menu (bug) + start plugin(problem)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nacknic
Member
Join Date: Mar 2019
Old 05-16-2019 , 15:56   simple vote map menu (bug) + start plugin(problem)
Reply With Quote #1

19.6.19 -> LOL i solved my problems alone

Problems:
1. show hudmessage players on and start the script after 1/10 (becuase i want to check the plugin) players in the server.
the problem after i change map in voting the plugin start again.

2. in vote map menu in the game:
when i click 1, its do the random stuff instead change to de_inferno
when i click 2, its change to de_inferno instead change to de_aztec

Full Script:
Code:
#include <amxmodx>

#define LOOP_DELAY 1.0
#define TASK_ID_1  101
#define TASK_ID_2  102
//#define MENU_EXIT  0

new g_player_id[ 32 ], g_player_num, g_chosen[ 4 ];
new const g_map_path[ ][ ] = { "maps/de_dust2_long.bsp" };
new const g_map[ ][ ] ={ "de_dust2_long", "de_inferno", "de_aztec" };

public plugin_init() 
	register_plugin( "retake", "1.0", "nacknic" );		

public client_putinserver( )
	set_task( LOOP_DELAY, "loop", TASK_ID_1,"", 0,  "b" );

public loop( )
{
	arrayset( g_chosen, 0, sizeof g_chosen );	
	if ( g_player_num < 1 )
	{
		get_players( g_player_id, g_player_num );
		set_hudmessage( 255, 255, 255, 0.30, 0.16, 0, 6.0, LOOP_DELAY );
		show_hudmessage( 0, "%d/10 Players on", g_player_num );	
	}
	else if( g_player_num == 1 )	
		stop_loop( );
}

public stop_loop( )
{
	g_player_num = 0;
	g_player_id[ 0 ] = 0;
	set_hudmessage( 255, 255, 255, 0.30, 0.16, 0, 6.0, 8.0 );
	show_hudmessage( 0, "Retake Plugin start right now" );	
	remove_task( TASK_ID_1, 0 );
	set_task( 1.0, "vote_map_menu", TASK_ID_2 );
}
	
public client_disconnect( )
{
	get_players( g_player_id, g_player_num );
	if( (g_player_num - 1) < 2 )	
	{
		set_hudmessage( 255, 255, 255, 0.30, 0.16, 0, 6.0, 8.0 );
		show_hudmessage( 0, "Reatake Plugin Ends: only %s/10 Players left", g_player_num );
		set_task( 8.0, "default_map" );
	}	
}

public default_map( )
{
	if( file_exists( g_map_path[ 0 ] ) )
		server_cmd( "changelevel %s", g_map[ 0 ] );
	else
	{
		static current_map[ 33 ]; 
		get_mapname( current_map, charsmax( current_map ) );
		server_cmd( "changelevel %s", current_map );
	}
}

public vote_map_menu( )
{
	new map_menu;
	map_menu = menu_create( "Choose Map", "menu_handler" );
	menu_additem( map_menu, "de_inferno", "1" );
	menu_additem( map_menu, "de_aztec", "2" );
	get_players( g_player_id, g_player_num );
	for( new i = 0; i < g_player_num; i++ )
		menu_display( g_player_id[ i ], map_menu, 0 );
	set_task( 7.0, "end_vote_map" );
}

public menu_handler( id, menu, item )
	g_chosen[ item ]++; //  increase the chosen item by +1
	
public end_vote_map( menu )
{
	if( g_chosen[ 1 ] > g_chosen[ 2 ] )
		server_cmd( "changelevel %s", g_map[ 1 ] );
	else if( g_chosen[ 1 ] < g_chosen[ 2 ] )
		server_cmd( "changelevel %s", g_map[ 2 ] );
	else if( g_chosen[ 1 ] == g_chosen[ 2 ] ) 
		server_cmd( "changelevel %s", g_map[ random_num( 1 ,2 ) ] );
}
UPDATE 17.5.19
i fixed problem 1, the plugin not start when the map changed until the plugin stop, the result was using cvar (i learn it just now ;) ).
problem 2, not fixed yet.
Code:
#include <amxmodx>

#define LOOP_DELAY 1.0
#define TASK_ID_1  101
#define TASK_ID_2  102
//#define MENU_EXIT  0

new g_player_id[ 32 ], g_player_num, g_chosen[ 4 ];
new const g_map_path[ ][ ] = { "maps/de_dust2_long.bsp" };
new const g_map[ ][ ] ={ "de_dust2_long", "de_inferno", "de_aztec" };
new cvar_game_started;

public plugin_init() 
{
	register_plugin( "retake", "1.0", "nacknic" );
	cvar_game_started = register_cvar( "game_startes", "1" );
}

public client_putinserver( )
{
         if( get_pcvar_num( cvar_game_started ) == 1 )
	 {
	 	set_pcvar_num( cvar_game_started, 0 );
	 	set_task( LOOP_DELAY, "loop", TASK_ID_1,"", 0,  "b" );
	 }
}
	

public loop( )
{
	arrayset( g_chosen, 0, sizeof g_chosen );	
	if ( g_player_num < 1 )
	{
		get_players( g_player_id, g_player_num );
		set_hudmessage( 255, 255, 255, 0.30, 0.16, 0, 6.0, LOOP_DELAY );
		show_hudmessage( 0, "%d/10 Players on", g_player_num );	
	}
	else if( g_player_num == 1 )	
		stop_loop( );
}

public stop_loop( )
{
	g_player_num = 0;
	g_player_id[ 0 ] = 0;
	set_hudmessage( 255, 255, 255, 0.30, 0.16, 0, 6.0, 8.0 );
	show_hudmessage( 0, "Retake Plugin start right now" );	
	remove_task( TASK_ID_1, 0 );
	set_task( 1.0, "vote_map_menu", TASK_ID_2 );
}
	
public client_disconnect( )
{
	get_players( g_player_id, g_player_num );
	if( (g_player_num - 1) < 2 )	
	{
		set_hudmessage( 255, 255, 255, 0.30, 0.16, 0, 6.0, 8.0 );
		show_hudmessage( 0, "Reatake Plugin Ends: only %s/10 Players left", g_player_num );
		set_task( 8.0, "default_map" );
	}	
}

public default_map( )
{
	if( file_exists( g_map_path[ 0 ] ) )
	{
		server_cmd( "changelevel %s", g_map[ 0 ] );
		set_pcvar_num( cvar_game_started, 1 );
	}
	else
	{
		static current_map[ 33 ]; 
		get_mapname( current_map, charsmax( current_map ) );
		server_cmd( "changelevel %s", current_map );
		set_pcvar_num( cvar_game_started, 1 );
	}
}

public vote_map_menu( )
{
	new map_menu;
	map_menu = menu_create( "Choose Map", "menu_handler" );
	menu_additem( map_menu, "de_inferno", "1" );
	menu_additem( map_menu, "de_aztec", "2" );
	get_players( g_player_id, g_player_num );
	for( new i = 0; i < g_player_num; i++ )
		menu_display( g_player_id[ i ], map_menu, 0 );
	set_task( 7.0, "end_vote_map" );
}

public menu_handler( id, menu, item )
	g_chosen[ item ]++; //  increase the chosen item by +1
	
public end_vote_map( menu )
{
	if( g_chosen[ 1 ] > g_chosen[ 2 ] )
		server_cmd( "changelevel %s", g_map[ 1 ] );
	else if( g_chosen[ 1 ] < g_chosen[ 2 ] )
		server_cmd( "changelevel %s", g_map[ 2 ] );
	else if( g_chosen[ 1 ] == g_chosen[ 2 ] ) 
		server_cmd( "changelevel %s", g_map[ random_num( 1 ,2 ) ] );
}
UPDATE 19.5.19
i fixed problem 2, the problem was item start from 0, when menu_additem( map_menu, "de_inferno", "1" ); was 1

Code:
#include <amxmodx>

#define LOOP_DELAY 1.0
#define TASK_ID_1  101
#define TASK_ID_2  102

new g_player_id[ 32 ], g_player_num, g_chosen[ 4 ];
new const g_map_path[ ][ ] = { "maps/de_dust2_long.bsp" };
new const g_map[ ][ ] ={ "de_dust2_long", "de_inferno", "de_aztec" };
new cvar_game_started;

public plugin_init() 
{
	register_plugin( "retake", "1.0", "nacknic" );
	cvar_game_started = register_cvar( "game_startes", "1" );
}

public client_putinserver( )
{
         if( get_pcvar_num( cvar_game_started ) == 1 )
	 {
	 	set_pcvar_num( cvar_game_started, 0 );
	 	set_task( LOOP_DELAY, "loop", TASK_ID_1,"", 0,  "b" );
	 }
}
	

public loop( )
{
	if ( g_player_num < 1 )
	{
		get_players( g_player_id, g_player_num );
		set_hudmessage(255, 255, 42, 0.0, 0.19, 0, 6.0, LOOP_DELAY )
		show_hudmessage( 0, "%d/10 Players on", g_player_num );	
	}
	else if( g_player_num == 1 )	
		stop_loop( );
}

public stop_loop( )
{
	g_player_num = 0;
	g_player_id[ 0 ] = 0;
	set_hudmessage( 255, 255, 255, 0.30, 0.16, 0, 6.0, 8.0 );
	show_hudmessage( 0, "Retake Plugin start right now" );	
	remove_task( TASK_ID_1, 0 );
	set_task( 1.0, "vote_map_menu", TASK_ID_2 );
}
	
public client_disconnect( )
{
	get_players( g_player_id, g_player_num );
	if( (g_player_num - 1) < 2 )	
	{
		arrayset( g_chosen, 0, sizeof g_chosen );
		set_hudmessage( 255, 255, 255, 0.30, 0.16, 0, 6.0, 8.0 );
		show_hudmessage( 0, "Reatake Plugin Ends: only %s/10 Players left", g_player_num );
		set_task( 8.0, "default_map" );
	}	
}

public default_map( )
{
	if( file_exists( g_map_path[ 0 ] ) )
	{
		server_cmd( "changelevel %s", g_map[ 0 ] );
		set_pcvar_num( cvar_game_started, 1 );
	}
	else
	{
		static current_map[ 33 ]; 
		get_mapname( current_map, charsmax( current_map ) );
		server_cmd( "changelevel %s", current_map );
		set_pcvar_num( cvar_game_started, 1 );
	}
}

public vote_map_menu( )
{
	new map_menu;
	map_menu = menu_create( "Choose Map", "menu_handler" );
	menu_additem( map_menu, "de_inferno", "1" );
	menu_additem( map_menu, "de_aztec", "2" );
	get_players( g_player_id, g_player_num );
	for( new i = 0; i < g_player_num; i++ )
		menu_display( g_player_id[ i ], map_menu, 0 );
	set_task( 7.0, "end_vote_map" );
}

public menu_handler( id, menu, item )
	g_chosen[ item ]++; //  increase the chosen item by +1
	
public end_vote_map( menu )
{
	if( g_chosen[ 0 ] > g_chosen[ 1 ])
		server_cmd( "changelevel %s", g_map[ 1 ] );
	else if( g_chosen[ 0 ] < g_chosen[ 1 ] )
	         server_cmd( "changelevel %s", g_map[ 2 ] );
	else if( g_chosen[ 0 ] == g_chosen[ 1 ] )
	         server_cmd( "changelevel %s", g_map[ random_num( 1 ,2 ) ] );
	menu_destroy( menu );
}

Last edited by nacknic; 05-19-2019 at 02:05.
nacknic is offline
Reply


Thread Tools
Display Modes

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


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