Advertisement
Guest User

Menu

a guest
May 9th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <cstrike>
  4. #include <fun>
  5.  
  6. #define PLUGIN "JB CT Menu"
  7. #define VERSION "1.0"
  8. #define AUTHOR "MiX"
  9.  
  10. #define COLOR_OFF -1
  11. #define COLOR_RED 0
  12. #define COLOR_BLUE 1
  13. #define COLOR_GREEN 2
  14. #define COLOR_LAST 2
  15.  
  16. new const MSG_PREFIX[] = "|Fn|"; // Defines the Message Prefix
  17. new g_iSelectedColor[33], g_sayText;
  18.  
  19. public plugin_init()
  20. {
  21. register_plugin(PLUGIN, VERSION, AUTHOR);
  22. register_clcmd("say /ctmenu", "clcmd_say_ctmenu", _, "- Opens a menu for CTs");
  23. register_logevent("logevent_roundstart", 2, "1=Round_Start");
  24. g_sayText = get_user_msgid("SayText");
  25. }
  26.  
  27. // Unglow all Terrorists on round start
  28. public logevent_roundstart()
  29. {
  30. static i;
  31. for (i = 0; i < 33; ++i)
  32. if (is_user_alive(i))
  33. set_user_rendering(i, kRenderFxGlowShell, 0, 0, 0);
  34. }
  35.  
  36. srv_message(id, const message[], any:...)
  37. {
  38. static szMessage[192];
  39. static const MSG_PREFIX_LENGTH = (sizeof(MSG_PREFIX) + 3);
  40. formatex(szMessage, MSG_PREFIX_LENGTH, "^x04%s^x01 ", MSG_PREFIX);
  41. vformat(szMessage[MSG_PREFIX_LENGTH], 191 - MSG_PREFIX_LENGTH, message, 3);
  42.  
  43. if (!id) {
  44. message_begin(MSG_BROADCAST, g_sayText, _, -1);
  45. write_byte(-1);
  46. } else {
  47. message_begin(MSG_ONE_UNRELIABLE, g_sayText, _, id);
  48. write_byte(id);
  49. }
  50. write_string(szMessage);
  51. message_end();
  52. }
  53.  
  54. // A player said /ctmenu in chat
  55. public clcmd_say_ctmenu(id)
  56. {
  57. // Check if user is an alive CT, else print an error message
  58. if (cs_get_user_team(id) != CS_TEAM_CT || !is_user_alive(id)) {
  59. srv_message(id, "You cannot open this menu as it's for alive CTs only.");
  60. return PLUGIN_HANDLED;
  61. }
  62. new menu = menu_create("CT Menu", "menu_handle_ct");
  63. menu_additem(menu, "Glow Players");
  64. menu_additem(menu, "Glow into 50/50");
  65. menu_additem(menu, "\dOpen Cells");
  66. menu_additem(menu, "\dStart a Funday");
  67. menu_display(id, menu);
  68. return PLUGIN_HANDLED;
  69. }
  70.  
  71. // Handles the option chosen in the CT Menu
  72. public menu_handle_ct(id, menu, item)
  73. {
  74. switch (item) {
  75. case 0: {
  76. menu_destroy(menu);
  77. g_iSelectedColor[id] = 0; // Set the first color option to the default color
  78. menu_display(id, menu_create_glow(id));
  79. }
  80. case 1: {
  81. menu_destroy(menu);
  82. glow_terrors_random(id);
  83. }
  84. case 2: {
  85. menu_destroy(menu);
  86. srv_message(id, "Functionality not yet implemented");
  87. }
  88. case 3: {
  89. menu_destroy(menu);
  90. srv_message(id, "Functionality not yet implemented");
  91. }
  92. default: // On exit
  93. menu_destroy(menu);
  94. }
  95. return PLUGIN_HANDLED;
  96. }
  97.  
  98. // Creates and returns the menu for glowing Terrorists
  99. public menu_create_glow(id)
  100. {
  101. static i, iTerrors[32], iTerrorsNum, iItemCount, szColorItem[17], szTempName[34], szMenuInfo[1];
  102. static iTempId;
  103.  
  104. // The currently selected color
  105. switch (g_iSelectedColor[id]) {
  106. case COLOR_RED:
  107. copy(szColorItem, 16, "\yColor: \wRed");
  108. case COLOR_BLUE:
  109. copy(szColorItem, 16, "\yColor: \wBlue");
  110. case COLOR_GREEN:
  111. copy(szColorItem, 16, "\yColor: \wGreen");
  112. default:
  113. copy(szColorItem, 16, "\yColor: \wOff");
  114. }
  115.  
  116. new menu = menu_create("CT Menu - Glow", "menu_handle_glow");
  117. menu_additem(menu, "\yUnglow all", {-1});
  118.  
  119. get_players(iTerrors, iTerrorsNum, "e", "TERRORIST");
  120. iItemCount = 1; // The amount of items on the current page
  121. for (i = 0; i < iTerrorsNum; i++) {
  122. iItemCount++;
  123. if (iItemCount > 6) {
  124. // The 7th item is the color chooser; 8 and 9 are previous and next page
  125. menu_additem(menu, szColorItem, {0});
  126. iItemCount = 0;
  127. }
  128. iTempId = iTerrors[i];
  129. szMenuInfo[0] = iTempId; // Store the ID in the info
  130. if (is_user_alive(iTempId)) {
  131. get_user_name(iTempId, szTempName, 33);
  132. } else {
  133. copy(szTempName, 2, "\d");
  134. get_user_name(iTempId, szTempName[2], 31);
  135. }
  136. menu_additem(menu, szTempName, szMenuInfo);
  137. }
  138. menu_additem(menu, szColorItem, {0}); // The last item is always the color chooser
  139.  
  140. return menu;
  141. }
  142.  
  143. // Handles the option chosen in the Glow menu
  144. public menu_handle_glow(id, menu, item)
  145. {
  146. if (item == MENU_EXIT) {
  147. menu_destroy(menu);
  148. return PLUGIN_HANDLED;
  149. }
  150.  
  151. // Get the selected item from the info
  152. static szMenuInfo[1], iTarget, iAccess, iCallback, iPage;
  153. menu_item_getinfo(menu, item, iAccess, szMenuInfo, 1, _, _, iCallback);
  154. iTarget = szMenuInfo[0];
  155.  
  156. // Check which item was selected
  157. switch (iTarget) {
  158. case -1: { // Unglow all
  159. static i, iTerrors[32], iTerrorsNum, szName[32];
  160. get_players(iTerrors, iTerrorsNum, "ae", "TERRORIST");
  161. for (i = 0; i < iTerrorsNum; i++)
  162. set_user_rendering(iTerrors[i], kRenderFxGlowShell, 0, 0, 0);
  163.  
  164. // Announce in chat
  165. get_user_name(id, szName, 31);
  166. srv_message(0, "%s has split the prisoners into two teams.", szName);
  167. }
  168. case 0: { // Change color
  169. if (g_iSelectedColor[id] >= COLOR_LAST)
  170. g_iSelectedColor[id] = COLOR_OFF;
  171. else
  172. g_iSelectedColor[id]++;
  173. }
  174. default: { // Glow a player
  175. if (is_user_alive(iTarget)) { // Disregard dead players
  176. static iColor[3], szColor[6], szName[32], szTarg[32];
  177.  
  178. // The selected color
  179. switch (g_iSelectedColor[id]) {
  180. case COLOR_RED:{
  181. iColor = {255, 0, 0};
  182. copy(szColor, 5, "red");
  183. }
  184. case COLOR_BLUE: {
  185. iColor = {0, 0, 255};
  186. copy(szColor, 5, "blue");
  187. }
  188. case COLOR_GREEN: {
  189. iColor = {0, 255, 0};
  190. copy(szColor, 5, "green");
  191. }
  192. default: iColor = {0, 0, 0};
  193. }
  194. set_user_rendering(iTarget, kRenderFxGlowShell, iColor[0], iColor[1], iColor[2]);
  195. }
  196. }
  197. }
  198. menu_destroy(menu);
  199. iPage = (item / 7); // 7 items per page (previous/next page and exit do not count as items)
  200. menu_display(id, menu_create_glow(id), iPage);
  201. return PLUGIN_HANDLED;
  202. }
  203.  
  204. // Divide all alive Terrorists into two Teams and glows them accordingly
  205. public glow_terrors_random(id)
  206. {
  207. static i, iTerrors[32], iTerrorsNum, iTeamMax, iTeamANum, iTeamBNum, iTeamA[16], iTeamB[16];
  208. get_players(iTerrors, iTerrorsNum, "ae", "TERRORIST");
  209.  
  210. iTeamMax = (iTerrorsNum / 2);
  211. iTeamANum = 0;
  212. iTeamBNum = 0;
  213. for (i = 0; i < iTerrorsNum; i++) {
  214. if (iTeamANum < iTeamMax) { // Check if Team A isn't full yet
  215. // Check if Team B isn't full yet, then randomly decide
  216. if ((iTeamBNum < iTeamMax) && random(2)) {
  217. iTeamB[iTeamBNum] = iTerrors[i];
  218. iTeamBNum++;
  219. } else { // Fill Team A with (remaining) Players
  220. iTeamA[iTeamANum] = iTerrors[i];
  221. iTeamANum++;
  222. }
  223. } else { // Fill Team B with remaining Players
  224. iTeamB[iTeamBNum] = iTerrors[i];
  225. iTeamBNum++;
  226. }
  227. }
  228. for (i = 0; i < iTeamANum; i++)
  229. set_user_rendering(iTeamA[i], kRenderFxGlowShell, 255, 0, 0);
  230.  
  231. for (i = 0; i < iTeamBNum; i++)
  232. set_user_rendering(iTeamB[i], kRenderFxGlowShell, 0, 0, 255);
  233.  
  234. // Announce in chat
  235. static szName[32];
  236. get_user_name(id, szName, 31);
  237. srv_message(0, "%s has randomly divided the Terrorists into two Teams.", szName);
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement