AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Solved [REQ] Plugin /maps (https://forums.alliedmods.net/showthread.php?t=338619)

JohnyS 07-17-2022 11:45

[REQ] Plugin /maps
 
Hello
Can somebody help me with a plugin that imports all map names from maps.ini and display them in a menu on any user whe it writes /maps?

lexzor 07-17-2022 13:32

Re: [REQ] Plugin /maps
 
PHP Code:

#include <amxmodx>
#include <amxmisc>

new Array:g_aMaps;

public 
plugin_init()
{
    
register_plugin("/maps""1.0""AMXX Community");

    
g_aMaps ArrayCreate(64);
    
import_maps();

    
register_clcmd("say /maps""mapsHandle");
    
register_clcmd("say_team /maps""mapsHandle");
}

public 
plugin_end()
{
    
ArrayDestroy(g_aMaps);
}

import_maps()
{
    new 
szConfigsDir[64], szFile[128];
    
get_configsdir(szConfigsDircharsmax(szConfigsDir));

    
formatex(szFilecharsmax(szFile), "%s/maps.ini"szConfigsDir);

    if(
file_exists(szFile))
    {
        new 
iFile fopen(szFile"r");
        new 
szMaps[64];

        while(
fgets(iFileszMapscharsmax(szMaps)))
        {
            
ArrayPushString(g_aMapsszMaps);
        }

        
fclose(iFile);
    }
}

public 
mapsHandle(id)
{
    if(
is_user_connected(id))
    {
        new 
iSize ArraySize(g_aMaps);

        if(
iSize 0)
        {
            new 
szMap[64]
            
client_print(idprint_console"^n[-] Available maps [-]^n")
            for(new 
ii<iSizei++)
            {
                
ArrayGetString(g_aMapsiszMapcharsmax(szMap));
                
client_print(idprint_console"* %s"szMap);
            }

            
client_print(idprint_console"^n[-] Available maps [-]^n")
        } else 
client_print(idprint_console"^n[-] There are no available maps in the list [-]^n")

        
engclient_cmd(id"toggleconsole");
    }



JohnyS 07-17-2022 15:08

Re: [REQ] Plugin /maps
 
Can you make the list into a hud menu instead of opening console? Some players clients dont accept commands sent from server and won't open the console

lexzor 07-17-2022 15:36

Re: [REQ] Plugin /maps
 
PHP Code:

#include <amxmodx>
#include <amxmisc>

new Array:g_aMaps;

public 
plugin_init()
{
    
register_plugin("/maps""1.0""AMXX Community");

    
g_aMaps ArrayCreate(64);
    
import_maps();

    
register_clcmd("say /maps""mapsHandle");
    
register_clcmd("say_team /maps""mapsHandle");
}

public 
plugin_end()
{
    
ArrayDestroy(g_aMaps);
}

import_maps()
{
    new 
szConfigsDir[64], szFile[128];
    
get_configsdir(szConfigsDircharsmax(szConfigsDir));

    
formatex(szFilecharsmax(szFile), "%s/maps.ini"szConfigsDir);

    if(
file_exists(szFile))
    {
        new 
iFile fopen(szFile"r");
        new 
szMaps[64];

        while(
fgets(iFileszMapscharsmax(szMaps)))
        {
            
ArrayPushString(g_aMapsszMaps);
        }

        
fclose(iFile);
    }
}

public 
mapsHandle(id)
{
    if(
is_user_connected(id))
    {
        new 
iSize ArraySize(g_aMaps);

        if(
iSize 0)
        {
            new 
szMap[64], szTitle[64];
            
formatex(szTitlecharsmax(szTitle), "Maps available on server \r[%i]"iSize)
            new 
iMenu menu_create(szTitle"menu_handler");

            for(new 
ii<iSizei++)
            {
                
ArrayGetString(g_aMapsiszMapcharsmax(szMap));
                
menu_additem(iMenuszMap)
            }

            
menu_setprop(iMenuMPROP_EXITMEXIT_ALL);
            if(
is_user_connected(id))
                
menu_display(idiMenu0, -1);

        } else 
client_print(idprint_chat"There are no available maps in the list")
    }


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

    
mapsHandle(id);

    return 
PLUGIN_CONTINUE;



JohnyS 07-17-2022 16:18

Re: [REQ] Plugin /maps
 
Got this error when i try to compile
HTML Code:

maplist.sma(63) : error 088: number of arguments does not match definition

Barlap 07-17-2022 17:46

Re: [REQ] Plugin /maps
 
Try this my dude
HTML Code:

#include <amxmodx>
#include <amxmisc>

new Array:g_aMaps;

public plugin_init()
{
    register_plugin("/maps", "1.0", "AMXX Community");

    g_aMaps = ArrayCreate(64);
    import_maps();

    register_clcmd("say /maps", "mapsHandle");
    register_clcmd("say_team /maps", "mapsHandle");
}

public plugin_end()
{
    ArrayDestroy(g_aMaps);
}

import_maps()
{
    new szConfigsDir[64], szFile[128];
    get_configsdir(szConfigsDir, charsmax(szConfigsDir));

    formatex(szFile, charsmax(szFile), "%s/maps.ini", szConfigsDir);

    if(file_exists(szFile))
    {
        new iFile = fopen(szFile, "r");
        new szMaps[64];

        while(fgets(iFile, szMaps, charsmax(szMaps)))
        {
            ArrayPushString(g_aMaps, szMaps);
        }

        fclose(iFile);
    }
}

public mapsHandle(id)
{
    if(is_user_connected(id))
    {
        new iSize = ArraySize(g_aMaps);

        if(iSize > 0)
        {
            new szMap[64], szTitle[64];
            formatex(szTitle, charsmax(szTitle), "Maps available on server \r[%i]", iSize)
            new iMenu = menu_create(szTitle, "menu_handler");

            for(new i; i<iSize; i++)
            {
                ArrayGetString(g_aMaps, i, szMap, charsmax(szMap));
                menu_additem(iMenu, szMap)
            }

            menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL);
            if(is_user_connected(id))
            menu_display(id, iMenu, 0);

        } else client_print(id, print_chat, "There are no available maps in the list")
    }
}

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

    mapsHandle(id);

    return PLUGIN_CONTINUE;
}


JohnyS 07-17-2022 18:21

Re: [REQ] Plugin /maps
 
Now it works.
But one more question:
How to get rid of those spaces from the menu?
https://i.imgur.com/g2pZuN2.jpg

lexzor 07-17-2022 19:26

Re: [REQ] Plugin /maps
 
PHP Code:

#include <amxmodx>
#include <amxmisc>

new Array:g_aMaps;

public 
plugin_init()
{
    
register_plugin("/maps""1.0""AMXX Community");

    
g_aMaps ArrayCreate(64);
    
import_maps();

    
register_clcmd("say /smaps""mapsHandle");
    
register_clcmd("say_team /smaps""mapsHandle");
    
register_clcmd("amx_maps""mapsHandle");
}

public 
plugin_end()
{
    
ArrayDestroy(g_aMaps);
}

import_maps()
{
    new 
szConfigsDir[64], szFile[128];
    
get_configsdir(szConfigsDircharsmax(szConfigsDir));

    
formatex(szFilecharsmax(szFile), "%s/maps.ini"szConfigsDir);

    if(
file_exists(szFile))
    {
        new 
iFile fopen(szFile"r");
        new 
szMaps[64];

        while(
fgets(iFileszMapscharsmax(szMaps)))
        {
            
ArrayPushString(g_aMapsszMaps);
        }

        
fclose(iFile);
    }
}

public 
mapsHandle(id)
{
    if(
is_user_connected(id))
    {
        new 
iSize ArraySize(g_aMaps);

        if(
iSize 0)
        {
            new 
szMap[64], szTitle[64];
            
formatex(szTitlecharsmax(szTitle), "\yMaps\w available on server \r[%i]\w"iSize)
            new 
iMenu menu_create(szTitle"menu_handler");

            for(new 
iiSizei++)
            {
                
ArrayGetString(g_aMapsiszMapcharsmax(szMap));
                
trim(szMap);
                
menu_additem(iMenuszMap)
            }

            
menu_setprop(iMenuMPROP_EXITMEXIT_ALL);
            if(
is_user_connected(id))
                
menu_display(idiMenu0);

        } else 
client_print(idprint_chat"There are no available maps in the list")
    }


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

    
mapsHandle(id);

    return 
PLUGIN_CONTINUE;



JohnyS 07-17-2022 19:51

Re: [REQ] Plugin /maps
 
It works.
Marking topic as closed.

tarsisd2 07-18-2022 05:28

Re: [REQ] Plugin /maps
 
if you use map manager, when you type /maps it shows all the maps and you can choose one to nominate


All times are GMT -4. The time now is 18:42.

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