设为首页收藏本站新闻投稿

MOD中国同盟社

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 516|回复: 2

[求助] amxx:这段代码中使用menu_item_getinfo有什么用 小白求助 [复制链接]

Rank: 7Rank: 7Rank: 7

帖子
878
精华
1
声望
2479 点
金币
546 Mold
被赞许
1 次
注册时间
2009-12-6
发表于 2011-1-15 16:57:52 |显示全部楼层
来自forums.alliedmods的amxx菜单系统教学贴

以下是基础菜单的代码
  1. #include <amxmodx>

  2. public plugin_init()
  3. {
  4.     //..stuff for your plugin

  5.     register_clcmd( "my_awesome_menu","AwesomeMenu");
  6.     //note that we do not need to register the menu anymore, but just a way to get to it
  7. }
  8. //lets make the function that will make the menu
  9. public AwesomeMenu(id)
  10. {
  11.     //first we need to make a variable that will hold the menu
  12.     new menu = menu_create("\rLook at this awesome Menu!:", "menu_handler");
  13.     //Note - menu_create
  14.     //The first parameter  is what the menu will be titled (what is at the very top)
  15.     //The second parameter is the function that will deal/handle with the menu (which key was pressed, and what to do)

  16.     //Now lets add some things to select from the menu
  17.     menu_additem(menu, "\wI'm Selection #1", "1", 0);
  18.     menu_additem(menu, "\wI'm Selection #2", "2", 0);
  19.     menu_additem(menu, "\wI'm Secret Selection #3", "3", ADMIN_ADMIN);
  20.     //Note - menu_additem
  21.     //The first parameter is which menu we will be adding this item/selection to
  22.     //The second parameter is what text will appear on the menu (Note that it is preceeded with a number of which item it is)
  23.     //The third parameter is data that we want to send with this item
  24.     //The fourth parameter is which admin flag we want to be able to access this item (I have had no experience with this, so I am just assuming this is how it works. It uses the admin flags from the amxconst.inc)

  25.     //Set a property on the menu
  26.     menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
  27.     //Note - menu_setprop
  28.     //The first parameter is the menu to modify
  29.     //The second parameter is what to modify (found in amxconst.inc)
  30.     //The third parameter is what to modify it to (in this case, we are adding a option to the menu that will exit the menu. setting it to MEXIT_NEVER will disable this option)

  31.     //Lets display the menu
  32.     menu_display(id, menu, 0);
  33.     //Note - menu_display
  34.     //The first parameter is which index to show it to (you cannot show this to everyone at once)
  35.     //The second parameter is which menu to show them (in this case, the one we just made)
  36.     //The third parameter is which page to start them on
  37. }
  38. //okay, we showed them the menu, now lets handle it (looking back at menu_create, we are going to use that function)
  39. public menu_handler(id, menu, item)
  40. {
  41.     //we don't want to deal with them if they exited a menu
  42.     if( item == MENU_EXIT )
  43.     {
  44.         menu_destroy(menu);
  45.         //Note that you will want to destroy the menu after they do something
  46.         return PLUGIN_HANDLED;
  47.     }

  48.     //now lets create some variables that will give us information about the menu and the item that was pressed/chosen
  49.     new data[6], iName[64];
  50.     new access, callback;
  51.     //heres the function that will give us that information (since it doesnt magicaly appear)
  52.     menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);

  53.     //Note - that you can do this next step how you want, this is just the way I prefer

  54.     //looking back to menu_additem, we sent data with every item we added, this is where it gets a little fishy for us (where you can do your own method)
  55.     new key = str_to_num(data);
  56.     //note that all my datas were numbers (you can do it with whatever type of string you want)

  57.     //now lets find which item was pressed
  58.     switch(key)
  59.     {
  60.         case 1:
  61.         {
  62.             client_print(id, print_chat, "Hooray! You selected the Awesome 1st Selection");
  63.             //note that if we dont want to continue through the function, we can't just end with a return. We want to kill the menu first
  64.             menu_destroy(menu);
  65.             return PLUGIN_HANDLED;
  66.         }
  67.         case 2:
  68.         {
  69.             client_print(id, print_chat, "OH NO! You selected the Awesome 2nd Selection! BEWARE!");
  70.         }
  71.         case 3: //again i don't have experience with the admin limitations, so i don't know if you need to have a check before this (im assuming you don't though ^_^)
  72.         {
  73.             client_print(id, print_chat, "You have selected the Awesome Admin Selection! Hail Teh Bail!");
  74.         }
  75.     }

  76.     //lets finish up this function with a menu_destroy, and a return
  77.     menu_destroy(menu);
  78.     return PLUGIN_HANDLED;
  79. }
复制代码
我想知道这段有什么用
  1.    
  2. //now lets create some variables that will give us information about the menu and the item that was pressed/chosen
  3.     new data[6], iName[64];
  4.     new access, callback;
  5.     //heres the function that will give us that information (since it doesnt magicaly appear)
  6.     menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
复制代码
老外的注释还是能看懂的

哪位能说下menu_item_getinfo的作用  谢谢了

使用道具 举报

Rank: 5Rank: 5

帖子
500
精华
0
声望
1471 点
金币
499 Mold
被赞许
3 次
注册时间
2010-10-12

可爱小猫

发表于 2011-1-15 17:40:48 |显示全部楼层
扔进谷歌里 慢慢理解

使用道具 举报

Rank: 7Rank: 7Rank: 7

帖子
863
精华
0
声望
2462 点
金币
584 Mold
被赞许
7 次
注册时间
2010-5-7
发表于 2011-1-15 18:38:28 |显示全部楼层
自己体悟。这个native是菜单的重点内容

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

回顶部