HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. [ZP] Extra Item : Immunity
  3.  
  4. Plugin Thread :
  5.  
  6. http://forums.alliedmods.net/showthread.php?t=105537
  7. */
  8.  
  9.  
  10. #include <amxmodx>
  11. #include <fun>
  12. #include <hamsandwich>
  13. #include <zombieplague>
  14.  
  15. #define AUTHOR "Javivi & sunx"
  16.  
  17. // If you want immunity for all round, uncomment this !
  18. //#define ALLROUND
  19.  
  20. // Task IDs
  21. #define TASK_AURA 321
  22.  
  23. // Ammo Pack cost
  24. #if !defined ALLROUND
  25. new const ITEM_COST = 15
  26. #else
  27. new const ITEM_COST = 30
  28. #endif
  29.  
  30. // Variables
  31. new g_itemID, g_HudSync
  32.  
  33. // Cvars
  34. #if !defined ALLROUND
  35. new cvar_duration
  36. #endif
  37.  
  38. new cvar_auracolor, cvar_aurasize
  39.  
  40. // Array
  41. new g_HaveImmunity[33], Time[33]
  42.  
  43.  
  44. public plugin_init()
  45. {
  46. // Plugin register
  47. register_plugin("[ZP] Extra Item: Immunity", "3.0", AUTHOR)
  48.  
  49. // Cvars
  50. #if !defined ALLROUND
  51. cvar_duration = register_cvar("zp_immunity_duration", "30")
  52. #endif
  53.  
  54. cvar_auracolor = register_cvar("zp_immunity_color", "255 165 0")
  55. cvar_aurasize = register_cvar("zp_immunity_aura_size", "25")
  56.  
  57. // Variables
  58. #if !defined ALLROUND
  59. g_itemID = zp_register_extra_item("Immunity", ITEM_COST , ZP_TEAM_HUMAN)
  60. #else
  61. g_itemID = zp_register_extra_item("Immunity (All round)", ITEM_COST , ZP_TEAM_HUMAN)
  62. #endif
  63. g_HudSync = CreateHudSyncObj()
  64.  
  65. // Language File
  66. register_dictionary("zp_extra_immunity.txt")
  67.  
  68. // Hamsandwich forward
  69. RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
  70.  
  71. // Gamemonitor info
  72. static szCvar[30]
  73. formatex(szCvar, charsmax(szCvar), "v3.0 by Javivi")
  74. register_cvar("zp_immunity", szCvar, FCVAR_SERVER|FCVAR_SPONLY)
  75. }
  76.  
  77. // If some one buy the item
  78. public zp_extra_item_selected(id, itemid)
  79. {
  80. if(itemid == g_itemID)
  81. {
  82. // Wait until the round start
  83. if (!zp_has_round_started())
  84. {
  85. new Temp[32]
  86. formatex(Temp, 31 , "!g[ZP] !y%L", id, "WAIT")
  87. chat_color(id, Temp)
  88. zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + ITEM_COST)
  89.  
  90. return
  91. }
  92. // If the player dont have immunity
  93. if(!g_HaveImmunity[id])
  94. {
  95. // Enable Godmode
  96. set_user_godmode(id, 1)
  97.  
  98. // Aura task
  99. set_task(0.1, "aura", id + TASK_AURA, _, _, "b")
  100.  
  101. g_HaveImmunity[id] = true
  102.  
  103. // If you want use the item all round
  104. #if defined ALLROUND
  105. set_hudmessage(85, 127, 255, -1.0, 0.15, 1, 0.1, 3.0, 0.05, 0.05, -1)
  106. ShowSyncHudMsg(id, g_HudSync, "%L", id, "IMMUME")
  107.  
  108. #else
  109. // Start the countdown !
  110. Time[id] = get_pcvar_num(cvar_duration)
  111. CountDown(id)
  112.  
  113. #endif
  114. }
  115.  
  116. // If the player already have immunity
  117. else
  118. {
  119. new Temp[32]
  120. formatex(Temp, 31, "!g[ZP] !y%L", id, "ALREADY")
  121. chat_color(id, Temp)
  122. zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + ITEM_COST)
  123.  
  124. return
  125. }
  126.  
  127. }
  128. }
  129.  
  130. // Countdown code
  131. public CountDown(id)
  132. {
  133. // If time is 0 or -1
  134. if(Time[id] <= 0)
  135. {
  136. // Remove aura task
  137. remove_task(id + TASK_AURA)
  138.  
  139. // Client_Print
  140. client_print(id, print_center, "%L", id, "EXPIRED")
  141.  
  142. // Disable godmode
  143. set_user_godmode(id, 0)
  144.  
  145. // The player dont have immunity
  146. g_HaveImmunity[id] = false
  147.  
  148. // Remove countdown
  149. return
  150. }
  151.  
  152. // Time - 1
  153. Time[id]--
  154.  
  155. // Show the immunity seconds
  156. set_hudmessage(85, 127, 255, -1.0, 0.15, 1, 0.1, 3.0, 0.05, 0.05, -1)
  157. ShowSyncHudMsg(id, g_HudSync, "%L", id, "REMAINING", Time[id])
  158.  
  159. // Repeat
  160. set_task(1.0, "CountDown", id)
  161. }
  162.  
  163.  
  164.  
  165. // If user is infected (Infection nade)
  166. public zp_user_infected_post(id)
  167. {
  168. if(g_HaveImmunity[id])
  169. {
  170. #if !defined ALLROUND
  171. // Remove countdown task
  172. Time[id] = 0
  173. #endif
  174.  
  175. // Remove aura task
  176. remove_task(id + TASK_AURA)
  177.  
  178. // The player dont have immunity
  179. g_HaveImmunity[id] = false
  180.  
  181. // Disable godmode
  182. set_user_godmode(id, 0)
  183. }
  184. }
  185.  
  186.  
  187. // At player spawn
  188. public fw_PlayerSpawn_Post(id)
  189. {
  190. if(g_HaveImmunity[id])
  191. {
  192. #if !defined ALLROUND
  193. // Remove countdown task
  194. Time[id] = 0
  195.  
  196. #else
  197.  
  198. // If allround is uncommented show a message.
  199. client_print(id, print_center, "%L", id, "EXPIRED")
  200. #endif
  201.  
  202. // Remove aura task
  203. remove_task(id + TASK_AURA)
  204.  
  205. // Disable godmode
  206. set_user_godmode(id, 0)
  207.  
  208. // Remove immunity
  209. g_HaveImmunity[id] = false
  210. }
  211. }
  212.  
  213.  
  214.  
  215. /*============
  216. Aura Code
  217. ============*/
  218.  
  219. public aura(id)
  220. {
  221. id -= TASK_AURA
  222.  
  223.  
  224. // If user die
  225. if (!is_user_alive(id))
  226. return
  227.  
  228. // Color cvar ---> RGB!
  229. new szColors[16]
  230. get_pcvar_string(cvar_auracolor, szColors, 15)
  231.  
  232. new gRed[4], gGreen[4], gBlue[4], iRed, iGreen, iBlue
  233. parse(szColors, gRed, 3, gGreen, 3, gBlue, 3)
  234.  
  235. iRed = clamp(str_to_num(gRed), 0, 255)
  236. iGreen = clamp(str_to_num(gGreen), 0, 255)
  237. iBlue = clamp(str_to_num(gBlue), 0, 255)
  238.  
  239. new Origin[3]
  240. get_user_origin(id, Origin)
  241.  
  242. message_begin(MSG_ALL, SVC_TEMPENTITY)
  243. write_byte(TE_DLIGHT)
  244. write_coord(Origin[0])
  245. write_coord(Origin[1])
  246. write_coord(Origin[2])
  247. write_byte(get_pcvar_num(cvar_aurasize))
  248. write_byte(iRed) // R
  249. write_byte(iGreen) // G
  250. write_byte(iBlue) // B
  251. write_byte(2)
  252. write_byte(0)
  253. message_end()
  254. }
  255.  
  256.  
  257. /*===============
  258. ColorChat Stock
  259. ===============*/
  260.  
  261. stock chat_color(const id, const input[], any:...)
  262. {
  263. static msg[191], iSayText
  264. vformat(msg, 190, input, 3)
  265.  
  266. if( !iSayText ) iSayText = get_user_msgid("SayText");
  267.  
  268. replace_all(msg, 190, "!g", "^4")
  269. replace_all(msg, 190, "!y", "^1")
  270.  
  271.  
  272. message_begin(id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, iSayText, _, id ? id : find_player("j") )
  273. write_byte(id ? id : find_player("j") )
  274. write_string(msg)
  275. message_end()
  276. }
  277.