AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved how to add item for the category number 8 of the menu (https://forums.alliedmods.net/showthread.php?t=336520)

Supremache 02-25-2022 11:30

how to add item for the category number 8 of the menu
 
how to add item for the category number 8 of the menu or how to replace an item instead of back category ? I tried some ways but some of these ways do shut down the server and others send error messages:

I tried this but is not work:
PHP Code:

menu_setpropiMenuMPROP_BACKNAMEfmt"\wTest Item %s"IsHouriStartiEnd ) ? "\y[Active]" "\d[Disactive]" ) )

//menu handler:
switch( iItem )
    {
        case 
MENU_EXITmenu_destroyiMenu );
        case 
MENU_BACKclient_print_coloridprint_team_default"^4[Items]^1 Test Item is not active^1.")//, iStart, iEnd )
/// code.... 

It replacing the name but can't press on it, also i wanna use it with array so i dont want to use just 8 categories by using the old menu style or adding menu_setprop( iMenu, MPROP_PERPAGE, 0 ); and use menu_additem

zXCaptainXz 02-25-2022 11:41

Re: how to add item for the category number 8 of the menu
 
Use the old menu system and save yourself a lot of headaches.

Supremache 02-25-2022 11:52

Re: how to add item for the category number 8 of the menu
 
Quote:

Originally Posted by zXCaptainXz (Post 2772434)
Use the old menu system and save yourself a lot of headaches.

Read again, also the old menu system is the same of the new but the difference thing is the new has created with stock that let the menu be easier to use, Also I remember i saw it on a plugin but couldn't find it

Edit: is it possible or not with new menu style?


Tried but i can not press the category:
PHP Code:

public CreateSubMenuid )
{
    new 
szPlayersMAX_PLAYERS ], iNumszID], iMenu menu_create"Test""SubMenuHandler" );
    
get_playersszPlayersiNum"ch" );
    
    for( new 
iNumi++)
    {
        
num_to_striszIDcharsmaxszID ) );
        
menu_additemiMenufmt"%n"id ), szID );
    }
    
    
menu_setpropiMenuMPROP_BACKNAME"\wReplace item" )
    
    if( !
menu_pagesiMenu ) )
    {
        
client_printidprint_chat"There's no players found...")
    }
    else 
menu_displayidiMenu, .page );

    return 
PLUGIN_HANDLED;
}

public 
SubMenuHandleridiMenuiItem 
{
    switch( 
iItem )
    {
        case 
MENU_EXITmenu_destroyiMenu );
        case 
MENU_BACKclient_print_coloridprint_team_default"^4[Items]^1 Test category number 8^1.")
    }

    return 
PLUGIN_HANDLED;



iceeedr 02-25-2022 17:22

Re: how to add item for the category number 8 of the menu
 
https://forums.alliedmods.net/showthread.php?t=147393

Supremache 02-25-2022 17:42

Re: how to add item for the category number 8 of the menu
 
Quote:

Originally Posted by iceeedr (Post 2772450)

Quote:

I wanna use it with array so i dont want to use just 8 categories by using the old menu style or adding menu_setprop( iMenu, MPROP_PERPAGE, 0 ); and use menu_additem
Quote:

Edit: is it possible or not with new menu style?
If it is possible, how because of If it is not possible then i have no choice i will type a lot with using old menu style

EFFx 02-25-2022 19:40

Re: how to add item for the category number 8 of the menu
 
Check if that helps you

zXCaptainXz 02-25-2022 21:15

Re: how to add item for the category number 8 of the menu
 
Quote:

Originally Posted by Supremache (Post 2772436)
Read again, also the old menu system is the same of the new but the difference thing is the new has created with stock that let the menu be easier to use, Also I remember i saw it on a plugin but couldn't find it

Edit: is it possible or not with new menu style?

I’m saying that because new menus are not easy to help you out with, they behave differently depending on your AMXX version. I gave up on 1.8.2 menus because they are buggy and a nightmare to customize, it’s just a one trick pony which can only properly do what it does by default.

What AMXX version are you currently using so we can better try to help you?

EDIT: If you need help with old menus, you can check out how they’re done in the base AMXX plugins, they use 8 items with 9 for back and 0 for next.

CrazY. 02-26-2022 08:44

Re: how to add item for the category number 8 of the menu
 
You can easily make a new menu out of the old menu.
Say /menu to pop up our cool menu.

Code:

#include <amxmodx>
#include <amxmisc>

