From 522511d059d667bc83820f344d9fcaa846cad029 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 14 Mar 2006 17:49:29 +0000 Subject: [PATCH] implemented menu_cancel --- amxmodx/newmenus.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index 45731693..4aa8e4e3 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -751,6 +751,39 @@ static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params) return 0; } \ Menu *pMenu = g_NewMenus[p]; +static cell AMX_NATIVE_CALL menu_cancel(AMX *amx, cell *params) +{ + int index = params[1]; + + if (index < 1 || index > gpGlobals->maxClients) + { + LogError(amx, AMX_ERR_NATIVE, "Player %d is not valid", index); + return 0; + } + + CPlayer *player = GET_PLAYER_POINTER_I(index); + if (!player->ingame) + { + LogError(amx, AMX_ERR_NATIVE, "Played %d is not in game", index); + return 0; + } + + int menu = player->newmenu; + if (menu < 0 || menu >= (int)g_NewMenus.size() || !g_NewMenus[menu]) + return 0; + + Menu *pMenu = g_NewMenus[menu]; + + player->newmenu = -1; + player->menu = 0; + executeForwards(pMenu->func, + static_cast(index), + static_cast(pMenu->thisId), + static_cast(MENU_EXIT)); + + return 1; +} + static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params) { GETMENU_R(params[1]); @@ -766,12 +799,12 @@ static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params) player = GET_PLAYER_POINTER_I(i); if (player->newmenu == pMenu->thisId) { + player->newmenu = -1; + player->menu = 0; executeForwards(pMenu->func, static_cast(i), static_cast(pMenu->thisId), static_cast(MENU_EXIT)); - player->newmenu = -1; - player->menu = 0; } } g_NewMenus[params[1]] = NULL; @@ -824,6 +857,7 @@ AMX_NATIVE_INFO g_NewMenuNatives[] = {"menu_item_setname", menu_item_setname}, {"menu_destroy", menu_destroy}, {"menu_setprop", menu_setprop}, + {"menu_cancel", menu_cancel}, {"player_menu_info", player_menu_info}, {NULL, NULL}, };