Raised This Month: $12 Target: $400
 3% 

A little help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
QuickDroLLL
Senior Member
Join Date: Dec 2021
Location: AMX Mod X Land
Old 08-15-2022 , 13:50   A little help
Reply With Quote #1

hello every one quickdrolll here so basicly how i can add menu items by just ini file.

Last edited by QuickDroLLL; 08-15-2022 at 13:51.
QuickDroLLL is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 08-15-2022 , 15:40   Re: A little help
Reply With Quote #2

I think, in plugin_init you need to parse that ini file and build a menu depending on what u have in that file.

How simply... If I could understand that parsing routines...

EDIT: I think you can look at https://github.com/OciXCrom/SimpleMenu
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 08-15-2022 at 15:41.
kww is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 08-15-2022 , 16:17   Re: A little help
Reply With Quote #3

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define FILE_NAME "menuitems.ini"

//dynamic array method
new Array:g_aMenuItems;


//double array method
#define MAX_ITEMS 10 //items num
new g_szItemsMenu[MAX_ITEMS][64];

public 
plugin_init()
{
    
g_aMenuItems ArrayCreate(64);
    
readFile()
    
register_clcmd("openMenu""open_menu");
}

public 
plugin_end()
{
    
ArrayDestroy(g_aMenuItems);
}

readFile()
{
    new 
szFile[128], szConfigsDir[64], iFile;
    
get_configsdir(szConfigsDircharsmax(szConfigsDir))
    
formatex(szFilecharsmax(szFile), "%s/%s"szConfigsDirFILE_NAME);

    if((
iFile fopen(szFile"r")) && iFile)
    {
        new 
szFileData[128], i;
        while(
fgets(iFileszFileDatacharsmax(szFileData)))
        {
            
trim(szFileData);
            if(!
szFileData[0] || szFileData[0] == ';')
                continue;

            
//dynamic array method
            
ArrayPushString(g_aMenuItemsszFileData);

            
//double array method an (index of bounds error would be thrown if you would have more than MAX_ITEMS menu items in your menu);
            
copy(g_szItemsMenu[i], charsmax(g_szItemsMenu[]), szFileData);
            
i++
        }
    }
}

public 
open_menu(id)
{
    new 
iMenu menu_create("This is my focking menu""menu_handler"), szItem[64];

    
//dynamic array method
    
for(new 0ArraySize(g_aMenuItems); i++)
    {
        
ArrayGetString(g_aMenuItemsiszItemcharsmax(szItem));
        
menu_additem(iMenuszItem);
    }
    
//

    //double array method 
    
for(new 0MAX_ITEMSi++)
    {
        if(
g_szItemsMenu[i][0] != EOS)
            
menu_additem(iMenug_szItemsMenu[i]);
    }
    
//

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

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

    
client_print(idprint_chat"Wow! You pressed a button!")
    
open_menu(id);

    return 
PLUGIN_CONTINUE;


Last edited by lexzor; 08-15-2022 at 16:21.
lexzor is offline
QuickDroLLL
Senior Member
Join Date: Dec 2021
Location: AMX Mod X Land
Old 08-15-2022 , 19:37   Re: A little help
Reply With Quote #4

Quote:
Originally Posted by lexzor View Post
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define FILE_NAME "menuitems.ini"

//dynamic array method
new Array:g_aMenuItems;


//double array method
#define MAX_ITEMS 10 //items num
new g_szItemsMenu[MAX_ITEMS][64];

public 
plugin_init()
{
    
g_aMenuItems ArrayCreate(64);
    
readFile()
    
register_clcmd("openMenu""open_menu");
}

public 
plugin_end()
{
    
ArrayDestroy(g_aMenuItems);
}

readFile()
{
    new 
szFile[128], szConfigsDir[64], iFile;
    
get_configsdir(szConfigsDircharsmax(szConfigsDir))
    
formatex(szFilecharsmax(szFile), "%s/%s"szConfigsDirFILE_NAME);

    if((
iFile fopen(szFile"r")) && iFile)
    {
        new 
szFileData[128], i;
        while(
fgets(iFileszFileDatacharsmax(szFileData)))
        {
            
trim(szFileData);
            if(!
szFileData[0] || szFileData[0] == ';')
                continue;

            
//dynamic array method
            
ArrayPushString(g_aMenuItemsszFileData);

            
//double array method an (index of bounds error would be thrown if you would have more than MAX_ITEMS menu items in your menu);
            
copy(g_szItemsMenu[i], charsmax(g_szItemsMenu[]), szFileData);
            
i++
        }
    }
}

public 
open_menu(id)
{
    new 
iMenu menu_create("This is my focking menu""menu_handler"), szItem[64];

    
//dynamic array method
    
for(new 0ArraySize(g_aMenuItems); i++)
    {
        
ArrayGetString(g_aMenuItemsiszItemcharsmax(szItem));
        
menu_additem(iMenuszItem);
    }
    
//

    //double array method 
    
for(new 0MAX_ITEMSi++)
    {
        if(
g_szItemsMenu[i][0] != EOS)
            
menu_additem(iMenug_szItemsMenu[i]);
    }
    
//

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

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

    
client_print(idprint_chat"Wow! You pressed a button!")
    
open_menu(id);

    return 
PLUGIN_CONTINUE;

what a greatfull help thank you !!
QuickDroLLL is offline
QuickDroLLL
Senior Member
Join Date: Dec 2021
Location: AMX Mod X Land
Old 08-15-2022 , 19:39   Re: A little help
Reply With Quote #5

Quote:
Originally Posted by kww View Post
I think, in plugin_init you need to parse that ini file and build a menu depending on what u have in that file.

How simply... If I could understand that parsing routines...

EDIT: I think you can look at https://github.com/OciXCrom/SimpleMenu
thank you for your help
QuickDroLLL is offline
Reply


Thread Tools
Display Modes

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 19:33.


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