new Array:g_menuItems

new g_playerMenuPage[33]
new g_playerMenuItemData[33][10]

public plugin_init()
{
        g_menuItems = ArrayCreate(32)

        for (new i = 1; i <= 20; i++)
        {
                ArrayPushString(g_menuItems, fmt("Item %d", i))
        }

        register_clcmd("say /menu", "ShowMenu")

        register_menu("Cool Menu", -1, "MenuHandler")
}

public ShowMenu(index)
{
        const itemsPerPage = 7
        new itemCount = ArraySize(g_menuItems)
        new pageCount = floatround(itemCount / float(itemsPerPage), floatround_ceil)
        new page = clamp(g_playerMenuPage[index], 0, pageCount - 1)
        new offset = page * itemsPerPage

        new buffer[32], menu[MAX_MENU_LENGTH], len, key

        len = copy(menu, charsmax(menu), "\yCool Menu")

        if (pageCount > 1)
        {
                len += formatex(menu[len], charsmax(menu) - len, " %d/%d", page + 1, pageCount)
        }

        len += copy(menu[len], charsmax(menu) - len, "^n^n")

        arrayset(g_playerMenuItemData[index], -1, sizeof g_playerMenuItemData[])

        for (new i = offset, limit = min(itemCount, offset + itemsPerPage); i < limit; i++)
        {
                ArrayGetString(g_menuItems, i, buffer, charsmax(buffer))
                g_playerMenuItemData[index][key] = i
                len += formatex(menu[len], charsmax(menu) - len, "\r%d. \w%s^n", ++key, buffer)
        }

        for (new i = key; i <= itemsPerPage; i++)
        {
                len += copy(menu[len], charsmax(menu) - len, "^n")
        }

        if (pageCount > 1)
        {
                if (page > 0)
                {
                        len += copy(menu[len], charsmax(menu) - len, "\r8. \wBack^n")
                }
                else
                {
                        len += copy(menu[len], charsmax(menu) - len, "\r8. \dBack^n")
                }
               
                if (page < pageCount - 1)
                {
                        len += copy(menu[len], charsmax(menu) - len, "\r9. \wMore^n")
                }
                else
                {
                        len += copy(menu[len], charsmax(menu) - len, "\r9. \dMore^n")
                }
        }

        len += copy(menu[len], charsmax(menu) - len, "\r0. \wExit")

        g_playerMenuPage[index] = page

        show_menu(index, -1, menu, -1, "Cool Menu")
}

public MenuHandler(index, key)
{
        switch (key)
        {
                case 7:
                {
                        // Back
                        g_playerMenuPage[index] -= 1
                        ShowMenu(index)
                }
                case 8:
                {
                        // More
                        g_playerMenuPage[index] += 1
                        ShowMenu(index)
                }
                case 9:
                {
                        // Exit
                }
                default:
                {
                        new item = g_playerMenuItemData[index][key]

                        if (0 <= item < ArraySize(g_menuItems))
                        {
                                new buffer[32]
                                ArrayGetString(g_menuItems, item, buffer, charsmax(buffer))
                                client_print(index, print_chat, "You've selected ^"%s^"", buffer)
                        }

                        ShowMenu(index)
                }
        }

        return PLUGIN_HANDLED
}

https://i.imgur.com/LTX2Fa7.png

Supremache 02-26-2022 13:29

Re: how to add item for the category number 8 of the menu
 
I thought it was possible to do this with the new menu system.
Anyway, thank you all I will be using the old system.

Supremache 04-21-2022 18:28

Re: how to add item for the category number 8 of the menu
 
@CrazY.
I tried using the code you posted but I ran into a problem when I tried to create multiple menus together and I don't know how to fix it, this what i did:

Code:

#include <amxmodx>
#include <amxmisc>

new Array:g_menuItems

enum _:ArrayTest
{
        Location,
        Item[ 32 ]
}

new g_playerMenuPage[33]
new g_menuloction[33]
new g_playerMenuItemData[33][10]
new eData[ ArrayTest ]

public plugin_init()
{
        g_menuItems = ArrayCreate(ArrayTest)

        for (new i = 1; i <= 5; i++)
        {
                eData[ Location ] = 1;
                copy( eData[ Item ], charsmax( eData[ Item ] ), fmt( "Item %d", i ) )
                ArrayPushArray(g_menuItems, eData )
        }
       
        for (new i = 1; i <= 5; i++)
        {
                eData[ Location ] = 2;
                copy( eData[ Item ], charsmax( eData[ Item ] ), fmt( "ItemPlus %d", i ) )
                ArrayPushArray(g_menuItems, eData )
        }

        register_clcmd("say /menu", "@TestMenu")

        register_menu("Cool Menu", -1, "MenuHandler")
}

