#define NAME_LENGTH 32 #define CMD_LENGTH 255 #define ARRAY_STRING_LENGTH 32 new Handle:g_kvMenu; enum GroupCommands { Handle:groupListName, Handle:groupListCommand }; new g_groupList[GroupCommands]; new g_groupCount; new Handle:g_configParser = INVALID_HANDLE; enum Places { Place_Category, Place_Item, Place_ReplaceNum }; new String:g_command[MAXPLAYERS+1][CMD_LENGTH]; new g_currentPlace[MAXPLAYERS+1][Places]; /** * What to put in the 'info' menu field (for PlayerList and Player_Team menus only) */ enum PlayerMethod { ClientId, /** Client id number ( 1 - Maxplayers) */ UserId, /** Client userid */ Name, /** Client Name */ SteamId, /** Client Steamid */ IpAddress, /** Client's Ip Address */ UserId2 /** Userid (not prefixed with #) */ }; BuildDynamicMenu() { if (g_kvMenu != INVALID_HANDLE) { CloseHandle(g_kvMenu); } g_kvMenu = CreateKeyValues("Commands"); new String:file[256]; BuildPath(Path_SM, file, 255, "configs/dynamicmenu/menu.ini"); FileToKeyValues(g_kvMenu, file); new String:name[NAME_LENGTH]; new String:buffer[NAME_LENGTH]; if (!KvGotoFirstSubKey(g_kvMenu)) { return; } decl String:admin[30]; new TopMenuObject:categoryId; new catId; new id; do { KvGetSectionName(g_kvMenu, buffer, sizeof(buffer)); KvGetString(g_kvMenu, "admin", admin, sizeof(admin),"sm_admin"); if ((categoryId =FindTopMenuCategory(hAdminMenu, buffer)) == INVALID_TOPMENUOBJECT) { categoryId = AddToTopMenu(hAdminMenu, buffer, TopMenuObject_Category, DynamicMenuCategoryHandler, INVALID_TOPMENUOBJECT, admin, ADMFLAG_GENERIC, name); } if (!KvGetSectionSymbol(g_kvMenu, catId)) { LogError("Key Id not found for section: %s", buffer); break; } if (!KvGotoFirstSubKey(g_kvMenu)) { return; } do { KvGetSectionName(g_kvMenu, buffer, sizeof(buffer)); KvGetString(g_kvMenu, "admin", admin, sizeof(admin),""); if (admin[0] == '\0') { //No 'admin' keyvalue was found //Use the first argument of the 'cmd' string instead decl String:temp[64]; KvGetString(g_kvMenu, "cmd", temp, sizeof(temp),""); BreakString(temp, admin, sizeof(admin)); } if (!KvGetSectionSymbol(g_kvMenu, id)) { LogError("Key Id not found for section: %s"); break; } decl String:keyId[64]; Format(keyId, sizeof(keyId), "%i %i", catId, id); AddToTopMenu(hAdminMenu, buffer, TopMenuObject_Item, DynamicMenuItemHandler, categoryId, admin, ADMFLAG_GENERIC, keyId); } while (KvGotoNextKey(g_kvMenu)); KvGoBack(g_kvMenu); } while (KvGotoNextKey(g_kvMenu)); KvRewind(g_kvMenu); } ParseConfigs() { if (g_configParser == INVALID_HANDLE) { g_configParser = SMC_CreateParser(); } SMC_SetReaders(g_configParser, NewSection, KeyValue, EndSection); if (g_groupList[groupListName] != INVALID_HANDLE) { CloseHandle(g_groupList[groupListName]); } if (g_groupList[groupListCommand] != INVALID_HANDLE) { CloseHandle(g_groupList[groupListCommand]); } g_groupList[groupListName] = CreateArray(ARRAY_STRING_LENGTH); g_groupList[groupListCommand] = CreateArray(ARRAY_STRING_LENGTH); decl String:configPath[256]; BuildPath(Path_SM, configPath, sizeof(configPath), "configs/adminmenu_grouping.txt"); if (!FileExists(configPath)) { LogError("Unable to locate admin menu groups file, no groups loaded."); return; } new line; new SMCError:err = SMC_ParseFile(g_configParser, configPath, line); if (err != SMCError_Okay) { decl String:error[256]; SMC_GetErrorString(err, error, sizeof(error)); LogError("Could not parse file (line %d, file \"%s\"):", line, configPath); LogError("Parser encountered error: %s", error); } return; } public SMCResult:NewSection(Handle:smc, const String:name[], bool:opt_quotes) { } public SMCResult:KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes) { PushArrayString(g_groupList[groupListName], key); PushArrayString(g_groupList[groupListCommand], value); } public SMCResult:EndSection(Handle:smc) { g_groupCount = GetArraySize(g_groupList[groupListName]); } public DynamicMenuCategoryHandler(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength) { if ((action == TopMenuAction_DisplayTitle) || (action == TopMenuAction_DisplayOption)) { GetTopMenuObjName(topmenu, object_id, buffer, maxlength); } } public DynamicMenuItemHandler(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength) { if (action == TopMenuAction_DisplayOption) { GetTopMenuObjName(topmenu, object_id, buffer, maxlength); } else if (action == TopMenuAction_SelectOption) { new String:keyId[64]; new String:catId[64]; GetTopMenuInfoString(topmenu, object_id, keyId, sizeof(keyId)); new start = BreakString(keyId, catId, sizeof(catId)); new id = StringToInt(keyId[start]); new category = StringToInt(catId); KvJumpToKeySymbol(g_kvMenu, category); KvJumpToKeySymbol(g_kvMenu, id); KvGetString(g_kvMenu, "cmd", g_command[param], sizeof(g_command[]),""); KvRewind(g_kvMenu); g_currentPlace[param][Place_Category] = category; g_currentPlace[param][Place_Item] = id; ParamCheck(param); } } public ParamCheck(client) { new String:buffer[6]; new String:buffer2[6]; KvJumpToKeySymbol(g_kvMenu, g_currentPlace[client][Place_Category]); KvJumpToKeySymbol(g_kvMenu, g_currentPlace[client][Place_Item]); new String:type[NAME_LENGTH]; if (g_currentPlace[client][Place_ReplaceNum] < 1) { g_currentPlace[client][Place_ReplaceNum] = 1; } Format(buffer, 5, "#%i", g_currentPlace[client][Place_ReplaceNum]); Format(buffer2, 5, "@%i", g_currentPlace[client][Place_ReplaceNum]); if (StrContains(g_command[client], buffer) != -1 || StrContains(g_command[client], buffer2) != -1) { //user has a parameter to fill. lets do it. Format(buffer, 5, "%i", g_currentPlace[client][Place_ReplaceNum]); KvJumpToKey(g_kvMenu, buffer); // Jump to current param KvGetString(g_kvMenu, "type", type, sizeof(type),"list"); new Handle:itemMenu = CreateMenu(Menu_Selection); new String:title[NAME_LENGTH]; if (strncmp(type,"group",5)==0 && g_groupCount) { decl String:nameBuffer[ARRAY_STRING_LENGTH]; decl String:commandBuffer[ARRAY_STRING_LENGTH]; for (new i = 0; i