AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   menu with spaces and crooked text (https://forums.alliedmods.net/showthread.php?t=330084)

alexbomjovem 01-19-2021 20:10

menu with spaces and crooked text
 
http://fast.maxigames.com.br/brasilia/cstrike/menuu.jpg


can someone help me fix it


PHP Code:

#include <amxmodx>
#include <amxmisc>

new gFileName[] = "menu.ini";   //Definimos el nombre de nuestro archivo.

#define MAXITEMS    10    //Definimos la cantidad de items que tendrá nuestro menú.
#define ITEMSLEN    32   //Definimos la cantidad de caracteres que podrá poseer el nombre de cada item del menu.

/* Items */
new gItems[MAXITEMS+1][ITEMSLEN+1]; //Aquí guardaremos los items de nuestro menú.

public plugin_init()
{
    
/* Plugin Registration */
    
register_plugin("[GUIA] Menu by *.ini file""0.0.1""SicknessArG");
    
    
/* Command */
    
register_clcmd("say /menu""cmdMenu");
}


public 
cmdMenu(id)
{
    new 
menu menu_create("\yMenu\w""cmdMenuHandler");   //Creamos el menú.
    
    
new Path[256];  //Creamos esta variable para luego usarla para obtener la ruta de la carpeta configs.
    
get_configsdir(Pathcharsmax(Path));   //Que RÁPIDO! ... Obtenemos la ruta a la carpeta configs.
    
formatex(Pathcharsmax(Path),"%s/%s"PathgFileName);    //Declaramos que Path ahora es la ruta a nuestro archivo.
    
    
if(!file_exists(Path))  //Chequeamos si nuestro archivo existe.
    
{
        
client_print(idprint_chat"[AMXX] El archivo %s no existe"gFileName);
        return 
PLUGIN_HANDLED;  //Sino, paramos ahí y no hacemos mas nada y seguís leyendo al pedo.
    
}
    
    new 
fopen(Path"rt");  //Si existe, leemos el texto del archivo (r = read) (t = text).
    
    
new iName[ITEMSLEN+1];  //Creamos una variable para el nombre de cada item del menu.
    
new Item;   //Creamos una variable para el numero de cada item.
    
    
while(!feof(f)) //Mientras que nuestro archivo este abierto...
    
{
        
fgets(fiNamecharsmax(iName));   //Obtenemos el nombre de cada item y lo guardamos dentro de la variable iName.

        
if(!iName[0] || iName[0] == ';'   //(No necesario, pero sirve), esto es para que si en el archivo un texto comienza con
        
|| iName[0] == '/' && iName[1] == '/' ) continue;   // ; o // no sea leído y por lo tanto no aparezca en nuestro menú.
        
        
copy(gItems[Item], charsmax(gItems), iName);    //Copiamos cada item dentro de la variable gItems.
        
Item++;      //Aumentamos la cantidad de items, cuyo valor es igual a la cantidad puesta en el archivo ini
                            //pero menor o igual a la cantidad definida en MAXITEMS.
                                    
        
if(Item >= MAXITEMS) break;   //Porque si la cantidad de items supera a MAXITEMS se rompe el loop y no continua nuestro plugin.
        
        
menu_additem(menuiNamegItems[Item]);        //Pero sino, adherimos cada item en el menú.
    
}
    
fclose(f);  //Cerramos nuestro archivo.
    
    
menu_display(idmenu); //Mostramos el menú.
    
return PLUGIN_HANDLED;
}

public 
cmdMenuHandler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
iData[6];
    new 
iName[ITEMSLEN+1];
    new 
Access;
    new 
Callback;
    
menu_item_getinfo(menuitemAccessiDatacharsmax(iData), iNamecharsmax(iName), Callback);

    
client_print(idprint_chat"Haz elegido %s"iName);  //Y al elegir un item se mostrará el nombre en el chat.
        
    
menu_destroy(menu);  //Cerramos el menú.
    
return PLUGIN_HANDLED;  //FIN.


file.ini where the menu fetches the items to add
PHP Code:

ORIGINAL
amarela
BRANCA
LARANJA
FACÃO
MACHADO 


fysiks 01-20-2021 02:54

Re: menu with spaces and crooked text
 
That code with what you claim is the INI file contents did not generate the menu in that image. Attach the .sma file and the menu.ini file to your post.

hitD 01-20-2021 05:20

Re: menu with spaces and crooked text
 
As you read all line, you also read the new line symbol. So when u do with fgets you need to add one line of code to replace the ^n symbol with empty.
After fgets method add this.
PHP Code:

replace(iNamecharsmax(iName), "^n"""


fysiks 01-21-2021 00:34

Re: menu with spaces and crooked text
 
Quote:

Originally Posted by hitD (Post 2733368)
As you read all line, you also read the new line symbol. So when u do with fgets you need to add one line of code to replace the ^n symbol with empty.
After fgets method add this.
PHP Code:

replace(iNamecharsmax(iName), "^n"""


I missed that. However, it is better to use trim(iName) trim whitespace.


All times are GMT -4. The time now is 10:37.

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