HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #pragma semicolon 1
  2.  
  3. // Includes
  4. ////////////
  5.  
  6. #include <amxmodx>
  7. #include <amxmisc>
  8.  
  9. // Defines
  10. ////////////
  11.  
  12. #define MAX_PLAYERS 32
  13.  
  14. // Arrays
  15. ////////////
  16.  
  17. new Array:g_aColourName;
  18. new Array:g_aColourSettings;
  19.  
  20. // Integers
  21. ////////////
  22.  
  23. new g_iColour[MAX_PLAYERS+1][3];
  24. new g_iCustomColour[MAX_PLAYERS+1][3];
  25.  
  26. new g_iTemp[MAX_PLAYERS+1];
  27. new g_iMenuPage[MAX_PLAYERS+1];
  28.  
  29. new g_iMaxColours;
  30.  
  31. //////////////////////////////////////////////////////////////
  32. // Plugin Forwards //
  33. //////////////////////////////////////////////////////////////
  34.  
  35. public plugin_init()
  36. {
  37. register_plugin("Chat Colour Menu", "1.50", "shadow.hk");
  38.  
  39. register_dictionary("common.txt");
  40. register_dictionary("colourmenu.txt");
  41.  
  42. register_clcmd("say /szinek", "ColourMenu");
  43. register_clcmd("say szinek", "ColourMenu");
  44. register_clcmd("say /szinmenu", "ColourMenu");
  45.  
  46. register_clcmd("colour_value", "cmdColourValue", -1, "<value>");
  47.  
  48. register_menucmd(register_menuid("Chat Colour Menu"), 1023, "ColourMenu_handler");
  49. register_menucmd(register_menuid("Custom Colour Menu"), 1023, "CustomMenu_handler");
  50. }
  51.  
  52. public plugin_cfg()
  53. {
  54. g_aColourName = ArrayCreate(16);
  55. g_aColourSettings = ArrayCreate(3);
  56.  
  57. new configsdir[32], file[64];
  58. get_configsdir(configsdir, 31);
  59. format(file, 63, "%s/colours.ini", configsdir);
  60.  
  61. LoadFile(file);
  62. }
  63.  
  64. //////////////////////////////////////////////////////////////
  65. // Client Forwards //
  66. //////////////////////////////////////////////////////////////
  67.  
  68. public client_putinserver(id)
  69. {
  70. g_iCustomColour[id] = { 0, 0, 0 };
  71. set_task(0.5, "taskColours", id);
  72. }
  73.  
  74. //////////////////////////////////////////////////////////////
  75. // Commands //
  76. //////////////////////////////////////////////////////////////
  77.  
  78. public cmdColourValue(id)
  79. {
  80. new szArg[4];
  81. read_argv(1, szArg, 3);
  82.  
  83. if( !is_str_num(szArg) )
  84. {
  85. return PLUGIN_HANDLED;
  86. }
  87.  
  88. g_iCustomColour[id][g_iTemp[id]] = clamp(str_to_num(szArg), 0, 255);
  89.  
  90. CustomMenu(id);
  91. return PLUGIN_HANDLED;
  92. }
  93.  
  94. //////////////////////////////////////////////////////////////
  95. // Menus & Menu Handlers //
  96. //////////////////////////////////////////////////////////////
  97.  
  98. // taken from alka's voteban source code
  99. public ColourMenu(id, iPos)
  100. {
  101. static i, iKeys, szMenu[512], iCurrPos;
  102. iCurrPos = 0;
  103.  
  104. static iStart, iEnd;
  105. iStart = iPos * 6;
  106.  
  107. static iPages;
  108. iPages = floatround(float(g_iMaxColours) / 6.0, floatround_ceil);
  109.  
  110. iEnd = iStart + 6;
  111. iKeys = ( MENU_KEY_0 | MENU_KEY_7 | MENU_KEY_8 );
  112.  
  113. if( iEnd > g_iMaxColours )
  114. {
  115. iEnd = g_iMaxColours;
  116. }
  117.  
  118. // heading
  119. static iLen;
  120. iLen = formatex(szMenu, sizeof(szMenu) - 1, "\y%L (\w%i/%i\y):^n^n", id, "MENU_COLOUR", g_iMenuPage[id] + 1, iPages);
  121.  
  122. // colour keys
  123. for(i = iStart; i < iEnd; i++)
  124. {
  125. iKeys |= ( 1<<iCurrPos++ );
  126. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "\r%d. \w%a^n", iCurrPos, ArrayGetStringHandle(g_aColourName, i));
  127. }
  128.  
  129. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "^n\r7. \y%L", id, "MENU_CUSTOM");
  130. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "^n\r8. \y%L^n", id, "COLOUR_DEFAULT");
  131.  
  132. // forward key
  133. if( iEnd == g_iMaxColours )
  134. {
  135. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "^n\r9. \d%L", id, "MORE");
  136. }
  137. else
  138. {
  139. iKeys |= MENU_KEY_9;
  140. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "^n\r9. \w%L", id, "MORE");
  141. }
  142.  
  143. // exit key
  144. if( !g_iMenuPage[id] )
  145. {
  146. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "^n\r0. \w%L", id, "EXIT");
  147. }
  148. else
  149. {
  150. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "^n\r0. \w%L", id, "BACK");
  151. }
  152.  
  153. show_menu(id, iKeys, szMenu, -1, "Chat Colour Menu");
  154. return PLUGIN_HANDLED;
  155. }
  156.  
  157. public ColourMenu_handler(id, key)
  158. {
  159. switch( key )
  160. {
  161. case 6:
  162. {
  163. CustomMenu(id);
  164. return PLUGIN_HANDLED;
  165. }
  166. case 7:
  167. {
  168. client_cmd(id, "con_color ^"%i %i %i^"", g_iColour[id][0], g_iColour[id][1], g_iColour[id][2]);
  169. client_print(id, print_chat, "[SzinesChat] %L %L szinre", id, "COLOUR_SET", id, "COLOUR_DEFAULT");
  170. }
  171. case 8: ++g_iMenuPage[id];
  172. case 9:
  173. {
  174. if( !g_iMenuPage[id] )
  175. {
  176. return PLUGIN_HANDLED;
  177. }
  178.  
  179. --g_iMenuPage[id];
  180. }
  181. default:
  182. {
  183. static colour, colours[3];
  184. colour = ( g_iMenuPage[id] * 6 + key );
  185.  
  186. ArrayGetArray(g_aColourSettings, colour, colours);
  187.  
  188. client_cmd(id, "con_color ^"%i %i %i^"", colours[0], colours[1], colours[2]);
  189. client_print(id, print_chat, "[SzinesChat] %L %a szinre", id, "COLOUR_SET", ArrayGetStringHandle(g_aColourName, colour));
  190. }
  191. }
  192.  
  193. ColourMenu(id, g_iMenuPage[id]);
  194. return PLUGIN_HANDLED;
  195. }
  196.  
  197. public CustomMenu(id)
  198. {
  199. new iLen, szMenu[256], iKeys;
  200. iKeys = ( MENU_KEY_0 | MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_8 | MENU_KEY_9 );
  201.  
  202. iLen = formatex(szMenu, sizeof(szMenu) - 1, "\y%L:^n^n", id, "MENU_CUSTOM");
  203.  
  204. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "\r1. \w%L: \y%i^n", id, "RED", g_iCustomColour[id][0]);
  205. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "\r2. \w%L: \y%i^n", id, "GREEN", g_iCustomColour[id][1]);
  206. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "\r3. \w%L: \y%i^n^n", id, "BLUE", g_iCustomColour[id][2]);
  207.  
  208. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "\r8. \y%L^n", id, "CUSTOM_SET");
  209. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "\r9. \w%L^n", id, "BACK");
  210. iLen += formatex(szMenu[iLen], sizeof(szMenu) - 1 - iLen, "\r0. \w%L", id, "EXIT");
  211.  
  212. show_menu(id, iKeys, szMenu, -1, "Custom Colour Menu");
  213. return PLUGIN_HANDLED;
  214. }
  215.  
  216. public CustomMenu_handler(id, key)
  217. {
  218. switch( key )
  219. {
  220. case 0, 1, 2:
  221. {
  222. g_iTemp[id] = key;
  223.  
  224. client_cmd(id, "messagemode colour_value");
  225. client_print(id, print_chat, "[SzinesChat] %L", id, "CUSTOM_VALUE");
  226. }
  227.  
  228. case 7:
  229. {
  230. CustomMenu(id);
  231.  
  232. client_cmd(id, "con_color ^"%i %i %i^"", g_iCustomColour[id][0], g_iCustomColour[id][1], g_iCustomColour[id][2]);
  233. client_print(id, print_chat, "[SzinesChat] %L ^"%i %i %i^"", id, "COLOUR_SET", g_iCustomColour[id][0], g_iCustomColour[id][1], g_iCustomColour[id][2]);
  234. }
  235. case 8: ColourMenu(id, g_iMenuPage[id]);
  236. case 9: g_iMenuPage[id] = 0;
  237. }
  238.  
  239. return PLUGIN_HANDLED;
  240. }
  241.  
  242. //////////////////////////////////////////////////////////////
  243. // Tasks //
  244. //////////////////////////////////////////////////////////////
  245.  
  246. public taskColours(id)
  247. {
  248. query_client_cvar(id, "con_color", "fwdConColour");
  249. }
  250.  
  251. //////////////////////////////////////////////////////////////
  252. // Miscellaneous Forwards //
  253. //////////////////////////////////////////////////////////////
  254.  
  255. public fwdConColour(id, const cvar[], const value[])
  256. {
  257. new colour[12];
  258. copy(colour, 11, value);
  259.  
  260. if( contain(colour, "+") != -1 )
  261. {
  262. replace_all(colour, 11, "+", " ");
  263. }
  264.  
  265. new szData[3][4];
  266. parse(colour, szData[0], 3, szData[1], 3, szData[2], 3);
  267.  
  268. g_iColour[id][0] = clamp(str_to_num(szData[0]), 0, 255);
  269. g_iColour[id][1] = clamp(str_to_num(szData[1]), 0, 255);
  270. g_iColour[id][2] = clamp(str_to_num(szData[2]), 0, 255);
  271. }
  272.  
  273. //////////////////////////////////////////////////////////////
  274. // File Data //
  275. //////////////////////////////////////////////////////////////
  276.  
  277. // Load Colour File
  278. LoadFile(const file[])
  279. {
  280. // Create a default file, if it doesn't exist
  281. if( !file_exists(file) )
  282. {
  283. write_file(file, "; Szin Konfiguracios Fajl^n; Hasznalat: <szinnev> <piros> <zold> <kek>^n^"Alap^" 255 180 30");
  284.  
  285. ArrayPushString(g_aColourName, "CS Default");
  286. ArrayPushArray(g_aColourSettings, { 255, 180, 30 });
  287.  
  288. g_iMaxColours = 1;
  289.  
  290. log_amx("%L", LANG_SERVER, "LOG_ERROR");
  291. return;
  292. }
  293.  
  294. new szLine[64], szData[3][4], szColourName[16], colours[3];
  295.  
  296. new File = fopen(file, "r");
  297.  
  298. while( !feof(File) )
  299. {
  300. fgets(File, szLine, 63);
  301. trim(szLine);
  302.  
  303. if( !szLine[0] || szLine[0] == '^n' || szLine[0] == ';' )
  304. {
  305. continue;
  306. }
  307.  
  308. parse(szLine, szColourName, 15, szData[0], 3, szData[1], 3, szData[2], 3);
  309.  
  310. colours[0] = clamp(str_to_num(szData[0]), 0, 255);
  311. colours[1] = clamp(str_to_num(szData[1]), 0, 255);
  312. colours[2] = clamp(str_to_num(szData[2]), 0, 255);
  313.  
  314. ArrayPushArray(g_aColourSettings, colours);
  315. ArrayPushString(g_aColourName, szColourName);
  316. }
  317.  
  318. fclose(File);
  319.  
  320. g_iMaxColours = ArraySize(g_aColourName);
  321.  
  322. log_amx("%L", LANG_SERVER, "LOG_LOADED", g_iMaxColours);
  323. }