public void OnPluginStart()
{
//这里的autobuy就是对应的F3按键,具体的定义,可以在\steamapps\common\Counter-Strike Global Offensive\csgo\cfg\config-default.cfg文件中找到
RegConsoleCmd("autobuy", Command_Info);
}
public Action Command_Info(int client, int args)
{
ShowQuickMenu(client);
return Plugin_Handled;
}
public void ShowQuickMenu(int client)
{
Menu menu = new Menu(ShowQuickMenuHandler, MENU_ACTIONS_ALL); //创建MenuHandler
menu.SetTitle("菜单”);
menu.AddItem(“info”, "信息显示1");
menu.ExitButton = true;
menu.Display(client, 12);
}
public int ShowQuickMenuHandler(Menu menu, MenuAction action, int param1, int param2)
{
char szInfo[10];
switch(action)
{
case MenuAction_Select:
{
menu.GetItem(param2, szInfo, sizeof(szInfo));
ClientCommand(param1, "%s", szInfo);
}
case MenuAction_End:
delete menu;
}
}
关于MenuHandler的原型,参考menu.inc
/**
* Called when a menu action is completed.
*
* @param menu The menu being acted upon.
* @param action The action of the menu.
* @param param1 First action parameter (usually the client).
* @param param2 Second action parameter (usually the item).
*/
typedef MenuHandler = function int (Menu menu, MenuAction action, int param1, int param2);