HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4.  
  5. new g_bwEnt[33]
  6.  
  7. #define PLUG_NAME "HATS"
  8. #define PLUG_AUTH "SgtBane"
  9. #define PLUG_VERS "0.2"
  10. #define PLUG_TAG "HATS"
  11.  
  12. #define menusize 220
  13.  
  14. new HatFile[64]
  15. new MenuPages, TotalHats
  16. new CurrentMenu[33]
  17.  
  18. #define MAX_HATS 64
  19. new HATMDL[MAX_HATS][41]
  20. new HATNAME[MAX_HATS][41]
  21.  
  22. public plugin_init()
  23. {
  24. register_plugin(PLUG_NAME, PLUG_VERS, PLUG_AUTH)
  25. register_concmd("amx_givehat", "Give_Hat", ADMIN_RCON, "<nick> <mdl #>")
  26. register_concmd("amx_removehats", "Remove_Hat", ADMIN_RCON, " - Removes hats from everyone.")
  27. register_menucmd(register_menuid("\ySapka Menu: [Oldal"),(1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9),"MenuCommand")
  28. register_clcmd("say /sapka", "ShowMenu", -1, "Shows Knife menu")
  29. }
  30.  
  31. public ShowMenu(id)
  32. {
  33. CurrentMenu[id] = 1
  34. ShowHats(id)
  35. return PLUGIN_HANDLED
  36. }
  37.  
  38. public ShowHats(id)
  39. {
  40. new keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)
  41.  
  42. new szMenuBody[menusize + 1], WpnID
  43. new nLen = format(szMenuBody, menusize, "\ySapka Menu: [Oldal %i/%i]^n",CurrentMenu[id],MenuPages)
  44.  
  45. // Get Hat Names And Add Them To The List
  46. for (new hatid=0; hatid < 8; hatid++) {
  47. WpnID = ((CurrentMenu[id] * 8) + hatid - 8)
  48. if (WpnID < TotalHats) {
  49. nLen += format(szMenuBody[nLen], menusize-nLen, "^n\w %i. %s",hatid + 1,HATNAME[WpnID])
  50. }
  51. }
  52.  
  53. // Next Page And Previous/Close
  54. if (CurrentMenu[id] == MenuPages) {
  55. nLen += format(szMenuBody[nLen], menusize-nLen, "^n^n\d9. Kovetkezo Oldal")
  56. } else {
  57. nLen += format(szMenuBody[nLen], menusize-nLen, "^n^n\w9. Kovetkezo Oldal")
  58. }
  59.  
  60. if (CurrentMenu[id] > 1) {
  61. nLen += format(szMenuBody[nLen], menusize-nLen, "^n\w0. Elozo Oldal")
  62. } else {
  63. nLen += format(szMenuBody[nLen], menusize-nLen, "^n\w0. Rendben")
  64. }
  65. show_menu(id, keys, szMenuBody, -1)
  66. return PLUGIN_HANDLED
  67. }
  68. public MenuCommand(id, key)
  69. {
  70. switch(key)
  71. {
  72. case 8: //9 - [Next Page]
  73. {
  74. if (CurrentMenu[id] < MenuPages) CurrentMenu[id]++
  75. ShowHats(id)
  76. return PLUGIN_HANDLED
  77. }
  78. case 9: //0 - [Close]
  79. {
  80. CurrentMenu[id]--
  81. if (CurrentMenu[id] > 0) ShowHats(id)
  82. return PLUGIN_HANDLED
  83. }
  84. default:
  85. {
  86. new HatID = ((CurrentMenu[id] * 8) + key - 8)
  87. if (HatID < TotalHats) {
  88. Set_Hat(id,HatID,id)
  89. }
  90. }
  91. }
  92. return PLUGIN_HANDLED
  93. }
  94.  
  95. public plugin_precache()
  96. {
  97. new cfgDir[32]
  98. get_configsdir(cfgDir,31)
  99. formatex(HatFile,63,"%s/HatList.ini",cfgDir)
  100. command_load()
  101.  
  102. for (new i = 1; i < TotalHats; ++i) {
  103. if (file_exists (HATMDL[i])) {
  104. precache_model(HATMDL[i])
  105. server_print("[%s] Precached %s",PLUG_TAG,HATMDL[i])
  106. } else {
  107. server_print("[%s] Failed to precache %s",PLUG_TAG,HATMDL[i])
  108. }
  109. }
  110. }
  111.  
  112. public client_connect(id)
  113. {
  114. if(g_bwEnt[id] > 0) engfunc(EngFunc_RemoveEntity,g_bwEnt[id])
  115. g_bwEnt[id] = 0
  116. }
  117.  
  118. public client_disconnect(id)
  119. {
  120. if(g_bwEnt[id] > 0) engfunc(EngFunc_RemoveEntity,g_bwEnt[id])
  121. g_bwEnt[id] = 0
  122. }
  123.  
  124. public Give_Hat(id)
  125. {
  126. new smodelnum[5], name[32]
  127. read_argv(1,name,31)
  128. read_argv(2,smodelnum,4)
  129.  
  130. new player = cmd_target(id,name,2)
  131. if (!player) {
  132. client_print(id,print_chat,"[%s] Ilyen jatekos nincs.",PLUG_TAG)
  133. return PLUGIN_HANDLED
  134. }
  135.  
  136. new imodelnum = (str_to_num(smodelnum))
  137. if (imodelnum > MAX_HATS) return PLUGIN_HANDLED
  138.  
  139. Set_Hat(player,imodelnum,id)
  140.  
  141. return PLUGIN_CONTINUE
  142. }
  143.  
  144. public Remove_Hat(id)
  145. {
  146. for (new i = 0; i < get_maxplayers(); ++i) {
  147. if (is_user_connected(i) && g_bwEnt[i] > 0) {
  148. engfunc(EngFunc_RemoveEntity,g_bwEnt[i])
  149. g_bwEnt[i] = 0
  150. }
  151. }
  152. client_print(id,print_chat,"[%s] Torolte mindenkinek a sapkajat.",PLUG_TAG)
  153. return PLUGIN_CONTINUE
  154. }
  155.  
  156. public Set_Hat(player,imodelnum,targeter)
  157. {
  158. new name[32]
  159. get_user_name(player, name, 31)
  160. if (imodelnum == 0) {
  161. if(g_bwEnt[player] > 0) engfunc(EngFunc_RemoveEntity,g_bwEnt[player])
  162. g_bwEnt[player] = 0
  163. client_print(targeter, print_chat, "[%s] Torolte a sapkajat %s",PLUG_TAG,name)
  164. } else if (file_exists(HATMDL[imodelnum])) {
  165. if(g_bwEnt[player] < 1) {
  166. g_bwEnt[player] = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  167. if(g_bwEnt[player] > 0)
  168. {
  169. set_pev(g_bwEnt[player], pev_movetype, MOVETYPE_FOLLOW)
  170. set_pev(g_bwEnt[player], pev_aiment, player)
  171. set_pev(g_bwEnt[player], pev_rendermode, kRenderNormal)
  172. set_pev(g_bwEnt[player], pev_renderamt, 0.0)
  173. engfunc(EngFunc_SetModel, g_bwEnt[player], HATMDL[imodelnum])
  174. }
  175. } else {
  176. engfunc(EngFunc_SetModel, g_bwEnt[player], HATMDL[imodelnum])
  177. }
  178. client_print(targeter, print_chat, "[%s] %s sapkat vett a fejere %s :)! ",PLUG_TAG,HATNAME[imodelnum],name)
  179. }
  180. }
  181.  
  182. public command_load()
  183. {
  184. if(file_exists(HatFile)) {
  185. HATMDL[0] = ""
  186. HATNAME[0] = "None"
  187. TotalHats = 1
  188. new sfLineData[128]
  189. new file = fopen(HatFile,"rt")
  190. while(file && !feof(file)) {
  191. fgets(file,sfLineData,127)
  192.  
  193. // Skip Comment and Empty Lines
  194. if (containi(sfLineData,";") > -1) continue
  195.  
  196. // BREAK IT UP!
  197. parse(sfLineData, HATMDL[TotalHats],40,HATNAME[TotalHats],40)
  198.  
  199. TotalHats += 1
  200. if(TotalHats >= MAX_HATS) {
  201. server_print("[%s] Reached hat limit",PLUG_TAG)
  202. break
  203. }
  204. }
  205. if(file) fclose(file)
  206. }
  207. MenuPages = floatround((TotalHats / 8.0), floatround_ceil)
  208. server_print("[%s] Loaded %i hats, Generated %i pages)",PLUG_TAG,TotalHats,MenuPages)
  209. }
  210.