Raised This Month: $32 Target: $400
 8% 

menu with spaces and crooked text


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alexbomjovem
New Member
Join Date: Jul 2018
Location: brasil
Old 01-19-2021 , 20:10   menu with spaces and crooked text
Reply With Quote #1




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 

Last edited by alexbomjovem; 01-19-2021 at 23:53.
alexbomjovem is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-20-2021 , 02:54   Re: menu with spaces and crooked text
Reply With Quote #2

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.
__________________
fysiks is offline
hitD
Junior Member
Join Date: May 2017
Location: Lithuania
Old 01-20-2021 , 05:20   Re: menu with spaces and crooked text
Reply With Quote #3

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"""

Last edited by hitD; 01-20-2021 at 05:21. Reason: Edit
hitD is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-21-2021 , 00:34   Re: menu with spaces and crooked text
Reply With Quote #4

Quote:
Originally Posted by hitD View Post
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.
__________________
fysiks 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:46.


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