AlliedModders

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

marky_uk 03-28-2009 23:47

Menu's
 
Yeah, me again >.<
Right well I've been working on menus for 2 days now...really am stumped. I've read the tutorials on using the new menus but I just don't understand how I call another menu from a menu.

I can get the first menu to display. But the second menu doesnt want to pop up.

Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
 
new PLUGIN[]="PlayerMODMenu"
new AUTHOR[]="Marky_UK"
new VERSION[]="1.00"

new g_MainMenu
new g_HPMenu
//new g_HPValue

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_clcmd("amx_playermenu","mainmenu",ADMIN_CFG,"Opens players menu")
}

public mainmenu(id)
{
    g_MainMenu = menu_create("Player Menu","mainmenu_handle")
    menu_additem(g_MainMenu, "Health", "1")
    menu_setprop(g_MainMenu, MPROP_EXIT, MEXIT_ALL)
    menu_display(id, g_MainMenu, 0)
    return PLUGIN_HANDLED
}

public hpmenu(id)
{
    g_HPMenu = menu_create("Health","hpmenu_handle")
    menu_additem(g_HPMenu, "100HP", "1")
    menu_additem(g_HPMenu, "200HP", "2")
    menu_setprop(g_HPMenu, MPROP_EXIT, MEXIT_ALL)
    menu_display(id, g_HPMenu, 0)
    return PLUGIN_HANDLED
}

public mainmenu_handle(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        menu_destroy(g_MainMenu)
        return PLUGIN_CONTINUE
    }
   
    new option[1], optionname[11]
    new access, callback
    menu_item_getinfo(menu, item, access, option,0, optionname, 10, callback)

    new key = str_to_num(option)

    switch(key)
    {
        case 1:
            {
                menu_destroy(g_MainMenu)
                hpmenu(id)
                return PLUGIN_HANDLED
            }
    }
    menu_destroy(g_MainMenu)
    return PLUGIN_HANDLED
}

public hpmenu_handle(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        menu_destroy(g_HPMenu)
        return PLUGIN_CONTINUE
    }
   
    new option[2], optionname[11]
    new access, callback
    menu_item_getinfo(menu, item, access, option,1, optionname, 10, callback)

    new key = str_to_num(option)

    switch(key)
    {
        case 1:
            {
                menu_destroy(g_HPMenu)
                set_user_health(id, 100)
                return PLUGIN_HANDLED
            }
        case 2:
            {
                menu_destroy(g_HPMenu)
                set_user_health(id, 200)
                return PLUGIN_HANDLED
            }
    }
    menu_destroy(g_HPMenu)
    return PLUGIN_HANDLED
}

Please could I have help? <3
Thanks.

Dores 03-28-2009 23:53

Re: Menu's
 
Just create the menu at plugin_init() or plugin_precache() and use menu_display for that menu in the wanted key(s).

By the way, the older menus are much better, IMO.

marky_uk 03-28-2009 23:57

Re: Menu's
 
So like

Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
 
new PLUGIN[]="PlayerMODMenu"
new AUTHOR[]="Marky_UK"
new VERSION[]="1.00"

new g_MainMenu
new g_HPMenu
//new g_HPValue

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_clcmd("amx_playermenu","mainmenu",ADMIN_CFG,"Opens players menu")

    g_MainMenu = menu_create("Player Menu","mainmenu_handle")
    menu_additem(g_MainMenu, "Health", "1")
    menu_setprop(g_MainMenu, MPROP_EXIT, MEXIT_ALL)


    g_HPMenu = menu_create("Health","hpmenu_handle")
    menu_additem(g_HPMenu, "100HP", "1")
    menu_additem(g_HPMenu, "200HP", "2")
    menu_setprop(g_HPMenu, MPROP_EXIT, MEXIT_ALL)
}

public mainmenu(id)
{
    menu_display(id, g_MainMenu, 0)
    return PLUGIN_HANDLED
}

public mainmenu_handle(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        menu_destroy(g_MainMenu)
        return PLUGIN_CONTINUE
    }
   
    new option[1], optionname[11]
    new access, callback
    menu_item_getinfo(menu, item, access, option,0, optionname, 10, callback)

    new key = str_to_num(option)

    switch(key)
    {
        case 1:
            {
                menu_destroy(g_MainMenu)
                menu_display(id, g_HPMenu, 0)
                return PLUGIN_HANDLED
            }
    }
    menu_destroy(g_MainMenu)
    return PLUGIN_HANDLED
}

public hpmenu_handle(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        menu_destroy(g_HPMenu)
        return PLUGIN_CONTINUE
    }
   
    new option[2], optionname[11]
    new access, callback
    menu_item_getinfo(menu, item, access, option,1, optionname, 10, callback)

    new key = str_to_num(option)

    switch(key)
    {
        case 1:
            {
                menu_destroy(g_HPMenu)
                set_user_health(id, 100)
                return PLUGIN_HANDLED
            }
        case 2:
            {
                menu_destroy(g_HPMenu)
                set_user_health(id, 200)
                return PLUGIN_HANDLED
            }
    }
    menu_destroy(g_HPMenu)
    return PLUGIN_HANDLED
}

EDIT:

Just tested the code, same problem.

First menu appears fine, press number 1. Nothing happens.
If I try to open the first menu again nothing happens

stupok 03-29-2009 02:34

Re: Menu's
 
