AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu remaking (https://forums.alliedmods.net/showthread.php?t=223322)

~Ice*shOt 08-12-2013 07:13

Menu remaking
 
I have code with two menus, could anyone help to do everything in one menu?

PHP Code:

#include <amxmodx>

#define Max 4

new SelUnlocked[Max]
new 
SelSelected[33]

new 
PlayerPts[33]

new const 
Selections[Max][] = { "First""Second""Third""Fourth" }
new const 
SelCosts[Max] = { 10030050500 }

public 
plugin_init()
{
    
register_clcmd("say /menu""Main_plMenu")
    
register_clcmd("say /menu2""Main_plMenu2")

    
register_clcmd("say /pts""GivePts")
}

public 
GivePts(id)
{
    
PlayerPts[id] += 100
}

public 
Main_plMenu(id)
{
    new 
Menu menu_create("\rSelections to unlock:""plMenu")

    for (new 
0Maxi++)
    {
        new 
Items[512], TempID[32]

        if (
PlayerPts[id] >= SelCosts[i])
        {
            
formatex(Itemscharsmax(Items), "\y%s \d[\w%d Pts\d]"Selections[i], SelCosts[i])

            
num_to_str(iTempIDcharsmax(TempID))

            
menu_additem(MenuItemsTempID0)
        }
        else
        {
            
formatex(Itemscharsmax(Items), "\d%s [\r*LOCKED* Need %i Pts\d]"Selections[i], SelCosts[i])
            
menu_additem(MenuItems"999"0menu_makecallback("Callback_Menu"))
        }
    }
    
menu_setprop(MenuMPROP_EXITMEXIT_ALL)
    
menu_display(idMenu0)
}

public 
plMenu(idMenuItem)
{
    if (
Item == MENU_EXIT
    {
        
menu_destroy(Menu)
        return 
PLUGIN_HANDLED
    
}

    new 
Data[6], iName[64]
    new 
AccessCallback
    menu_item_getinfo
(MenuItemAccessData5iName63Callback)

    new 
Key str_to_num(Data)

    
PlayerPts[id] -= SelCosts[Key]

    
SelUnlocked[Key] = true

    PrintColor
(id"You unlocked %s Selection!"Selections[Key])

    return 
PLUGIN_HANDLED
}

public 
Main_plMenu2(id)
{
    new 
Menu menu_create("\rSelections to switch:""plMenu2")

    for (new 
0Maxi++)
    {
        new 
Items[512], TempID[32]

        if (
SelUnlocked[i])
        {
            if (
SelSelected[id] == i)
            {
                
formatex(Itemscharsmax(Items), "\d%s [\rSelected\d]"Selections[i])
                
menu_additem(MenuItems"999"0menu_makecallback("Callback_Menu"))
            }
            else
            {
                
formatex(Itemscharsmax(Items), "\y%s"Selections[i])

                
num_to_str(iTempIDcharsmax(TempID))

                
menu_additem(MenuItemsTempID0)
            }
        }
        else
        {
            
formatex(Itemscharsmax(Items), "\d%s [\r*LOCKED* Need %i Pts\d]"Selections[i], SelCosts[i])
            
menu_additem(MenuItems"999"0menu_makecallback("Callback_Menu"))
        }

    }
    
menu_setprop(MenuMPROP_EXITMEXIT_ALL)
    
menu_display(idMenu0)
}

public 
plMenu2(idMenu Item)
{
    if (
Item == MENU_EXIT
    {
        
menu_destroy(Menu)
        return 
PLUGIN_HANDLED
    
}

    new 
Data[6], iName[64]
    new 
AccessCallback
    menu_item_getinfo
(MenuItemAccessData5iName63Callback)

    new 
Key str_to_num(Data)

    
SelSelected[id] = Key

    PrintColor
(id"You Selected %s Selection!"Selections[Key])

    
menu_destroy(Menu)
    return 
PLUGIN_HANDLED
}

public 
Callback_Menu(idMenuItem)
{
    return 
ITEM_DISABLED



Black Rose 08-13-2013 14:18

Re: Menu remaking
 
https://forums.alliedmods.net/showthread.php?t=154538

I don't understand what you want. Explain how the menu should work exactly.

~Ice*shOt 08-13-2013 14:35

Re: Menu remaking
 
You see two menu, I need to join theses menu to one

Black Rose 08-13-2013 17:58

Re: Menu remaking
 
1 Attachment(s)
Before my answer I just want to show people how a GOOD explanation looks like.
Quote:

Originally Posted by ~Ice*shOt
--------------------------------------------------
Here is main menu.
--------------------------------------------------
// All theses disabled
1. First [ Need 200 $ ]
2. Second [ Need 600 $ ]
3. Third [ Need 800 $ ]
4. Fourth [ Need 300 $ ]
--------------------------------------------------
For example I have 200 $ and press #1.
--------------------------------------------------
// #1 enabled, others disabled
1. First
2. Second [ Need 600 $ ]
3. Third [ Need 800 $ ]
4. Fourth [ Need 300 $ ]
--------------------------------------------------
Again press #1.
--------------------------------------------------
// All theses disabled
1. First [ Selected ]
2. Second [ Need 600 $ ]
3. Third [ Need 800 $ ]
4. Fourth [ Need 300 $ ]
--------------------------------------------------
Now I have collected 300 $ and press #4
--------------------------------------------------
// #4 enabled, others disabled
1. First [ Selected ]
2. Second [ Need 600 $ ]
3. Third [ Need 800 $ ]
4. Fourth
--------------------------------------------------
Again press #4
--------------------------------------------------
// #1 enabled, others disabled
1. First
2. Second [ Need 600 $ ]
3. Third [ Need 800 $ ]
4. Fourth [ Selected ]
//////////////
All this I've in two menus.. one needed

Here's my result:
https://forums.alliedmods.net/attach...1&d=1376431090

This code won't allow you to chose "nothing" as soon as you chose something. Is that something you need?
And here is the code:
Code:
#include <amxmodx> #define MENUITEM_DISABLED   (1<<26) enum enumSelections {     name[32],     cost } new const g_Selections[][enumSelections] = {     { "First" , 100 },     { "Second" , 300 },     { "Third" , 50 },     { "Fourth" , 500 } }; new bool:g_Unlocked[33][sizeof g_Selections]; new g_Selected[33]; new g_Points[33]; public plugin_init() {     register_plugin("Dual Action Menu", "1.0", "[ --{-@ ]");     register_clcmd("menu", "cmd_menu");     register_clcmd("say /pts", "GivePts"); } public client_connect(id) {     g_Points[id] = 0;     g_Selected[id] = -1; } public GivePts(id) {     g_Points[id] += 100; } public cmd_menu(id) {     new menu = menu_create("\rHello pirate!", "menu_handler")     for ( new i = 0; i < sizeof g_Selections ; i++ ) {         new menuitem[64], menuitem_disable = 0;                 if ( g_Selected[id] == i ) {             formatex(menuitem, charsmax(menuitem), "\d%s   [SELECTED]", g_Selections[i][name])             menuitem_disable = MENUITEM_DISABLED;         }         else if ( g_Unlocked[id][i] )             formatex(menuitem, charsmax(menuitem), "\y%s", g_Selections[i][name])         else if ( g_Points[id] < g_Selections[i][cost] ) {             formatex(menuitem, charsmax(menuitem), "\d%s   \d[\r%d Pts\d]", g_Selections[i][name], g_Selections[i][cost])             menuitem_disable = MENUITEM_DISABLED;         }         else             formatex(menuitem, charsmax(menuitem), "\y%s   \d[\w%d Pts\d]", g_Selections[i][name], g_Selections[i][cost])                 menu_additem(menu, menuitem, "", menuitem_disable);     }         menu_display(id, menu, 0) } public menu_handler(id, menu, item) {     if ( item == MENU_EXIT ) {         menu_destroy(menu)         return PLUGIN_HANDLED     }         if ( g_Unlocked[id][item] ) {             g_Selected[id] = item;         client_print(id, print_chat, "You have selected %s", g_Selections[item][name]);                 return PLUGIN_CONTINUE     }         g_Points[id] -= g_Selections[item][cost];     g_Unlocked[id][item] = true;         client_print(id, print_chat, "You have unlocked %s", g_Selections[item][name]);         return PLUGIN_HANDLED }

~Ice*shOt 08-14-2013 04:25

Re: Menu remaking
 
OMG Man, you're awesome. Thanks a lot! It's exactly what i need.


All times are GMT -4. The time now is 15:55.

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