AlliedModders

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

Liverwiz 05-17-2012 15:01

Menus
 
Can someone show me how to write a menu? AMX documentation looks outdated. I used AMXX-Studio's Menu Generator and that just confused me more....

so far i have....
Code:

public cmdAdminMenu(id, level, cid)
{
        if(!cmd_access(id, level, cide, 1))
                return PLUGIN_HANDLED
        /* Menu BKF Admin */
        /* Use menu_display(id, mBKFAdmin, 0) to show the menu to an user. */
        m_adminMenu = menu_create("BKF Admin", "mh_BKFAdmin")
        menu_additem(a_adminMenu, "Set Player Level", "1", ADMIN_KICK)
        menu_additem(a_adminMenu, "Set Player Frags", "ma_BKFAdmin", ADMIN_KICK, mcbBKFAdmin)
        menu_additem(a_adminMenu, "Give Player Frags", "ma_BKFAdmin", ADMIN_KICK, mcbBKFAdmin)
        menu_additem(a_adminMenu, "Prune Vault", "ma_BKFAdmin", ADMIN_BAN, mcbBKFAdmin)
        menu_additem(a_adminMenu, "Set CVARs", "ma_BKFAdmin", ADMIN_CFG, mcbBKFAdmin)
        /* Menu End */

        menu_display(id, a_adminMenu, 0)
        return PLUGIN_HANDLED
}

public mh_BKFAdmin(id, menu, item)
{
        switch(item)
        {
                case 0:
                        // is that how it works?
                default:
                        menu_destroy()
                       
        }
        return PLUGIN_HANDLED
}

public ma_BKFAdmin(id) {
        /* This event is called when an item was selected */
}
public mcb_BKFAdmin(id, menu, item) {
        /* This is the callback-event, here you can set items enabled or disabled. */
        /* If you want to enable an item, use: return ITEM_ENABLED */
        /* If you want to disable an item, use: return ITEM_DISABLED */
}

I called cmdAdminMenu from client_concmd(\\stuffs)

EpicMonkey 05-17-2012 15:07

Re: Menus
 
have you tried reading the menu tut ?
http://forums.alliedmods.net/showthread.php?t=46364

Liverwiz 05-17-2012 15:14

Re: Menus
 
Quote:

Originally Posted by EpicMonkey (Post 1710782)

I have now! :mrgreen:

Many thanks.

Bilal Pro 05-17-2012 17:41

Re: Menus
 
An empty menu if you still didnt came further.

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /test""CmdTest")
}

public 
CmdTest(id)
{
    new 
menu menu_create("Menu title""Menuhandler")
    
    
menu_additem(menu"Option 1""1")
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
menu_display(idmenu0)
}

public 
Menuhandler(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], name[64], accescallback
    menu_item_getinfo
(menuitemaccesdatacharsmax(data), namecharsmax(name), callback)
    new 
key str_to_num(data)
    
    switch (
key)
    {
        case 
1client_print(idprint_center"Awesome u pressed the first option!")
        }
    return 
PLUGIN_HANDLED



mottzi 05-17-2012 18:27

Re: Menus
 
You should destroy the menu in the handler btw.

Bilal Pro 05-17-2012 19:26

Re: Menus
 
I did?

Kreation 05-17-2012 20:02

Re: Menus
 
Quote:

Originally Posted by Bilal Pro (Post 1710948)
I did?

You did, if they press exit.

He means you should at the end of the function.

Liverwiz 05-17-2012 20:41

Re: Menus
 
I've got another question. Is there a way for a menu's handler to return a value to its calling function.
For instance.....i want the client to choose a value, then implement the chosen value in the calling function.

Liverwiz 05-17-2012 20:42

Re: Menus
 
Quote:

Originally Posted by mottzi (Post 1710921)
You should destroy the menu in the handler btw.

He had a bunch of errors in that code. But i got what he was trying to say. That tut that EpicMonkey posted was awesome.

StickP0le 05-17-2012 20:48

Re: Menus
 
Quote:

Originally Posted by mottzi (Post 1710921)
You should destroy the menu in the handler btw.

thatīs really necesary?


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

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