HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <engine>
  4. #include <colorchat>
  5.  
  6. new const Plugin[] = {"Sapik"}
  7. new const Version[] = {"1.0"}
  8. new const Author[] = {"LyleChriss"}
  9.  
  10. new const Prefix[] = {""}
  11.  
  12. //#define FLAG ADMIN_KICK
  13.  
  14. new const MenuCmds[][] = {
  15. "say /sapka",
  16. "say /sapik",
  17. "say /sapi"
  18. }
  19.  
  20. new const RemoveCmds[][] = {
  21. "say /alap",
  22. "say /nincs",
  23. "say /nohat",
  24. "say remove"
  25. }
  26.  
  27. enum _:DATA
  28. {
  29. Name[32],
  30. Model[32]
  31. }
  32. new sData[DATA]
  33.  
  34. new Trie:SayHats, Array:Hats
  35. new g_HatEnt[33]
  36.  
  37. public plugin_init() {
  38. register_plugin(Plugin, Version, Author)
  39.  
  40. for(new i; i<sizeof(MenuCmds);i++)
  41. {
  42. #if defined FLAG
  43. register_clcmd(MenuCmds[i], "Hats_Menu", FLAG)
  44. #else
  45. register_clcmd(MenuCmds[i], "Hats_Menu")
  46. #endif
  47. }
  48. for(new i; i<sizeof(RemoveCmds);i++)
  49. {
  50. #if defined FLAG
  51. register_clcmd(RemoveCmds[i], "Remove_Hat", FLAG)
  52. #else
  53. register_clcmd(RemoveCmds[i], "Remove_Hat")
  54. #endif
  55. }
  56.  
  57. register_clcmd("say", "sayhandler");
  58. register_clcmd("say_team", "sayhandler");
  59. }
  60.  
  61. public plugin_precache()
  62. {
  63. SayHats=TrieCreate()
  64. Hats=ArrayCreate(DATA)
  65. new sBuffer[256], sFile[64], pFile
  66. get_localinfo("amxx_configsdir", sFile, charsmax(sFile))
  67. format(sFile, charsmax(sFile), "%s/hats.ini", sFile)
  68.  
  69. pFile = fopen(sFile, "rt")
  70.  
  71. if(pFile)
  72. {
  73. while(!feof(pFile))
  74. {
  75. fgets(pFile, sBuffer, charsmax(sBuffer))
  76. trim(sBuffer)
  77. if(sBuffer[0] == ';') continue;
  78.  
  79. parse(sBuffer, sData[Name], 31, sData[Model], 31)
  80.  
  81. if(containi(sData[Model], ".mdl") && !TrieKeyExists(SayHats, sData[Name]))
  82. {
  83. precache_model(sData[Model])
  84. TrieSetString(SayHats, sData[Name], sData[Model])
  85. ArrayPushArray(Hats, sData)
  86. }
  87. }
  88. fclose(pFile)
  89. }
  90. else write_file(sFile, ";^"hat name^" ^"models/hats_folder/hat_model.mdl^"^n")
  91. }
  92.  
  93. public client_connect(id)
  94. {
  95. if(g_HatEnt[id] > 0) remove_entity(g_HatEnt[id])
  96. g_HatEnt[id] = 0
  97. }
  98.  
  99. public client_disconnect(id)
  100. {
  101. if(g_HatEnt[id] > 0) remove_entity(g_HatEnt[id])
  102. g_HatEnt[id] = 0
  103. }
  104.  
  105. public sayhandler(id)
  106. {
  107. #if defined FLAG
  108. if(~get_user_flags(id) & FLAG) return;
  109. #endif
  110.  
  111. new message[190]; read_args(message, charsmax(message));
  112. remove_quotes(message);
  113.  
  114. if(TrieKeyExists(SayHats, message))
  115. {
  116. new sModel[64];
  117. TrieGetString(SayHats, message, sModel, charsmax(sModel));
  118. Set_Hat(id, sModel, message);
  119. }
  120. }
  121.  
  122. public Remove_Hat(id, lvl, cid)
  123. {
  124. #if defined FLAG
  125. if(cmd_access(id, lvl, cid, 0))
  126. {
  127. #endif
  128. remove_entity(g_HatEnt[id])
  129. g_HatEnt[id] = 0
  130. if(Prefix[0])
  131. ColorChat(id, NORMAL, "^4[%s]^1 Törölted a sapkád.", Prefix)
  132. else
  133. ColorChat(0, NORMAL, "^4[%s %s]^1 Törölted a sapkád.", Plugin, Version)
  134. #if defined FLAG
  135. }
  136. #endif
  137. }
  138.  
  139. public Hats_Menu(id, lvl, cid)
  140. {
  141. #if defined FLAG
  142. if(cmd_access(id, lvl, cid, 0))
  143. {
  144. #endif
  145. new txt[128]
  146. formatex(txt, charsmax(txt), "%s v%s by %s", Plugin, Version, Author)
  147.  
  148. new menu = menu_create(txt, "Hats_Handler")
  149.  
  150. menu_additem(menu, "Nincs", "", 0)
  151. for(new i;i<ArraySize(Hats);i++)
  152. {
  153. ArrayGetArray(Hats, i, sData)
  154. formatex(txt, charsmax(txt), "%s", sData[Name])
  155.  
  156. menu_additem(menu, txt, "", 0)
  157. }
  158.  
  159. menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
  160. menu_setprop(menu, MPROP_BACKNAME, "Vissza")
  161. menu_setprop(menu, MPROP_NEXTNAME, "Következő")
  162. menu_setprop(menu, MPROP_EXITNAME, "Kilépés")
  163.  
  164. menu_display(id, menu, 0)
  165. #if defined FLAG
  166. }
  167. #endif
  168. }
  169.  
  170. public Hats_Handler(id, menu, item)
  171. {
  172. if(item == MENU_EXIT) {
  173. menu_destroy(menu);
  174. return PLUGIN_HANDLED;
  175. }
  176.  
  177. if(item == 0)
  178. {
  179. remove_entity(g_HatEnt[id])
  180. g_HatEnt[id] = 0
  181. if(Prefix[0])
  182. ColorChat(id, NORMAL, "^4[%s]^1 Törölted a sapkád.", Prefix)
  183. else
  184. ColorChat(0, NORMAL, "^4[%s %s]^1 Törölted a sapkád.", Plugin, Version)
  185. }
  186. else
  187. {
  188. ArrayGetArray(Hats, item, sData)
  189. Set_Hat(id, sData[Model], sData[Name])
  190. }
  191. menu_destroy(menu);
  192. return PLUGIN_HANDLED;
  193. }
  194.  
  195. public Set_Hat(id, model[], name[])
  196. {
  197. if(g_HatEnt[id] < 1)
  198. {
  199. g_HatEnt[id] = create_entity("info_target")
  200.  
  201. entity_set_string(g_HatEnt[id], EV_SZ_classname, "hat")
  202. entity_set_edict(g_HatEnt[id], EV_ENT_aiment, id)
  203. entity_set_edict(g_HatEnt[id], EV_ENT_owner, id)
  204. entity_set_int(g_HatEnt[id], EV_INT_movetype, MOVETYPE_FOLLOW)
  205. entity_set_model(g_HatEnt[id], model)
  206. }
  207. else
  208. entity_set_model(g_HatEnt[id], model)
  209.  
  210. if(Prefix[0])
  211. ColorChat(id, NORMAL, "^4[%s]^1 kiválasztottad a(z) ^3%s ^1sapkát.", Prefix, name)
  212. else
  213. ColorChat(0, NORMAL, "^4[%s %s]^1 kiválasztottad a(z) ^3%s ^1sapkát.", Plugin, Version, name)
  214.  
  215. }
  216.  
  217. public plugin_end()
  218. {
  219. ArrayDestroy(Hats)
  220. TrieDestroy(SayHats)
  221. }
  222.