Raised This Month: $ Target: $400
 0% 

Map menu with fixed map in every map.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-13-2011 , 12:08   Map menu with fixed map in every map.
Reply With Quote #1

I've written some basic code.
Yet I found out that every time when I say rtv it will be different map names.
How can I make them become fixed in the beginning of each map?

Can anyone fix the bug? It print me everything in the maps.ini
Code:
#include <amxmodx>
#include <amxmisc>

#define MAX_MAPS 5

new g_MaxPlayers, g_CurrentMapName[64];

new g_MapsNames[MAX_MAPS][32];
new g_MapsNum;

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

readmaps() 
{ 
	new sz_Configdir[64];
	new sz_FileName[64];
	get_configsdir(sz_Configdir, 63);
	formatex(sz_FileName, 63, "%s/maps.ini", sz_Configdir);

	if(!file_exists(sz_FileName))
	{
		server_print("[ERROR] %s: Maps file %s not found.", PLUGIN, sz_FileName);
		return;
	}
	new i_Len;
	while(g_MapsNum < MAX_MAPS && read_file(sz_FileName, g_MapsNum ,g_MapsNames[g_MapsNum][1], 30, i_Len))
	{ 
		if(g_MapsNames[g_MapsNum][0] == ';') continue;
		g_MapsNames[g_MapsNum][0] = i_Len;
		++g_MapsNum;
	}
	server_print("[AMXX] %s: loaded %d maps.", PLUGIN, g_MapsNum);
} 

public main_menu(id)
{
	new szMessages[256];
	read_args(szMessages, 255);
	remove_quotes(szMessages);
	
	new i_PlayersNum = get_playersnum(1);
	
	if(equal(szMessages, "rtv"))
	{
		new buffer[512], buffer2[512];
		new i_TimeLeft = get_timeleft();
		formatex(buffer, 511, "\d[Rock the vote]\yMap menu^nTotal player: %d/%d", i_PlayersNum, g_MaxPlayers);
		new menu = menu_create(buffer, "menu_handler");
		
		static i;
		for(i=0; i < MAX_MAPS; i++)
		{
			formatex(buffer2, 511, "0%% %s", g_MapsNames[i][1]);
			menu_additem(menu, buffer2, _, 0);
		}
		menu_addblank(menu, 0);
		menu_additem(menu, "Extend", "6", 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 6:
		{
			client_print(id, print_chat, "You press a button.");
			main_menu(id);
		}
		case 7:
		{
			client_print(id, print_chat, "You press a button.");
        }
	}
	return PLUGIN_HANDLED;
}
Attached Thumbnails
Click image for larger version

Name:	Image 142.jpg
Views:	230
Size:	16.6 KB
ID:	90663  
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others

Last edited by GarbageBox; 08-15-2011 at 14:34.
GarbageBox is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-13-2011 , 17:02   Re: Map menu with fixed map in every map.
Reply With Quote #2

I don't understand your issue. Also, you should only read the file once if the map file is not expected to change mid-game. You should look how mapchooser does it and use something more similar to that because your current method is way overkill (and might be the cause of your problem).
__________________
fysiks is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-14-2011 , 02:10   Re: Map menu with fixed map in every map.
Reply With Quote #3

Okay, I will look mapchooser later.
How can I in each map beginning randomly get 5 maps and make it become regular in the menu?
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-14-2011 , 02:37   Re: Map menu with fixed map in every map.
Reply With Quote #4

I think Exolent has a function to get random numbers without repeating. I would probably use that and use only those indexes.
__________________
fysiks is offline
Blue Snake.
Member
Join Date: May 2011
Location: Romania
Old 08-14-2011 , 12:25   Re: Map menu with fixed map in every map.
Reply With Quote #5

PHP Code:
public randoms(const start, const enddest[], const len)
{
    new 
numberbool:found=false
    
for(new i=0;i<len;i++)
    {
        while(!
found)
        {
            
found=false
            number
=random_num(startend)
            for(new 
j=0;j<i;j++)
                if(
number!=dest[j])
                {
                    
found=true
                    
break;
                }
            
dest[i]=number
        
}
    }

Not tested.

Last edited by Blue Snake.; 08-14-2011 at 12:27.
Blue Snake. is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-15-2011 , 14:33   Re: Map menu with fixed map in every map.
Reply With Quote #6

Quote:
Originally Posted by Blue Snake. View Post
PHP Code:
public randoms(const start, const enddest[], const len)
{
    new 
numberbool:found=false
    
for(new i=0;i<len;i++)
    {
        while(!
found)
        {
            
found=false
            number
=random_num(startend)
            for(new 
j=0;j<i;j++)
                if(
number!=dest[j])
                {
                    
found=true
                    
break;
                }
            
dest[i]=number
        
}
    }

Not tested.
I don't understand your code
Can you tell more detail about it and I update a little of my code in #1.
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-15-2011 , 14:42   Re: Map menu with fixed map in every map.
Reply With Quote #7

Quote:
Originally Posted by Blue Snake. View Post
PHP Code:
public randoms(const start, const enddest[], const len)
{
    new 
numberbool:found=false
    
for(new i=0;i<len;i++)
    {
        while(!
found)
        {
            
found=false
            number
=random_num(startend)
            for(new 
j=0;j<i;j++)
                if(
number!=dest[j])
                {
                    
found=true
                    
break;
                }
            
dest[i]=number
        
}
    }

Not tested.
That's a bad method.
See my tutorial about getting random values from an array.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-16-2011 , 08:09   Re: Map menu with fixed map in every map.
Reply With Quote #8

Quote:
Originally Posted by Exolent[jNr] View Post
That's a bad method.
See my tutorial about getting random values from an array.
I decided to give up
I had watch your tutorial's. It seems very difficult to me
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 08-18-2011 , 15:53   Re: Map menu with fixed map in every map.
Reply With Quote #9

I'm still no idea with it...
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-18-2011 , 16:10   Re: Map menu with fixed map in every map.
Reply With Quote #10

First, you want to read all maps into a dynamic array.
Then, you want to grab 5 random ones using the random_range function I provided:
Code:
new mapIndexes[MAX_MAPS]; // we want this many (MAX_MAPS) random_range(0, numMaps - 1, mapIndexes, sizeof(mapIndexes));
numMaps is the size of the dynamic array holding all of the maps.
Then, you loop through the mapIndexes array and get each map from the dynamic array using the indexes from mapIndexes.
When you have the map, you store it in g_MapsNames array.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 03:23.


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