AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Map menu with fixed map in every map. (https://forums.alliedmods.net/showthread.php?t=164600)

GarbageBox 08-13-2011 12:08

Map menu with fixed map in every map.
 
1 Attachment(s)
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;
}


fysiks 08-13-2011 17:02

Re: Map menu with fixed map in every map.
 
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).

GarbageBox 08-14-2011 02:10

Re: Map menu with fixed map in every map.
 
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?

fysiks 08-14-2011 02:37

Re: Map menu with fixed map in every map.
 
I think Exolent has a function to get random numbers without repeating. I would probably use that and use only those indexes.

Blue Snake. 08-14-2011 12:25

Re: Map menu with fixed map in every map.
 
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.

GarbageBox 08-15-2011 14:33

Re: Map menu with fixed map in every map.
 
Quote:

Originally Posted by Blue Snake. (Post 1532454)
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:oops:
Can you tell more detail about it and I update a little of my code in #1.

Exolent[jNr] 08-15-2011 14:42

Re: Map menu with fixed map in every map.
 
Quote:

Originally Posted by Blue Snake. (Post 1532454)
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.

GarbageBox 08-16-2011 08:09

Re: Map menu with fixed map in every map.
 
Quote:

Originally Posted by Exolent[jNr] (Post 1533239)
That's a bad method.
See my tutorial about getting random values from an array.

I decided to give up:oops:
I had watch your tutorial's. It seems very difficult to me:shock:

Exolent[jNr] 08-16-2011 10:11

Re: Map menu with fixed map in every map.
 
Quote:

Originally Posted by GarbageBox (Post 1533772)
I decided to give up:oops:
I had watch your tutorial's. It seems very difficult to me:shock:

Getting random values isn't difficult at all.

You basically want to set up all values you want in an array.
Then, as you select values, delete them from the array.

Code:
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; }

fysiks 08-16-2011 15:13

Re: Map menu with fixed map in every map.
 
Quote:

Originally Posted by GarbageBox (Post 1533772)
I decided to give up:oops:
I had watch your tutorial's. It seems very difficult to me:shock:

You don't have to understand how the function works at all. You just need to know how to give it the arguments.


All times are GMT -4. The time now is 03:23.

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