AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   scripting and menu (https://forums.alliedmods.net/showthread.php?t=154401)

neverminde 04-07-2011 11:41

scripting and menu
 
(I hope I have not made ​​mistakes in this pattern)

In this menu handler 1 key runs some function and opens menu again
(first page).
Last key runs another function, but it must open second page of menu.
I dont know how.


Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>

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


public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)

    register_clcmd("menu_example", "function_menu", ADMIN_ALL,"")
       
    register_clcmd("music_switch" , "my_switch")
}

public my_action(id)
{
    //something here
}

public my_switch(id)
{
    //something here
}

public function_menu(id)
{
    new menu = menu_create("My_menu", "menu_handler")
    menu_additem(menu, "first menu item","1")
    menu_additem(menu, "second menu item","2")
    menu_additem(menu, "...", "3")
    menu_additem(menu, "...", "4")
    menu_additem(menu, "...", "5")
    menu_additem(menu, "...", "6")
    menu_additem(menu, "...", "7")
    menu_additem(menu, "...", "8")
    menu_additem(menu, "...", "9")   
    menu_additem(menu, "..." "10")   
    menu_additem(menu, "last menu item" , "11")

    menu_setprop(menu, MPROP_EXIT,MEXIT_ALL)
    menu_display(id,menu,0)

    return PLUGIN_HANDLED
}

public menu_handler(id,menu,item)
{
    if(item == MENU_EXIT)
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }

    new data[6], iName[64], access, callback
    menu_item_getinfo(menu, item, access, data, 5, iName, 63, callback)

    new key = str_to_num(data)
    switch(key)
    {
case 1:
    client_cmd(id, "my_action")
    client_cmd(id, "menu_example")

case 2:
    //something
     
case 3:
    //something
     
case 4:
    //something         

case 5:
    //something

case 6:
    //something 

case 7:
    //something

case 8:
    //something
 
case 9:
    //something
case 10:
{
    //something
}
case 11:
{
    client_cmd(id, "music_switch")
    client_cmd(id, "menu_example")
   

}

    return PLUGIN_CONTINUE
}

ps how set [phpcode] ?

Nyuszy 04-07-2011 12:22

Re: scripting and menu
 
menu_display ( id, menu, page )

neverminde 04-07-2011 13:05

Re: scripting and menu
 
i have add this
Code:

menu_display( id, "function_menu", "1")
at 11 key
Code:

case 11:
{   
        client_cmd(id, "music_switch")     
        menu_display( id, "function_menu", "1")   
}

1 Error now - error 035: argument type mismatch (argument 2)

ConnorMcLeod 04-07-2011 13:11

Re: scripting and menu
 
Don't use client_cmd, call the function.

client_cmd(id, "music_switch")

->

my_switch(id)


Also :

new key = str_to_num(data)
switch(key)

Could be replaced with

switch( item )

but items start from 0 when key start from 1


For php code use [php]

fysiks 04-07-2011 19:38

Re: scripting and menu
 
Here ya go, use this as an example:

PHP Code:

#include <amxmodx>

public plugin_init()
{
    
register_clcmd("say menu""cmdMenu")
}

public 
cmdMenu(id)
{
    
open_menu(id0)
    
client_print(idprint_chat"cmdMenu")
}

open_menu(idpage 0)
{
    
// show menu here
    
client_print(idprint_chat"creating menu")
    new 
menu menu_create("My_menu""menu_handler")
    
menu_additem(menu"first menu item","1")
    
menu_additem(menu"second menu item","2")
    
menu_additem(menu"...""3")
    
menu_additem(menu"...""4")
    
menu_additem(menu"...""5")
    
menu_additem(menu"...""6")
    
menu_additem(menu"...""7")
    
menu_additem(menu"...""8")
    
menu_additem(menu"...""9")    
    
menu_additem(menu"...""10")    
    
menu_additem(menu"last menu item" "11")

    
menu_setprop(menuMPROP_EXIT,MEXIT_ALL)
    
menu_display(id,menu,page)

    return 
PLUGIN_HANDLED
}

public 
menu_handler(id,menu,item)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}

    new 
data[6], iName[64], _accesscallback
    menu_item_getinfo
(menuitem_accessdata5iName63callback)

    new 
key str_to_num(data)
    switch(
key)
    {
        case 
1:
        {
            
my_action(id)
        }
        case 
2:{}
        case 
3:{}
        case 
4:{}
        case 
5:{}
        case 
6:{}
        case 
7:{}
        case 
8:{}
        case 
9:{}
        case 
10:{}
        case 
11:
        {
            
my_switch(id)
        }
    }
    
menu_destroy(menu)
    
    new 
oldmenunewmenumenupage
    player_menu_info
(idoldmenunewmenumenupage)
    
open_menu(idmenupage)
    return 
PLUGIN_CONTINUE
}

public 
my_action(id)
{
    
//something here
    
client_print(idprint_chat"my_action")


public 
my_switch(id)
{
    
//something here
    
client_print(idprint_chat"my_switch")



neverminde 04-08-2011 18:10

Re: scripting and menu
 
very cool! that is what i need.
thanks thanks thanks ! :)


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

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