Raised This Month: $ Target: $400
 0% 

Menu's


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
marky_uk
Junior Member
Join Date: Aug 2008
Old 03-28-2009 , 23:47   Menu's
Reply With Quote #1

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.
marky_uk is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 03-28-2009 , 23:53   Re: Menu's
Reply With Quote #2

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.
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
marky_uk
Junior Member
Join Date: Aug 2008
Old 03-28-2009 , 23:57   Re: Menu's
Reply With Quote #3

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

Last edited by marky_uk; 03-29-2009 at 00:07.
marky_uk is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 03-29-2009 , 02:34   Re: Menu's
Reply With Quote #4

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
}
__________________
stupok is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-29-2009 , 02:46   Re: Menu's
Reply With Quote #5

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
}
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 09:00.


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