Maybe I'm too sleepy to see the problem, but running this code should help you to find what is wrong. I added some debug messages.

Also, I changed option[1] -> option[2]

Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>

new PLUGIN[]="PlayerMODMenu"
new AUTHOR[]="Marky_UK"
new VERSION[]="1.00"

new g_MainMenu
new g_HPMenu
//new g_HPValue

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_clcmd("amx_playermenu","mainmenu",ADMIN_CFG,"Opens players menu")
       
        g_MainMenu = menu_create("Player Menu","mainmenu_handle")
        menu_additem(g_MainMenu, "Health", "1")
        menu_setprop(g_MainMenu, MPROP_EXIT, MEXIT_ALL)
       
       
        g_HPMenu = menu_create("Health","hpmenu_handle")
        menu_additem(g_HPMenu, "100HP", "1")
        menu_additem(g_HPMenu, "200HP", "2")
        menu_setprop(g_HPMenu, MPROP_EXIT, MEXIT_ALL)
}

public mainmenu(id)
{
        menu_display(id, g_MainMenu, 0)
        return PLUGIN_HANDLED
}

public mainmenu_handle(id, menu, item)
{
        if(item == MENU_EXIT)
        {
                menu_destroy(g_MainMenu)
                return PLUGIN_CONTINUE
        }
       
        new option[2], optionname[11]
        new access, callback
        menu_item_getinfo(menu, item, access, option,1, optionname, 10, callback)
       
        new key = str_to_num(option)
       
        client_print(id, print_chat, "* mainmenu_handle(%i, %i, %i) optionname=^"^%s^" key=%i", id, menu, item, option, key)
       
        switch(key)
        {
                case 1:
                {
                        client_print(id, print_chat, "* mainmenu_handle() PRESSED KEY %i", key)
                        menu_destroy(g_MainMenu)
                        menu_display(id, g_HPMenu, 0)
                        return PLUGIN_HANDLED
                }
                default:
                {
                        client_print(id, print_chat, "* mainmenu_handle() PRESSED KEY %i", key)
                        menu_destroy(g_MainMenu)
                        return PLUGIN_HANDLED
                }
        }
       
        client_print(id, print_chat, "* mainmenu_handle() NO KEY PRESSED")
       
        menu_destroy(g_MainMenu)
        return PLUGIN_HANDLED
}

public hpmenu_handle(id, menu, item)
{
        if(item == MENU_EXIT)
        {
                menu_destroy(g_HPMenu)
                return PLUGIN_CONTINUE
        }
       
        new option[2], optionname[11]
        new access, callback
        menu_item_getinfo(menu, item, access, option,1, optionname, 10, callback)
       
        new key = str_to_num(option)
       
        switch(key)
        {
                case 1:
                {
                        menu_destroy(g_HPMenu)
                        set_user_health(id, 100)
                        return PLUGIN_HANDLED
                }
                case 2:
                {
                        menu_destroy(g_HPMenu)
                        set_user_health(id, 200)
                        return PLUGIN_HANDLED
                }
                default:
                {
                        menu_destroy(g_HPMenu)
                        return PLUGIN_HANDLED
                }
        }
        menu_destroy(g_HPMenu)
        return PLUGIN_HANDLED
}


Exolent[jNr] 03-29-2009 02:46

Re: Menu's
 
Since the menus are global, you shouldn't destroy them.
Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>

new PLUGIN[]="PlayerMODMenu"
new AUTHOR[]="Marky_UK"
new VERSION[]="1.00"

new g_MainMenu
new g_HPMenu
//new g_HPValue

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_clcmd("amx_playermenu","mainmenu",ADMIN_CFG,"Opens players menu")
       
        g_MainMenu = menu_create("Player Menu","mainmenu_handle")
        menu_additem(g_MainMenu, "Health", "1")
        menu_setprop(g_MainMenu, MPROP_EXIT, MEXIT_ALL)
       
       
        g_HPMenu = menu_create("Health","hpmenu_handle")
        menu_additem(g_HPMenu, "100HP", "1")
        menu_additem(g_HPMenu, "200HP", "2")
        menu_setprop(g_HPMenu, MPROP_EXIT, MEXIT_ALL)
}

public mainmenu(id)
{
        menu_display(id, g_MainMenu, 0)
        return PLUGIN_HANDLED
}

public mainmenu_handle(id, menu, item)
{
        if(item == MENU_EXIT)
        {
                return PLUGIN_CONTINUE
        }
       
        new option[2], optionname[11]
        new access, callback
        menu_item_getinfo(menu, item, access, option,1, optionname, 10, callback)
       
        new key = str_to_num(option)
       
        switch(key)
        {
                case 1:
                {
                        menu_display(id, g_HPMenu, 0)
                }
        }
        return PLUGIN_HANDLED
}

public hpmenu_handle(id, menu, item)
{
        if(item == MENU_EXIT)
        {
                menu_display(id, g_MainMenu)
                return PLUGIN_CONTINUE
        }
       
        new option[2], optionname[11]
        new access, callback
        menu_item_getinfo(menu, item, access, option,1, optionname, 10, callback)
       
        new key = str_to_num(option)
       
        switch(key)
        {
                case 1:
                {
                        set_user_health(id, 100)
                }
                case 2:
                {
                        set_user_health(id, 200)
                }
        }
        return PLUGIN_HANDLED
}



All times are GMT -4. The time now is 09:00.

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