HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #pragma semicolon 1
  2.  
  3. #include <amxmodx>
  4.  
  5. #define NVAULT_SAVE
  6.  
  7. #define PLUGIN_NAME "Crosshair Menu"
  8. #define PLUGIN_VERS "1.2.5"
  9. #define PLUGIN_AUTH "KriTo & PurposeLess"
  10.  
  11. new const crosshairs[][][] = {
  12. {"Lined Point","LinedPoint_R","LinedPoint_Y","LinedPoint_G","LinedPoint_P","LinedPoint_C"},
  13. {"Cross","Cross_R","Cross_Y","Cross_G","Cross_P","Cross_C"},
  14. {"Cross-2","Cross2_R","Cross2_Y","Cross2_G","Cross2_P","Cross2_C"},
  15. {"Point","Point_R","Point_Y","Point_G","Point_P","Point_C"},
  16. {"Square","Square_R","Square_Y","Square_G","Square_P","Square_C"},
  17. {"Square-2","Square2_R","Square2_Y","Square2_G","Square2_P","Square2_C"},
  18. {"Cool Cross","CoolCross_R","CoolCross_Y","CoolCross_G","CoolCross_P","CoolCross_C"}
  19. };
  20.  
  21. new const colors[][] = {
  22. "Piros",
  23. "Sárga",
  24. "Zöld",
  25. "Lila",
  26. "Cián"
  27. };
  28.  
  29. new
  30. g_crosshair_type[MAX_PLAYERS + 1],
  31. g_crosshair_color[MAX_PLAYERS + 1],
  32. bool:g_scope[MAX_PLAYERS + 1],
  33. g_msgids[4];
  34.  
  35. public plugin_init() {
  36. register_plugin(PLUGIN_NAME, PLUGIN_VERS, PLUGIN_AUTH);
  37.  
  38. register_clcmd("say /crosshair", "@clcmd_crosshair");
  39. register_clcmd("say /cross", "@clcmd_crosshair");
  40.  
  41. register_event("SetFOV", "@Event_SetFOV", "be");
  42. register_event("CurWeapon", "@Event_CurWeapon", "be", "1=1", "2!18");
  43.  
  44. g_msgids[0] = get_user_msgid("HideWeapon");
  45. g_msgids[1] = get_user_msgid("WeaponList");
  46. g_msgids[2] = get_user_msgid("SetFOV");
  47. g_msgids[3] = get_user_msgid("CurWeapon");
  48. }
  49.  
  50. @Event_SetFOV(const id) {
  51. if(!g_crosshair_type[id]) {
  52. return;
  53. }
  54.  
  55. new FOV = read_data(1);
  56.  
  57. if(FOV == 90) {
  58. g_scope[id] = false;
  59. }
  60. else {
  61. g_scope[id] = true;
  62. SetMessage_HideWeapon(id, 0);
  63. }
  64. }
  65.  
  66. public plugin_precache() {
  67. for(new i = 0; i < sizeof(crosshairs); i++) {
  68. for(new a = 1; a < sizeof(crosshairs[]); a++) {
  69. precache_generic(fmt("sprites/%s.txt", crosshairs[i][a]));
  70. }
  71. }
  72. precache_generic("sprites/recrosshair.spr");
  73. }
  74.  
  75. public client_putinserver(id) {
  76. client_cmd(id, "crosshair 1");
  77. }
  78.  
  79. @clcmd_crosshair(const id) {
  80. new menu = menu_create("\yCélkereszt Menü", "@clcmd_crosshair_handler");
  81.  
  82. if(g_crosshair_type[id]) {
  83. menu_additem(menu, fmt("Típus módosítás \dJelenegi: %s", crosshairs[g_crosshair_type[id] - 1][0]), "1");
  84. menu_additem(menu, fmt("Szín módosítás \dJelenegi: %s", colors[g_crosshair_color[id]]), "2");
  85. menu_additem(menu, "Visszaállítás", "3");
  86. }
  87. else {
  88. menu_additem(menu, "Típus módosítás \dJelenegi: Alap", "1");
  89. }
  90.  
  91. menu_display(id, menu);
  92. return PLUGIN_HANDLED;
  93. }
  94.  
  95. @clcmd_crosshair_handler(const id, const menu, const item) {
  96. if(item == MENU_EXIT) {
  97. menu_destroy(menu);
  98. return PLUGIN_HANDLED;
  99. }
  100. new data[6];
  101. menu_item_getinfo(menu, item, _, data, charsmax(data));
  102. new key = str_to_num(data), weapon = get_user_weapon(id);
  103. switch(key) {
  104. case 1: {
  105. g_crosshair_type[id] = Calc(g_crosshair_type[id] + 1, sizeof(crosshairs), 1);
  106. Change_Crosshair(id, weapon);
  107. }
  108. case 2: {
  109. g_crosshair_color[id] = Calc(g_crosshair_color[id] + 1, sizeof(colors) - 1, 0);
  110. Change_Crosshair(id, weapon);
  111. }
  112. case 3: {
  113. SetMessage_HideWeapon(id, 0);
  114. g_crosshair_type[id] = 0;
  115. }
  116. }
  117. @clcmd_crosshair(id);
  118. return PLUGIN_HANDLED;
  119. }
  120.  
  121. Calc(const arg, const max, const min) {
  122. return (arg > max) ? min : arg;
  123. }
  124.  
  125. @Event_CurWeapon(const id) {
  126. if(!g_crosshair_type[id] || g_scope[id]) {
  127. return;
  128. }
  129.  
  130. new weapon = read_data(2);
  131. Change_Crosshair(id, weapon);
  132. }
  133.  
  134. Change_Crosshair(const id, const weapon) {
  135. switch(weapon) {
  136. case CSW_P228: SetMessage_WeaponList(id, 9, 52);
  137. case CSW_HEGRENADE: SetMessage_WeaponList(id, 12, 1);
  138. case CSW_XM1014: SetMessage_WeaponList(id, 5, 32);
  139. case CSW_C4: SetMessage_WeaponList(id, 14, 1);
  140. case CSW_MAC10: SetMessage_WeaponList(id, 6, 100);
  141. case CSW_AUG: SetMessage_WeaponList(id, 4, 90);
  142. case CSW_SMOKEGRENADE: SetMessage_WeaponList(id, 13, 1);
  143. case CSW_ELITE: SetMessage_WeaponList(id, 10, 120);
  144. case CSW_FIVESEVEN: SetMessage_WeaponList(id, 7, 100);
  145. case CSW_UMP45: SetMessage_WeaponList(id, 6, 100);
  146. case CSW_GALIL: SetMessage_WeaponList(id, 4, 90);
  147. case CSW_FAMAS: SetMessage_WeaponList(id, 4, 90);
  148. case CSW_USP: SetMessage_WeaponList(id, 6, 100);
  149. case CSW_GLOCK18: SetMessage_WeaponList(id, 10, 120);
  150. case CSW_MP5NAVY: SetMessage_WeaponList(id, 10, 120);
  151. case CSW_M249: SetMessage_WeaponList(id, 3, 200);
  152. case CSW_M3: SetMessage_WeaponList(id, 5, 32);
  153. case CSW_M4A1: SetMessage_WeaponList(id, 4, 90);
  154. case CSW_TMP: SetMessage_WeaponList(id, 10, 120);
  155. case CSW_FLASHBANG: SetMessage_WeaponList(id, 11, 2);
  156. case CSW_DEAGLE: SetMessage_WeaponList(id, 8, 35);
  157. case CSW_SG552: SetMessage_WeaponList(id, 4, 90);
  158. case CSW_AK47: SetMessage_WeaponList(id, 2, 90);
  159. case CSW_KNIFE: SetMessage_WeaponList(id, -1, -1);
  160. case CSW_P90: SetMessage_WeaponList(id, 7, 100);
  161. default: return;
  162. }
  163.  
  164. SetMessage_HideWeapon(id, 1<<6);
  165. SetMessage_SetFOV(id, 89);
  166. SetMessage_CurWeapon(id);
  167. SetMessage_SetFOV(id, 90);
  168. }
  169.  
  170. SetMessage_WeaponList(const id, const pAmmoId, const pAmmoMaxAmount) {
  171. message_begin(MSG_ONE, g_msgids[1], .player = id); {
  172. write_string(crosshairs[g_crosshair_type[id] - 1][g_crosshair_color[id] + 1]);
  173. write_byte(pAmmoId);
  174. write_byte(pAmmoMaxAmount);
  175. write_byte(-1);
  176. write_byte(-1);
  177. write_byte(0);
  178. write_byte(11);
  179. write_byte(2);
  180. write_byte(0);
  181. }
  182. message_end();
  183. }
  184.  
  185. SetMessage_SetFOV(const id, const FOV) {
  186. message_begin(MSG_ONE, g_msgids[2], .player = id); {
  187. write_byte(FOV);
  188. }
  189. message_end();
  190. }
  191.  
  192. SetMessage_CurWeapon(const id) {
  193. new ammo;
  194. get_user_weapon(id, ammo);
  195.  
  196. message_begin(MSG_ONE, g_msgids[3], .player = id); {
  197. write_byte(1);
  198. write_byte(2);
  199. write_byte(ammo);
  200. }
  201. message_end();
  202. }
  203.  
  204. SetMessage_HideWeapon(const id, const byte) {
  205. message_begin(MSG_ONE, g_msgids[0], .player = id); {
  206. write_byte(byte);
  207. }
  208. message_end();
  209. }
  210.  
  211. #if defined NVAULT_SAVE
  212. #include <nvault>
  213.  
  214. new g_vault;
  215.  
  216. public plugin_cfg() {
  217. g_vault = nvault_open("crosshairvault");
  218.  
  219. if(g_vault == INVALID_HANDLE) {
  220. set_fail_state("Unknown nvault for crosshair");
  221. }
  222. }
  223.  
  224. public plugin_end() {
  225. nvault_close(g_vault);
  226. }
  227.  
  228. public client_authorized(id, const authid[]) {
  229. g_crosshair_type[id] = nvault_get(g_vault, fmt("%s_type", authid));
  230. g_crosshair_color[id] = nvault_get(g_vault, fmt("%s_color", authid));
  231. }
  232.  
  233. public client_disconnected(id) {
  234. new authid[MAX_AUTHID_LENGTH];
  235. get_user_authid(id, authid, charsmax(authid));
  236.  
  237. if(!g_crosshair_type[id]) {
  238. if(nvault_get(g_vault, fmt("%s_type", authid))) {
  239. nvault_remove(g_vault, fmt("%s_type", authid));
  240. nvault_remove(g_vault, fmt("%s_authid", authid));
  241. }
  242. return;
  243. }
  244.  
  245. new data[MAX_AUTHID_LENGTH+10];
  246.  
  247. num_to_str(g_crosshair_type[id], data, charsmax(data));
  248. nvault_pset(g_vault, fmt("%s_type", authid), data);
  249.  
  250. num_to_str(g_crosshair_color[id], data, charsmax(data));
  251. nvault_pset(g_vault, fmt("%s_color", authid), data);
  252. }
  253. #endif