@TestMenu( id )
{
        new iMenu = menu_create( "\yTest Menu:", "@TestHandler" );
       
        menu_additem( iMenu, "Location One", "1" );
        menu_additem( iMenu, "Location Two", "2" );
       
        menu_display(id, iMenu)
        return PLUGIN_HANDLED;
}

@TestHandler( id, iMenu, iItem )
{
        if(iItem != MENU_EXIT)
        {
                new szData[ 10 ], iUnused;
                menu_item_getinfo( iMenu, iItem, iUnused, szData, charsmax( szData ), .callback = iUnused )
               
                new iItemID = str_to_num( szData );
               
                ShowMenu(id, iItemID )
        }
        menu_destroy(iMenu);
        return PLUGIN_HANDLED;

}


public ShowMenu(index, iLocation )
{
        const itemsPerPage = 7
        new itemCount = ArraySize(g_menuItems)
        new pageCount = floatround(itemCount / float(itemsPerPage), floatround_ceil)
        new page = clamp(g_playerMenuPage[index], 0, pageCount - 1)
        new offset = page * itemsPerPage
        g_menuloction[ index ] = iLocation
        new menu[MAX_MENU_LENGTH], len, key

        len = copy(menu, charsmax(menu), "\yCool Menu")

        if (pageCount > 1)
        {
                len += formatex(menu[len], charsmax(menu) - len, " %d/%d", page + 1, pageCount)
        }

        len += copy(menu[len], charsmax(menu) - len, "^n^n")

        arrayset(g_playerMenuItemData[index], -1, sizeof g_playerMenuItemData[])

        for (new i = offset, limit = min(itemCount, offset + itemsPerPage); i < limit; i++)
        {
                ArrayGetArray(g_menuItems, i, eData )
               
                if( eData[ Location ] && eData[ Location ] != iLocation )
                {
                        continue;
                }
               
                g_playerMenuItemData[index][key] = i
               
                len += formatex(menu[len], charsmax(menu) - len, "\r%d. \w%s^n", ++key, eData[ Item ])
               
        }

        for (new i = key; i <= itemsPerPage; i++)
        {
                len += copy(menu[len], charsmax(menu) - len, "^n")
        }

        if (pageCount > 1)
        {
                if (page > 0)
                {
                        len += copy(menu[len], charsmax(menu) - len, "\r8. \wBack^n")
                }
                else
                {
                        len += copy(menu[len], charsmax(menu) - len, "\r8. \dBack^n")
                }
               
                if (page < pageCount - 1)
                {
                        len += copy(menu[len], charsmax(menu) - len, "\r9. \wMore^n")
                }
                else
                {
                        len += copy(menu[len], charsmax(menu) - len, "\r9. \dMore^n")
                }
        }

        len += copy(menu[len], charsmax(menu) - len, "\r0. \wExit")

        g_playerMenuPage[index] = page

        show_menu(index, -1, menu, -1, "Cool Menu")
}

public MenuHandler(index, key)
{
        switch (key)
        {
                case 7:
                {
                        // Back
                        g_playerMenuPage[index] -= 1
                        ShowMenu(index, g_menuloction[ index ])
                }
                case 8:
                {
                        // More
                        g_playerMenuPage[index] += 1
                        ShowMenu(index, g_menuloction[ index ])
                }
                case 9:
                {
                        // Exit
                }
                default:
                {
                        new item = g_playerMenuItemData[index][key]

                        if (0 <= item < ArraySize(g_menuItems))
                        {
                                new buffer[32]
                                ArrayGetString(g_menuItems, item, buffer, charsmax(buffer))
                                client_print(index, print_chat, "You've selected ^"%s^"", buffer)
                        }

                        ShowMenu(index, g_menuloction[ index ])
                }
        }

        return PLUGIN_HANDLED
}

Menu number one:

https://i.ibb.co/Js1WcT2/12.png https://i.ibb.co/82hgPqd/33.png

Menu number two:

https://i.ibb.co/SB00z2D/441.png https://i.ibb.co/t3zMRwF/gaga.png

As you can see, they are combined, each menu is reading the same number, not like the new menu style, Please try to test the code to understand more about the issue.


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

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