- Регистрация
- 20 Фев 2018
- Сообщения
- 263
- Симпатии
- 65
- Пол
- Мужской
Имеется плагин
Скипаю пункт меню при условии что у игрока нет определенных флагов, не могу допереть как скипнуть его же в обработчике? Т.е. если есть скрытый пункт, он в обработчик не входит
Код:
#include <amxmodx>
#include <menu_modular>
const MENU_MAX_ITEMS = 8;
enum fwdStruct {
FWD_SELECTED
};
enum playerStruct {
PLAYER_POS,
PLAYER_MENU
};
enum menuStruct {
MENU_NAME[MENU_MAX_NAME],
MENU_ACCESS
};
enum itemStruct {
ITEM_NAME[ITEM_MAX_NAME],
ITEM_INFO[ITEM_INFO_MAX_NAME],
ITEM_MENU,
ITEM_ACCESS
};
new g_fwdHandle[fwdStruct];
new g_menuData[menuStruct];
new g_itemData[itemStruct];
new Array: g_aMenus;
new Array: g_aItems;
new bool: g_bConnected[MAX_PLAYERS + 1];
new g_iPlayerData[MAX_PLAYERS + 1][playerStruct];
public plugin_init() {
register_plugin("Menu modular: Core", "1.0.0", "cpctrl");
register_menucmd(register_menuid("MENU_MODULAR_MAIN"), 1023, "HandlerMenuModular");
g_fwdHandle[FWD_SELECTED] = CreateMultiForward("mm_item_selected", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL);
}
public plugin_cfg() {
register_dictionary("menu_modular.txt");
}
public client_putinserver(id) {
if (is_user_hltv(id) && is_user_bot(id)) {
return;
}
g_bConnected[id] = true;
}
public client_disconnected(id) {
if (g_bConnected[id]) {
g_bConnected[id] = false;
}
}
Show_MenuModular(id, menu, pos) {
if (pos < 0) {
return -1;
}
new items = get_menu_items(menu);
new start = pos * MENU_MAX_ITEMS;
if (start > items) {
start = items;
}
start = start - (start % MENU_MAX_ITEMS);
g_iPlayerData[id][PLAYER_POS] = (start / MENU_MAX_ITEMS);
new end = start + MENU_MAX_ITEMS;
if (end > items) {
end = items;
}
new menuStr[512], len, keys = (1 << 9);
ArrayGetArray(g_aMenus, menu, g_menuData, sizeof g_menuData);
len = formatex(menuStr, charsmax(menuStr), "%L \d[%d|%d]^n^n", id, g_menuData[MENU_NAME], pos + 1, items / MENU_MAX_ITEMS + ((items % MENU_MAX_ITEMS) ? 1 : 0));
new info[ITEM_INFO_MAX_NAME];
for (new b, a = start; a < end; a++) {
ArrayGetArray(g_aItems, a, g_itemData, sizeof g_itemData);
if (g_itemData[ITEM_MENU] != menu) {
continue;
}
if (g_itemData[ITEM_INFO]) {
formatex(info, ITEM_INFO_MAX_NAME - 1, " \d[\w%s\d]", g_itemData[ITEM_INFO]);
}
if (g_itemData[ITEM_ACCESS] == ADMIN_ALL || g_itemData[ITEM_ACCESS] != ADMIN_ALL && (get_user_flags(id) & g_itemData[ITEM_ACCESS])) {
keys |= (1 << b);
len += formatex(menuStr[len], charsmax(menuStr) - len, "\d[%d] \y%L%s^n", ++b, id, g_itemData[ITEM_NAME], info[0] != EOS ? info : "");
continue;
}
//len += formatex(menuStr[len], charsmax(menuStr) - len, "\d[%d] \r%L%s^n", ++b, id, g_itemData[ITEM_NAME], info[0] != EOS ? info : "");
}
new tmp[15];
setc(tmp, MENU_MAX_ITEMS - (end - start) + 1, '^n');
len += copy(menuStr[len], charsmax(menuStr) - len, tmp);
if (end < items) {
keys |= (1 << 8);
formatex(menuStr[len], charsmax(menuStr) - len, "\d[9] \y%L^n\d[0] \y%L", id, "MENU_NEXT", id, pos ? "MENU_BACK" : "MENU_EXIT");
}
else {
formatex(menuStr[len], charsmax(menuStr) - len, "\d[0] \y%L", id, pos ? "MENU_BACK" : "MENU_EXIT");
}
return show_menu(id, keys, menuStr, -1, "MENU_MODULAR_MAIN");
}
public HandlerMenuModular(id, key) {
if (!g_bConnected[id]) {
return PLUGIN_HANDLED;
}
switch (key) {
case 8: return Show_MenuModular(id, g_iPlayerData[id][PLAYER_MENU], ++g_iPlayerData[id][PLAYER_POS]);
case 9: return Show_MenuModular(id, g_iPlayerData[id][PLAYER_MENU], --g_iPlayerData[id][PLAYER_POS]);
default: {
new item = (g_iPlayerData[id][PLAYER_POS] * MENU_MAX_ITEMS + key);
ExecuteForward(g_fwdHandle[FWD_SELECTED], _, id, g_iPlayerData[id][PLAYER_MENU], item);
}
}
return PLUGIN_HANDLED;
}
get_menu_items(menu) {
new items;
for (new i; i < ArraySize(g_aItems); i++) {
ArrayGetArray(g_aItems, i, g_itemData);
if (g_itemData[ITEM_MENU] == menu) {
items++;
}
}
return items;
}
public plugin_natives() {
register_library("menu_modular");
register_native("mm_add_menu", "add_menu");
register_native("mm_add_item", "add_item");
register_native("mm_item_setinfo", "item_setinfo");
register_native("mm_show_menu", "_show_menu");
}
public add_menu(plugin, argc) {
enum {
arg_name = 1,
arg_access
};
if (!g_aMenus) {
g_aMenus = ArrayCreate(menuStruct);
}
get_string(arg_name, g_menuData[MENU_NAME], MENU_MAX_NAME - 1);
g_menuData[MENU_ACCESS] = get_param(arg_access);
return ArrayPushArray(g_aMenus, g_menuData);
}
public add_item(plugin, argc) {
enum {
arg_menu = 1,
arg_name,
arg_info,
arg_access
};
if (!g_aItems) {
g_aItems = ArrayCreate(itemStruct);
}
get_string(arg_name, g_itemData[ITEM_NAME], ITEM_MAX_NAME - 1);
new info[ITEM_INFO_MAX_NAME];
get_string(arg_info, info, ITEM_INFO_MAX_NAME - 1);
if (info[0] != EOS) {
copy(g_itemData[ITEM_INFO], ITEM_INFO_MAX_NAME - 1, info);
}
else {
g_itemData[ITEM_INFO][0] = EOS;
}
g_itemData[ITEM_MENU] = get_param(arg_menu);
g_itemData[ITEM_ACCESS] = get_param(arg_access);
return ArrayPushArray(g_aItems, g_itemData);
}
public bool: item_setinfo(plugin, argc) {
enum {
arg_item = 1,
arg_name,
arg_info,
arg_access
};
new item = get_param(arg_item);
if (item < 0 || item > ArraySize(g_aItems)) {
return false;
}
ArrayGetArray(g_aItems, item, g_itemData);
get_string(arg_name, g_itemData[ITEM_NAME], ITEM_MAX_NAME - 1);
new info[ITEM_INFO_MAX_NAME];
get_string(arg_info, info, ITEM_INFO_MAX_NAME - 1);
if (info[0] != EOS) {
copy(g_itemData[ITEM_INFO], ITEM_INFO_MAX_NAME - 1, info);
}
g_itemData[ITEM_ACCESS] = get_param(arg_access);
ArraySetArray(g_aItems, item, g_itemData);
return true;
}
public _show_menu(plugin, argc) {
enum {
arg_player = 1,
arg_menu
};
new id = get_param(arg_player);
if (!g_bConnected[id]) {
return -1;
}
new menu = get_param(arg_menu);
if (0 > menu && menu > ArraySize(g_aMenus)) {
return -1;
}
return Show_MenuModular(id, g_iPlayerData[id][PLAYER_MENU] = menu, g_iPlayerData[id][PLAYER_POS] = 0);
}
Последнее редактирование: