AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How to get map names and add menu ? (https://forums.alliedmods.net/showthread.php?t=316263)

Hennesy 05-14-2019 16:24

How to get map names and add menu ?
 
Actually the question in the title of the topic.
How can I add to the menu the entire list of maps that is available?
It can be an example without the menu itself, just through menu.additem

asherkin 05-14-2019 16:50

Re: How to get map names and add menu ?
 
https://sm.alliedmods.net/new-api/sourcemod/ReadMapList

Hennesy 05-14-2019 16:57

Re: How to get map names and add menu ?
 
Quote:

Originally Posted by asherkin (Post 2651662)

in fact, it gives me nothing. An example of how to work with this please?

ThatKidWhoGames 05-15-2019 09:14

Re: How to get map names and add menu ?
 
PHP Code:

void CreateMapMenu(int client)
{
    
ArrayList array = new ArrayList(ByteCountToCells(64));
    
ReadMapList(array);
    
int length = array.Length;
    if (!
length)
    {
        
delete array;
        return;
    }

    
Menu menu = new Menu(Menu_Handler);
    
menu.SetTitle("Map Menu\n ");

    
char map[64], displayName[64];
    for (
int i 0lengthi++)
    {
        array.
GetString(imapsizeof(map));
        
GetMapDisplayName(mapdisplayNamesizeof(displayName));
        
menu.AddItem(displayNamedisplayName);
    }

    
delete array;

    
menu.Display(clientMENU_TIME_FOREVER);
}

public 
int Menu_Handler(Menu menuMenuAction actionint clientint param2)
{
    if (
action == MenuAction_Select)
    {
        
// Do stuff
    
} else if (action == MenuAction_End) {
        
delete menu;
    }

    return 
0;



Powerlord 05-15-2019 15:26

Re: How to get map names and add menu ?
 
Might want to change

Code:

ArrayList array = new ArrayList(64);
to
Code:

ArrayList array = new ArrayList(ByteCountToCells(64));
Also, the function GetMapDisplayName exists to resolve Workshop map names for TF2 and CS:GO for the display part of the menu. In theory, it works on other games that support workshop maps as well. If a map isn't a workshop map, it just returns the name unchanged.

ThatKidWhoGames 05-16-2019 11:38

Re: How to get map names and add menu ?
 
Quote:

Originally Posted by Powerlord (Post 2651778)
Might want to change

Code:

ArrayList array = new ArrayList(64);
to
Code:

ArrayList array = new ArrayList(ByteCountToCells(64));
Also, the function GetMapDisplayName exists to resolve Workshop map names for TF2 and CS:GO for the display part of the menu. In theory, it works on other games that support workshop maps as well. If a map isn't a workshop map, it just returns the name unchanged.

Good catch, thanks! Updated my post to reflect Powerlord's proposed changes.


All times are GMT -4. The time now is 20:59.

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