Raised This Month: $ Target: $400
 0% 

Map menu with fixed map in every map.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-20-2011 , 19:11   Re: Map menu with fixed map in every map.
Reply With Quote #26

Code:
#include <amxmodx>
#include <amxmisc>

#define MAX_MAPS 5
#define MAPSINI "maps.ini"

new const PLUGIN[] = "Maps Management"
new const VERSION[] = "3.5"
new const AUTHOR[] = "WS.Chu:)"

new s_Maps[MAX_MAPS][32];
new g_MaxPlayers, g_CurrentMapName[64];
new mapIndexes[MAX_MAPS];
new g_Started[32];

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR);
	
	register_clcmd("say", "main_menu");
	
	g_MaxPlayers = get_maxplayers();
	
	get_mapname(g_CurrentMapName, 63);
	
	readmaps();
}

readmaps()
{
	if(!RetrieveMaps(s_Maps))
		return PLUGIN_CONTINUE;
	
	for( new i = 0; i < MAX_MAPS; i++ ) 
	{ 
		random_range(0, MAX_MAPS - 1, mapIndexes, sizeof(mapIndexes));
		server_print("Map: %s", s_Maps[mapIndexes[i]]);
		static id;
		g_Started[id] = true;
	}
	
	return PLUGIN_CONTINUE;
}

public main_menu(id)
{
	new szMessages[256];
	read_args(szMessages, 255);
	remove_quotes(szMessages);
	
	if(equal(szMessages, "rtv"))
	{
		//if(!RetrieveMaps(s_Maps))
		//	return PLUGIN_CONTINUE;
		if(!g_Started[id])
		{
			new buffer[512], buffer1[512], buffer2[512];
			
			new i_PlayersNum = get_playersnum(1);
			
			new i_TimeLeft = get_timeleft();
			
			formatex(buffer, 511, "\d[MAP] \yVote menu^nTotal Player: %d/%d^nTimeleft: %d:%02d", i_PlayersNum, g_MaxPlayers, i_TimeLeft / 60, i_TimeLeft % 60);
			formatex(buffer2, 511, "Nominate: %s", g_CurrentMapName);
			
			new menu = menu_create(buffer, "menu_handler");
			
			for(new i = 0; i < MAX_MAPS; i++)
			{
				formatex(buffer1, 511, "0%% %s", s_Maps[mapIndexes[i]]);
				menu_additem(menu, buffer1, _, 0);
			}
			menu_addblank(menu, 0);
			menu_additem(menu, "Extend", "6", 0);
			menu_additem(menu, buffer2, "7", 0);
			
			menu_setprop(menu, MPROP_NUMBER_COLOR, "\w");
			menu_setprop(menu, MPROP_EXITNAME, "EXIT!");
			menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
			
			menu_display(id, menu, 0);
			
			return PLUGIN_HANDLED;
		}
	}
	return PLUGIN_CONTINUE;
}

public menu_handler(id, menu, item)
{
	if( item == MENU_EXIT )
	{
		menu_destroy(menu);
		return PLUGIN_HANDLED;
    }

	new data[6], szName[64];
	new access, callback;
	menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback);
	
	new key = str_to_num(data);
	
	switch(key)
	{
		case 1:
		{
			client_print(id, print_chat, "TEST");
		}
		case 6:
		{
			client_print(id, print_chat, "TEST");
		}
		case 7:
		{
			client_print(id, print_chat, "TEST");
		}
	}
	return PLUGIN_HANDLED;
}

bool:RetrieveMaps(s_MapsFound[][])
{
	static id;
	if(!g_Started[id])
	{
		new s_File[256], s_ConfigsDir[256];
		get_configsdir(s_ConfigsDir, 255);
		formatex(s_File, 255, "%s/%s", s_ConfigsDir, MAPSINI);
			
		if (!file_exists(s_File))
			get_cvar_string("mapcyclefile", s_File, charsmax(s_File)); 
			
		//new s_CurrentMap[MAX_MAP_LENGTH];
		new s_CurrentMap[32];
		get_mapname(s_CurrentMap, charsmax(s_CurrentMap));
		
		new p_File = fopen(s_File, "rt");
		new Array:a_Maps;
		new i_MapsCount = SaveAllMaps(p_File, a_Maps);
		
		new bool:b_Error = true, i;   
		switch (i_MapsCount)
		{
			case 0             : log_amx("There are no maps in the %s.", s_File);
			case 1 .. MAX_MAPS : log_amx("Not enough maps found. (requires at least %d maps)", MAX_MAPS + 1 );
			default            :  b_Error = false;
		}
		if (b_Error)
		{
			fclose(p_File); 
			ArrayDestroy(a_Maps);
			return false;
		}
		fclose(p_File);
		
		new i_Rand, i_Cnt;
		while (i_Cnt != MAX_MAPS)
		{
			i_Rand = random_num(0, ArraySize(a_Maps) - 1);
	//		ArrayGetString(a_Maps, i_Rand, s_MapsFound[i_Cnt], MAX_MAP_LENGTH - 1);
			ArrayGetString(a_Maps, i_Rand, s_MapsFound[i_Cnt], 32 - 1);
			
			if (equal(s_MapsFound[i_Cnt], s_CurrentMap))
			{
				continue;
			}
			
			for (i = 0; i < i_Cnt; i++)
			{
				if (equal(s_MapsFound[i], s_MapsFound[i_Cnt]))
				{
					break;
				}
			}
			
			if (i == i_Cnt)
			{
				ArrayDeleteItem(a_Maps, i_Rand);
				i_Cnt++;
			}
		}
		ArrayDestroy(a_Maps);
		return true;
	}
	return false;
}

SaveAllMaps(p_File, &Array:a_Maps)
{
	static id;
	if(!g_Started[id])
	{
	//	a_Maps = ArrayCreate(MAX_MAP_LENGTH);
	//	new s_Buffer[MAX_MAP_LENGTH]
		a_Maps = ArrayCreate(32);
		new s_Buffer[32]
		
		while (!feof(p_File))
		{
			fgets(p_File, s_Buffer, charsmax(s_Buffer));
			trim(s_Buffer);
			if (!s_Buffer[0] || s_Buffer[0] == ';' || (s_Buffer[0] == '/' && s_Buffer[1] == '/'))
			{
				continue;
			}
			if (is_map_valid(s_Buffer))
			{
				ArrayPushString(a_Maps, s_Buffer);
			}
		}
		return ArraySize(a_Maps);
	}
	return false;
}

stock random_range(_min, _max, output[], size)
{
    new Array:values = ArrayCreate(1), numValues;
    for(new i = _min; i <= _max; i++)
    {
        ArrayPushCell(values, i);
        numValues++;
    }
    
    new rand, i;
    while(i < size && numValues > 0)
    {
        rand = random(numValues);
        
        output[i++] = ArrayGetCell(values, rand);
        
        ArrayDeleteItem(values, rand);
        numValues--;
    }
    
    ArrayDestroy(values);
    
    return i;
}
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
 



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 20:29.


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