Advertisement
Guest User

menu.sp

a guest
Feb 23rd, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.05 KB | None | 0 0
  1. public Action:cmd_CallBack(client, args)
  2. {
  3. decl String:cmd[64], String:name[name_LENGTH];
  4. GetCmdArg(0, cmd, sizeof(cmd));
  5. if (GetTrieString(g_hTrie_cmd, cmd, name, name_LENGTH))
  6. {
  7. g_MyLastTargetId[client] = 0;
  8. g_sMyLastKey[client][0] = 0;
  9. ShowMenuByName(client, name);
  10. }
  11. return Plugin_Handled;
  12. }
  13.  
  14. stock ShowMenuByName(client, const String:name[], bool:bShowLastPage = false, time = 0, MC_flags = 0)
  15. {
  16. if (!strcmp(name, PLAYER_LIST))
  17. {
  18. ShowOldPlayerListMenu(client);
  19. return;
  20. }
  21.  
  22. new item = FindStringInArray(g_hMenuArray[ma_name], name);
  23. if (item < 0)
  24. return;
  25.  
  26. new item_count = GetArrayCell(g_hMenuArray[ma_item], item);
  27. if (item_count < 1)
  28. return;
  29.  
  30. g_MyLastMenuIndex[client] = item;
  31. decl String:key[key_LENGTH], String:text[text_LENGTH], x;
  32.  
  33. new menu_type = GetArrayCell(g_hMenuArray[ma_type], g_MyLastMenuIndex[client]);
  34. new Handle:menu = INVALID_HANDLE;
  35. new flags = GetUserFlagBits(client);
  36.  
  37. for (item = 1; item <= item_count; item++)
  38. {
  39. FormatEx(key, key_LENGTH, "%s%d", name, item);
  40.  
  41. if (GetTrieValue(g_hItemTrie[it_flag], key, x) && (!(flags & x) && !(flags & ADMFLAG_ROOT)))
  42. continue;
  43.  
  44. if (g_hClientTrie[client][ct_ItemHidden] && GetTrieValue(g_hClientTrie[client][ct_ItemHidden], key, x))
  45. continue;
  46.  
  47. if (!GetTrieValue(g_hItemTrie[it_type], key, x))
  48. continue; // wtf
  49.  
  50. // title
  51. if (!(MC_flags & MC_FLAG_no_title) && GetArrayString(g_hMenuArray[ma_title], g_MyLastMenuIndex[client], text, sizeof(text)) && text[0])
  52. {
  53. if (!menu) menu = menu_type == MC_MENU ? CreateMenu(menu_CallBack) : CreatePanel();
  54. wS_EditText(client, text, sizeof(text));
  55.  
  56. if (menu_type == MC_MENU)
  57. SetMenuTitle(menu, "%s\n \n", text);
  58. else
  59. {
  60. Format(text, sizeof(text), "%s\n \n", text);
  61. SetPanelTitle(menu, text);
  62. }
  63. }
  64.  
  65. if (x == IT_TEXT && !(MC_flags & MC_FLAG_no_text))
  66. {
  67. text[0] = 0;
  68. if (GetTrieString(g_hItemTrie[it_text], key, text, sizeof(text)))
  69. wS_EditText(client, text, sizeof(text));
  70.  
  71. if (menu_type == MC_MENU)
  72. {
  73. if (!menu) menu = CreateMenu(menu_CallBack);
  74. AddMenuItem(menu, "", text, ITEMDRAW_DISABLED);
  75. }
  76. else
  77. {
  78. if (!menu) menu = CreatePanel();
  79. DrawPanelText(menu, text);
  80. }
  81. }
  82. else if (x == IT_ITEM && !(MC_flags & MC_FLAG_no_item))
  83. {
  84. text[0] = 0;
  85. if (GetTrieString(g_hItemTrie[it_text], key, text, sizeof(text)))
  86. wS_EditText(client, text, sizeof(text));
  87.  
  88. new ITEMDRAW_ = (GetTrieString(g_hItemTrie[it_cmds], key, "", 0) && (!g_hClientTrie[client][ct_ItemBlocked] || !GetTrieValue(g_hClientTrie[client][ct_ItemBlocked], key, x))) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
  89. if (menu_type == MC_MENU)
  90. {
  91. if (!menu) menu = CreateMenu(menu_CallBack);
  92. AddMenuItem(menu, key, text, ITEMDRAW_);
  93. }
  94. else
  95. {
  96. if (!menu) menu = CreatePanel();
  97. if (GetTrieValue(g_hItemTrie[it_pos], key, x)) SetPanelCurrentKey(menu, x);
  98. DrawPanelItem(menu, text, ITEMDRAW_);
  99. }
  100. }
  101. }
  102.  
  103. if (!menu)
  104. return;
  105.  
  106. // back
  107. x = 0;
  108. if (!(MC_flags & MC_FLAG_no_back))
  109. {
  110. if ((GetArrayString(g_hMenuArray[ma_back_cmds], g_MyLastMenuIndex[client], text, sizeof(text)) && text[0])
  111. || (GetArrayString(g_hMenuArray[ma_back], g_MyLastMenuIndex[client], text, sizeof(text)) && text[0] && (!strcmp(text, PLAYER_LIST) || FindStringInArray(g_hMenuArray[ma_name], text) > -1)))
  112. {
  113. if (menu_type == MC_MENU)
  114. SetMenuExitBackButton(menu, true);
  115. else
  116. {
  117. x = 1;
  118. DrawPanelText(menu, " ");
  119. SetPanelCurrentKey(menu, PANEL_BACK);
  120. FormatEx(text, sizeof(text), "%T", "back", client);
  121. DrawPanelItem(menu, text);
  122. }
  123. }
  124. }
  125.  
  126. // exit
  127. if (!(MC_flags & MC_FLAG_no_exit) && GetArrayCell(g_hMenuArray[ma_exit], g_MyLastMenuIndex[client]) == 1)
  128. {
  129. if (menu_type == MC_PANEL)
  130. {
  131. if (!x) DrawPanelText(menu, " ");
  132. SetPanelCurrentKey(menu, g_Engine == Engine_CSGO ? 9 : 10);
  133. FormatEx(text, sizeof(text), "%T", "exit", client);
  134. DrawPanelItem(menu, text);
  135. }
  136. }
  137. else if (menu_type == MC_MENU)
  138. SetMenuExitButton(menu, false);
  139.  
  140. if (menu_type == MC_PANEL)
  141. {
  142. SendPanelToClient(menu, client, panel_CallBack, time);
  143. CloseHandle(menu);
  144. return;
  145. }
  146.  
  147. if (bShowLastPage && g_hClientTrie[client][ct_LastPage] && GetTrieValue(g_hClientTrie[client][ct_LastPage], name, x))
  148. DisplayMenuAtItem(menu, client, x, time);
  149. else
  150. DisplayMenu(menu, client, time);
  151. }
  152.  
  153. public menu_CallBack(Handle:menu, MenuAction:action, client, item)
  154. {
  155. if (action == MenuAction_End)
  156. CloseHandle(menu);
  157.  
  158. else if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)
  159. ShowBackMenu(client);
  160.  
  161. else if (action == MenuAction_Select && GetMenuItem(menu, item, g_sMyLastKey[client], key_LENGTH))
  162. {
  163. //
  164. decl String:name[name_LENGTH];
  165. GetArrayString(g_hMenuArray[ma_name], g_MyLastMenuIndex[client], name, name_LENGTH);
  166. if (!g_hClientTrie[client][ct_LastPage]) g_hClientTrie[client][ct_LastPage] = CreateTrie();
  167. SetTrieValue(g_hClientTrie[client][ct_LastPage], name, GetMenuSelectionPosition(), true);
  168. //
  169.  
  170. decl String:cmds[cmds_LENGTH];
  171.  
  172. if (GetTrieString(g_hItemTrie[it_info], g_sMyLastKey[client], cmds, cmds_LENGTH) && cmds[0])
  173. {
  174. if (!g_hClientTrie[client][ct_ItemInfo]) g_hClientTrie[client][ct_ItemInfo] = CreateTrie();
  175. SetTrieString(g_hClientTrie[client][ct_ItemInfo], name, cmds, true);
  176. }
  177.  
  178. if (GetTrieString(g_hItemTrie[it_cmds], g_sMyLastKey[client], cmds, cmds_LENGTH) && cmds[0])
  179. {
  180. wS_EditText(client, cmds, cmds_LENGTH);
  181. ServerCommand(cmds);
  182. }
  183. }
  184. }
  185.  
  186. public panel_CallBack(Handle:panel, MenuAction:action, client, item)
  187. {
  188. if (action != MenuAction_Select)
  189. return;
  190.  
  191. if (item == PANEL_BACK)
  192. {
  193. ClientCommand(client, "playgamesound buttons/combine_button7.wav");
  194. ShowBackMenu(client);
  195. return;
  196. }
  197.  
  198. if (item > PANEL_BACK)
  199. {
  200. ClientCommand(client, "playgamesound buttons/combine_button7.wav");
  201. return;
  202. }
  203.  
  204. // Раз panel опция кликабельна, то у неё есть cmds.
  205.  
  206. new item_count = GetArrayCell(g_hMenuArray[ma_item], g_MyLastMenuIndex[client]);
  207. if (item_count < 1)
  208. return; // wtf
  209.  
  210. ClientCommand(client, "playgamesound buttons/button14.wav");
  211. new item_number = 1;
  212.  
  213. decl String:name[name_LENGTH], String:key[key_LENGTH];
  214. GetArrayString(g_hMenuArray[ma_name], g_MyLastMenuIndex[client], name, name_LENGTH);
  215.  
  216. if (item_count > 1)
  217. {
  218. // 1. Создали panel 2. Добавили text 3. Добавили item
  219. // Здесь item == 1, но нам нужен key "name_2", т.к. добавленный text это "name_1".
  220.  
  221. // 1. Создали panel 2. Добавили text 3. Сместили опцию на 5 позицию 4. Добавили item
  222. // Здесь item == 5, но нам нужен key "name_2", т.к. добавленный text это "name_1".
  223.  
  224. item_number = -1;
  225.  
  226. for (new i = 1, valid_item = 0, pos; i <= item_count; i++)
  227. {
  228. FormatEx(key, key_LENGTH, "%s%d", name, i);
  229.  
  230. if (!GetTrieString(g_hItemTrie[it_cmds], key, "", 0))
  231. continue;
  232.  
  233. if (++valid_item == item) // valid_item = кликабельная опция с cmds
  234. {
  235. item_number = i;
  236. break;
  237. }
  238.  
  239. if (GetTrieValue(g_hItemTrie[it_pos], key, pos) && pos == item) // возможно это она, просто была смещена
  240. {
  241. item_number = i;
  242. break;
  243. }
  244. }
  245.  
  246. if (item_number == -1)
  247. {
  248. LogError("item_number == -1 (wtf)");
  249. return;
  250. }
  251. }
  252.  
  253. FormatEx(g_sMyLastKey[client], key_LENGTH, "%s%d", name, item_number);
  254. decl String:cmds[cmds_LENGTH];
  255.  
  256. if (GetTrieString(g_hItemTrie[it_info], g_sMyLastKey[client], cmds, cmds_LENGTH) && cmds[0])
  257. {
  258. if (!g_hClientTrie[client][ct_ItemInfo]) g_hClientTrie[client][ct_ItemInfo] = CreateTrie();
  259. SetTrieString(g_hClientTrie[client][ct_ItemInfo], name, cmds, true);
  260. }
  261.  
  262. if (GetTrieString(g_hItemTrie[it_cmds], g_sMyLastKey[client], cmds, cmds_LENGTH) && cmds[0])
  263. {
  264. wS_EditText(client, cmds, cmds_LENGTH);
  265. ServerCommand(cmds);
  266. }
  267. }
  268.  
  269. public PLAYER_LIST_CallBack(Handle:menu, MenuAction:action, client, item)
  270. {
  271. if (action == MenuAction_End)
  272. CloseHandle(menu);
  273.  
  274. else if (action == MenuAction_Cancel && item == MenuCancel_ExitBack)
  275. ShowBackMenu(client, true);
  276.  
  277. else if (action == MenuAction_Select)
  278. {
  279. if (g_hClientTrie[client][ct_PlayerList])
  280. SetTrieValue(g_hClientTrie[client][ct_PlayerList], "pos", GetMenuSelectionPosition(), true);
  281.  
  282. decl String:sId[16];
  283. if (GetMenuItem(menu, item, sId, sizeof(sId)))
  284. {
  285. g_MyLastTargetId[client] = StringToInt(sId);
  286. new target = GetClientOfUserId(g_MyLastTargetId[client]);
  287. if (target > 0)
  288. {
  289. decl String:cmds[cmds_LENGTH];
  290. if (g_hClientTrie[client][ct_PlayerList] && GetTrieString(g_hClientTrie[client][ct_PlayerList], "cmds", cmds, sizeof(cmds)))
  291. {
  292. g_TargetCanBeInMenu[client][target] = false;
  293. wS_EditText(client, cmds, sizeof(cmds));
  294. ServerCommand(cmds);
  295. return;
  296. }
  297. }
  298. else
  299. PrintCenterText(client, "%T", "TargetExit", client);
  300. }
  301.  
  302. ShowOldPlayerListMenu(client);
  303. }
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement