Big changes to dynamic menu. Removed constant kv tracking. Tested everything.
Big changes to dynamic menu. Removed constant kv tracking. Tested everything.
Import of config files.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/configs/dynamicmenu/adminmenu_grouping.txt Mon Mar 31 22:44:18 2008 +0000
1.3 @@ -0,0 +1,18 @@
1.4 +/* Add group options to be added to 'group' or 'groupplayer' type submenus
1.5 + * The left side is the name that will show in the menu, right is the command that will be fired
1.6 + */
1.7 +
1.8 +Groups
1.9 +{
1.10 + "All" "@all"
1.11 + "Bots" "@bots"
1.12 + "Alive" "@alive"
1.13 + "Dead" "@dead"
1.14 + "Humans" "@humans"
1.15 + "Current aim" "@aim"
1.16 +
1.17 + /* You can enable these if you are using Counter-Strike Source and running the cstrike extension */
1.18 +// "Terrorists" "@t"
1.19 +// "Counter-Terrorists" "@ct"
1.20 +
1.21 +}
1.22 \ No newline at end of file
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/configs/dynamicmenu/menu.ini Mon Mar 31 22:44:18 2008 +0000
2.3 @@ -0,0 +1,4 @@
2.4 +"Commands"
2.5 +{
2.6 +
2.7 +}
2.8 \ No newline at end of file
3.1 --- a/plugins/adminmenu/dynamicmenu.sp Sun Mar 30 07:00:22 2008 +0000
3.2 +++ b/plugins/adminmenu/dynamicmenu.sp Mon Mar 31 22:44:18 2008 +0000
3.3 @@ -4,8 +4,6 @@
3.4
3.5 #define ARRAY_STRING_LENGTH 32
3.6
3.7 -new Handle:g_kvMenu;
3.8 -
3.9 enum GroupCommands
3.10 {
3.11 Handle:groupListName,
3.12 @@ -40,23 +38,59 @@
3.13 UserId2 /** Userid (not prefixed with #) */
3.14 };
3.15
3.16 +enum ExecuteType
3.17 +{
3.18 + Execute_Player,
3.19 + Execute_Server
3.20 +}
3.21 +
3.22 +enum SubMenu_Type
3.23 +{
3.24 + SubMenu_Group,
3.25 + SubMenu_GroupPlayer,
3.26 + SubMenu_Player,
3.27 + SubMenu_MapCycle,
3.28 + SubMenu_List,
3.29 + SubMenu_OnOff
3.30 +}
3.31 +
3.32 +enum Item
3.33 +{
3.34 + String:Item_cmd[256],
3.35 + ExecuteType:Item_execute,
3.36 + Handle:Item_submenus
3.37 +}
3.38 +
3.39 +enum Submenu
3.40 +{
3.41 + SubMenu_Type:Submenu_type,
3.42 + String:Submenu_title[32],
3.43 + PlayerMethod:Submenu_method,
3.44 + Submenu_listcount,
3.45 + Handle:Submenu_listdata
3.46 +}
3.47 +
3.48 +new Handle:g_DataArray;
3.49 +
3.50 BuildDynamicMenu()
3.51 {
3.52 - if (g_kvMenu != INVALID_HANDLE)
3.53 - {
3.54 - CloseHandle(g_kvMenu);
3.55 - }
3.56 + new itemInput[Item];
3.57 + g_DataArray = CreateArray(sizeof(itemInput));
3.58
3.59 - g_kvMenu = CreateKeyValues("Commands");
3.60 + new String:executeBuffer[32];
3.61 +
3.62 + new Handle:kvMenu;
3.63 + kvMenu = CreateKeyValues("Commands");
3.64 new String:file[256];
3.65 BuildPath(Path_SM, file, 255, "configs/dynamicmenu/menu.ini");
3.66 - FileToKeyValues(g_kvMenu, file);
3.67 + FileToKeyValues(kvMenu, file);
3.68
3.69 new String:name[NAME_LENGTH];
3.70 new String:buffer[NAME_LENGTH];
3.71
3.72 -
3.73 - if (!KvGotoFirstSubKey(g_kvMenu))
3.74 + KvSetEscapeSequences(kvMenu, true);
3.75 +
3.76 + if (!KvGotoFirstSubKey(kvMenu))
3.77 {
3.78 return;
3.79 }
3.80 @@ -65,14 +99,11 @@
3.81
3.82 new TopMenuObject:categoryId;
3.83
3.84 - new catId;
3.85 - new id;
3.86 -
3.87 do
3.88 {
3.89 - KvGetSectionName(g_kvMenu, buffer, sizeof(buffer));
3.90 + KvGetSectionName(kvMenu, buffer, sizeof(buffer));
3.91
3.92 - KvGetString(g_kvMenu, "admin", admin, sizeof(admin),"sm_admin");
3.93 + KvGetString(kvMenu, "admin", admin, sizeof(admin),"sm_admin");
3.94
3.95 if ((categoryId =FindTopMenuCategory(hAdminMenu, buffer)) == INVALID_TOPMENUOBJECT)
3.96 {
3.97 @@ -87,22 +118,16 @@
3.98
3.99 }
3.100
3.101 - if (!KvGetSectionSymbol(g_kvMenu, catId))
3.102 - {
3.103 - LogError("Key Id not found for section: %s", buffer);
3.104 - break;
3.105 - }
3.106 -
3.107 - if (!KvGotoFirstSubKey(g_kvMenu))
3.108 + if (!KvGotoFirstSubKey(kvMenu))
3.109 {
3.110 return;
3.111 }
3.112
3.113 do
3.114 {
3.115 - KvGetSectionName(g_kvMenu, buffer, sizeof(buffer));
3.116 -
3.117 - KvGetString(g_kvMenu, "admin", admin, sizeof(admin),"");
3.118 + KvGetSectionName(kvMenu, buffer, sizeof(buffer));
3.119 +
3.120 + KvGetString(kvMenu, "admin", admin, sizeof(admin),"");
3.121
3.122 if (admin[0] == '\0')
3.123 {
3.124 @@ -110,21 +135,165 @@
3.125 //Use the first argument of the 'cmd' string instead
3.126
3.127 decl String:temp[64];
3.128 - KvGetString(g_kvMenu, "cmd", temp, sizeof(temp),"");
3.129 + KvGetString(kvMenu, "cmd", temp, sizeof(temp),"");
3.130
3.131 BreakString(temp, admin, sizeof(admin));
3.132 }
3.133 -
3.134 - if (!KvGetSectionSymbol(g_kvMenu, id))
3.135 +
3.136 +
3.137 + KvGetString(kvMenu, "cmd", itemInput[Item_cmd], sizeof(itemInput[Item_cmd]));
3.138 + KvGetString(kvMenu, "execute", executeBuffer, sizeof(executeBuffer));
3.139 +
3.140 + if (StrEqual(executeBuffer, "server"))
3.141 {
3.142 - LogError("Key Id not found for section: %s");
3.143 - break;
3.144 + itemInput[Item_execute] = Execute_Server;
3.145 + }
3.146 + else //assume player type execute
3.147 + {
3.148 + itemInput[Item_execute] = Execute_Player;
3.149 }
3.150 -
3.151 - decl String:keyId[64];
3.152 +
3.153 + /* iterate all submenus and load data into itemInput[Item_submenus] (adt array handle) */
3.154 +
3.155 + new count = 1;
3.156 + decl String:countBuffer[10] = "1";
3.157 +
3.158 + decl String:inputBuffer[32];
3.159 +
3.160 + while (KvJumpToKey(kvMenu, countBuffer))
3.161 + {
3.162 + new submenuInput[Submenu];
3.163 +
3.164 + if (count == 1)
3.165 + {
3.166 + itemInput[Item_submenus] = CreateArray(sizeof(submenuInput));
3.167 + }
3.168 +
3.169 + KvGetString(kvMenu, "type", inputBuffer, sizeof(inputBuffer));
3.170 +
3.171 + if (strncmp(inputBuffer,"group",5)==0)
3.172 + {
3.173 + if (StrContains(inputBuffer, "player") != -1)
3.174 + {
3.175 + submenuInput[Submenu_type] = SubMenu_GroupPlayer;
3.176 + }
3.177 + else
3.178 + {
3.179 + submenuInput[Submenu_type] = SubMenu_Group;
3.180 + }
3.181 + }
3.182 + else if (StrEqual(inputBuffer,"mapcycle"))
3.183 + {
3.184 + submenuInput[Submenu_type] = SubMenu_MapCycle;
3.185 +
3.186 + KvGetString(kvMenu, "path", inputBuffer, sizeof(inputBuffer),"mapcycle.txt");
3.187 +
3.188 + submenuInput[Submenu_listdata] = CreateDataPack();
3.189 + WritePackString(submenuInput[Submenu_listdata], inputBuffer);
3.190 + ResetPack(submenuInput[Submenu_listdata]);
3.191 + }
3.192 + else if (StrContains(inputBuffer, "player") != -1)
3.193 + {
3.194 + submenuInput[Submenu_type] = SubMenu_Player;
3.195 + }
3.196 + else if (StrEqual(inputBuffer,"onoff"))
3.197 + {
3.198 + submenuInput[Submenu_type] = SubMenu_OnOff;
3.199 + }
3.200 + else //assume 'list' type
3.201 + {
3.202 + submenuInput[Submenu_type] = SubMenu_List;
3.203 +
3.204 + submenuInput[Submenu_listdata] = CreateDataPack();
3.205 +
3.206 + new String:temp[6];
3.207 + new String:value[64];
3.208 + new String:text[64];
3.209 + new i=1;
3.210 + new bool:more = true;
3.211 +
3.212 + new listcount = 0;
3.213 +
3.214 + do
3.215 + {
3.216 + Format(temp,3,"%i",i);
3.217 + KvGetString(kvMenu, temp, value, sizeof(value), "");
3.218 +
3.219 + Format(temp,5,"%i.",i);
3.220 + KvGetString(kvMenu, temp, text, sizeof(text), value);
3.221 +
3.222 + Format(temp,5,"%i*",i);
3.223 + KvGetString(kvMenu, temp, admin, sizeof(admin),"");
3.224 +
3.225 + if (value[0]=='\0')
3.226 + {
3.227 + more = false;
3.228 + }
3.229 + else
3.230 + {
3.231 + listcount++;
3.232 + WritePackString(submenuInput[Submenu_listdata], value);
3.233 + WritePackString(submenuInput[Submenu_listdata], text);
3.234 + WritePackString(submenuInput[Submenu_listdata], admin);
3.235 + }
3.236 +
3.237 + i++;
3.238 +
3.239 + } while (more);
3.240 +
3.241 + ResetPack(submenuInput[Submenu_listdata]);
3.242 + submenuInput[Submenu_listcount] = listcount;
3.243 + }
3.244 +
3.245 + if ((submenuInput[Submenu_type] == SubMenu_Player) || (submenuInput[Submenu_type] == SubMenu_GroupPlayer))
3.246 + {
3.247 + KvGetString(kvMenu, "method", inputBuffer, sizeof(inputBuffer));
3.248 +
3.249 + if (StrEqual(inputBuffer, "clientid"))
3.250 + {
3.251 + submenuInput[Submenu_method] = ClientId;
3.252 + }
3.253 + else if (StrEqual(inputBuffer, "steamid"))
3.254 + {
3.255 + submenuInput[Submenu_method] = SteamId;
3.256 + }
3.257 + else if (StrEqual(inputBuffer, "userid2"))
3.258 + {
3.259 + submenuInput[Submenu_method] = UserId2;
3.260 + }
3.261 + else if (StrEqual(inputBuffer, "userid"))
3.262 + {
3.263 + submenuInput[Submenu_method] = UserId;
3.264 + }
3.265 + else if (StrEqual(inputBuffer, "ip"))
3.266 + {
3.267 + submenuInput[Submenu_method] = IpAddress;
3.268 + }
3.269 + else
3.270 + {
3.271 + submenuInput[Submenu_method] = Name;
3.272 + }
3.273 +
3.274 + }
3.275 +
3.276 + KvGetString(kvMenu, "title", inputBuffer, sizeof(inputBuffer));
3.277 + strcopy(submenuInput[Submenu_title], sizeof(submenuInput[Submenu_title]), inputBuffer);
3.278 +
3.279 + count++;
3.280 + Format(countBuffer, sizeof(countBuffer), "%i", count);
3.281 +
3.282 + PushArrayArray(itemInput[Item_submenus], submenuInput[0]);
3.283 +
3.284 + KvGoBack(kvMenu);
3.285 + }
3.286 +
3.287 + /* Save this entire item into the global items array and add it to the menu */
3.288 +
3.289 + new location = PushArrayArray(g_DataArray, itemInput[0]);
3.290
3.291 - Format(keyId, sizeof(keyId), "%i %i", catId, id);
3.292 -
3.293 + decl String:locString[10];
3.294 + IntToString(location, locString, sizeof(locString));
3.295 +
3.296 AddToTopMenu(hAdminMenu,
3.297 buffer,
3.298 TopMenuObject_Item,
3.299 @@ -132,15 +301,15 @@
3.300 categoryId,
3.301 admin,
3.302 ADMFLAG_GENERIC,
3.303 - keyId);
3.304 + locString);
3.305
3.306 - } while (KvGotoNextKey(g_kvMenu));
3.307 + } while (KvGotoNextKey(kvMenu));
3.308
3.309 - KvGoBack(g_kvMenu);
3.310 + KvGoBack(kvMenu);
3.311
3.312 - } while (KvGotoNextKey(g_kvMenu));
3.313 + } while (KvGotoNextKey(kvMenu));
3.314
3.315 - KvRewind(g_kvMenu);
3.316 + CloseHandle(kvMenu);
3.317 }
3.318
3.319 ParseConfigs()
3.320 @@ -230,23 +399,17 @@
3.321 }
3.322 else if (action == TopMenuAction_SelectOption)
3.323 {
3.324 - new String:keyId[64];
3.325 - new String:catId[64];
3.326 - GetTopMenuInfoString(topmenu, object_id, keyId, sizeof(keyId));
3.327 + new String:locString[10];
3.328 + GetTopMenuInfoString(topmenu, object_id, locString, sizeof(locString));
3.329
3.330 - new start = BreakString(keyId, catId, sizeof(catId));
3.331 -
3.332 - new id = StringToInt(keyId[start]);
3.333 - new category = StringToInt(catId);
3.334 + new location = StringToInt(locString);
3.335
3.336 - KvJumpToKeySymbol(g_kvMenu, category);
3.337 - KvJumpToKeySymbol(g_kvMenu, id);
3.338 + new output[Item];
3.339 + GetArrayArray(g_DataArray, location, output[0]);
3.340
3.341 - KvGetString(g_kvMenu, "cmd", g_command[param], sizeof(g_command[]),"");
3.342 - KvRewind(g_kvMenu);
3.343 + strcopy(g_command[param], sizeof(g_command[]), output[Item_cmd]);
3.344
3.345 - g_currentPlace[param][Place_Category] = category;
3.346 - g_currentPlace[param][Place_Item] = id;
3.347 + g_currentPlace[param][Place_Item] = location;
3.348
3.349 ParamCheck(param);
3.350 }
3.351 @@ -256,11 +419,11 @@
3.352 {
3.353 new String:buffer[6];
3.354 new String:buffer2[6];
3.355 -
3.356 - KvJumpToKeySymbol(g_kvMenu, g_currentPlace[client][Place_Category]);
3.357 - KvJumpToKeySymbol(g_kvMenu, g_currentPlace[client][Place_Item]);
3.358
3.359 - new String:type[NAME_LENGTH];
3.360 + new outputItem[Item];
3.361 + new outputSubmenu[Submenu];
3.362 +
3.363 + GetArrayArray(g_DataArray, g_currentPlace[client][Place_Item], outputItem[0]);
3.364
3.365 if (g_currentPlace[client][Place_ReplaceNum] < 1)
3.366 {
3.367 @@ -272,17 +435,11 @@
3.368
3.369 if (StrContains(g_command[client], buffer) != -1 || StrContains(g_command[client], buffer2) != -1)
3.370 {
3.371 - //user has a parameter to fill. lets do it.
3.372 - KvJumpToKey(g_kvMenu, buffer[1]); // Jump to current param
3.373 - KvGetString(g_kvMenu, "type", type, sizeof(type),"list");
3.374 -
3.375 - PrintToChatAll("Checking param %s - type %s", buffer[1], type);
3.376 + GetArrayArray(outputItem[Item_submenus], g_currentPlace[client][Place_ReplaceNum] - 1, outputSubmenu[0]);
3.377
3.378 new Handle:itemMenu = CreateMenu(Menu_Selection);
3.379 -
3.380 - new String:title[NAME_LENGTH];
3.381
3.382 - if (strncmp(type,"group",5)==0 && g_groupCount)
3.383 + if ((outputSubmenu[Submenu_type] == SubMenu_Group) || (outputSubmenu[Submenu_type] == SubMenu_GroupPlayer))
3.384 {
3.385 decl String:nameBuffer[ARRAY_STRING_LENGTH];
3.386 decl String:commandBuffer[ARRAY_STRING_LENGTH];
3.387 @@ -295,10 +452,11 @@
3.388 }
3.389 }
3.390
3.391 - if (strncmp(type,"mapcycle",8) == 0)
3.392 - {
3.393 + if (outputSubmenu[Submenu_type] == SubMenu_MapCycle)
3.394 + {
3.395 decl String:path[200];
3.396 - KvGetString(g_kvMenu, "path", path, sizeof(path),"mapcycle.txt");
3.397 + ReadPackString(outputSubmenu[Submenu_listdata], path, sizeof(path));
3.398 + ResetPack(outputSubmenu[Submenu_listdata]);
3.399
3.400 new Handle:file = OpenFile(path, "rt");
3.401 new String:readData[128];
3.402 @@ -316,41 +474,10 @@
3.403 }
3.404 }
3.405 }
3.406 - else if (StrContains(type, "player") != -1)
3.407 + else if ((outputSubmenu[Submenu_type] == SubMenu_Player) || (outputSubmenu[Submenu_type] == SubMenu_GroupPlayer))
3.408 {
3.409 - PrintToChatAll("Building Player List");
3.410 -
3.411 - new PlayerMethod:playermethod;
3.412 - new String:method[NAME_LENGTH];
3.413 -
3.414 - KvGetString(g_kvMenu, "method", method, sizeof(method),"name");
3.415 -
3.416 - if (strncmp(method,"clientid",8)==0)
3.417 - {
3.418 - playermethod = ClientId;
3.419 - }
3.420 - else if (strncmp(method,"steamid",7)==0)
3.421 - {
3.422 - playermethod = SteamId;
3.423 - }
3.424 - else if (strncmp(method,"userid2",7)==0)
3.425 - {
3.426 - playermethod = UserId2;
3.427 - }
3.428 - else if (strncmp(method,"userid",6)==0)
3.429 - {
3.430 - playermethod = UserId;
3.431 - }
3.432 - else if (strncmp(method,"ip",2)==0)
3.433 - {
3.434 - playermethod = IpAddress;
3.435 - }
3.436 - else
3.437 - {
3.438 - playermethod = Name;
3.439 - }
3.440 -
3.441 -
3.442 + new PlayerMethod:playermethod = outputSubmenu[Submenu_method];
3.443 +
3.444 new String:nameBuffer[32];
3.445 new String:infoBuffer[32];
3.446 new String:temp[4];
3.447 @@ -399,66 +526,44 @@
3.448 }
3.449 }
3.450 }
3.451 - else if (strncmp(type,"onoff",5) == 0)
3.452 + else if (outputSubmenu[Submenu_type] == SubMenu_OnOff)
3.453 {
3.454 AddMenuItem(itemMenu, "1", "On");
3.455 AddMenuItem(itemMenu, "0", "Off");
3.456 }
3.457 else
3.458 {
3.459 - //list menu
3.460 -
3.461 - PrintToChatAll("Building List Menu");
3.462 -
3.463 - new String:temp[6];
3.464 new String:value[64];
3.465 new String:text[64];
3.466 - new i=1;
3.467 - new bool:more = true;
3.468
3.469 new String:admin[NAME_LENGTH];
3.470 -
3.471 - do
3.472 +
3.473 + for (new i=0; i<outputSubmenu[Submenu_listcount]; i++)
3.474 {
3.475 - // load the i and i. options from kv and make a menu from them (i* = required admin level to view)
3.476 - Format(temp,3,"%i",i);
3.477 - KvGetString(g_kvMenu, temp, value, sizeof(value), "");
3.478 + ReadPackString(outputSubmenu[Submenu_listdata], value, sizeof(value));
3.479 + ReadPackString(outputSubmenu[Submenu_listdata], text, sizeof(text));
3.480 + ReadPackString(outputSubmenu[Submenu_listdata], admin, sizeof(admin));
3.481
3.482 - Format(temp,5,"%i.",i);
3.483 - KvGetString(g_kvMenu, temp, text, sizeof(text), value);
3.484 -
3.485 - Format(temp,5,"%i*",i);
3.486 - KvGetString(g_kvMenu, temp, admin, sizeof(admin),"");
3.487 -
3.488 - if (value[0]=='\0')
3.489 - {
3.490 - more = false;
3.491 - }
3.492 - else if (CheckCommandAccess(client, admin, 0))
3.493 + if (CheckCommandAccess(client, admin, 0))
3.494 {
3.495 AddMenuItem(itemMenu, value, text);
3.496 }
3.497 -
3.498 - i++;
3.499 -
3.500 - } while (more);
3.501 -
3.502 + }
3.503 +
3.504 + ResetPack(outputSubmenu[Submenu_listdata]);
3.505 }
3.506
3.507 - KvGetString(g_kvMenu, "title", title, sizeof(title),"Choose an Option");
3.508 - SetMenuTitle(itemMenu, title);
3.509 + SetMenuTitle(itemMenu, outputSubmenu[Submenu_title]);
3.510
3.511 DisplayMenu(itemMenu, client, MENU_TIME_FOREVER);
3.512 }
3.513 else
3.514 {
3.515 //nothing else need to be done. Run teh command.
3.516 - new String:execute[7];
3.517 - KvGetString(g_kvMenu, "execute", execute, sizeof(execute), "player");
3.518
3.519 DisplayTopMenu(hAdminMenu, client, TopMenuPosition_LastCategory);
3.520
3.521 - if (execute[0]=='p') // assume 'player' type execute option
3.522 + if (outputItem[Item_execute] == Execute_Player) // assume 'player' type execute option
3.523 {
3.524 FakeClientCommand(client, g_command[client]);
3.525 }
3.526 @@ -471,8 +576,6 @@
3.527 g_command[client][0] = '\0';
3.528 g_currentPlace[client][Place_ReplaceNum] = 1;
3.529 }
3.530 -
3.531 - KvRewind(g_kvMenu);
3.532 }
3.533
3.534 public Menu_Selection(Handle:menu, MenuAction:action, param1, param2)