HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <hamsandwich>
  4.  
  5. #define GLOWSTICK_CLASSNAME "glowstick"
  6.  
  7. #define Maximum "Elértétek a maximális Fénypálca számot!"
  8. #define Nincs "Nincs egy Fénypálcád sem!"
  9.  
  10. const PEV_FLARE_COLOR = pev_punchangle
  11. new const sound_grenade_flare_explode[] = { "items/nvg_on.wav" }
  12.  
  13. new g_radius_light = 6, g_frequency = 15, g_duration = 60, g_round_sticks = 4, g_limit = 64
  14. new cv_radius_light, cv_frequency, cv_duration, cv_round_sticks, cv_limit
  15.  
  16. new active_sticks
  17.  
  18. ///// ///// ///// /////
  19.  
  20. new i_glowsticks[33]
  21.  
  22. new bool:g_is_alive[33]
  23. new user_weapon[33]
  24.  
  25. ///// ///// ///// ///// ///// ///// ///// ///// /////
  26.  
  27. new g_model_glowstick[][] =
  28. {
  29. "models/glowstick/glowstick01.mdl",
  30. "models/glowstick/glowstick02.mdl",
  31. "models/glowstick/glowstick03.mdl",
  32. "models/glowstick/glowstick04.mdl"
  33. }
  34.  
  35. public plugin_precache()
  36. {
  37. precache_model(g_model_glowstick[0])
  38. precache_model(g_model_glowstick[1])
  39. precache_model(g_model_glowstick[2])
  40. precache_model(g_model_glowstick[3])
  41.  
  42. precache_sound(sound_grenade_flare_explode)
  43. }
  44.  
  45. ///// ///// ///// ///// ///// ///// ///// ///// /////
  46.  
  47. public plugin_init()
  48. {
  49. register_plugin("Glowsticks", "1.02", "Leo_[BH]")
  50.  
  51.  
  52.  
  53. register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
  54. register_event("CurWeapon","CurWeapon","be","1=1")
  55. register_forward(FM_PlayerPreThink, "fw_clientPreThink", 0)
  56. RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
  57. RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
  58.  
  59. cv_radius_light = register_cvar("glowsticks_radius_light", "6")
  60. cv_frequency = register_cvar("glowsticks_frequency", "15")
  61. cv_duration = register_cvar("glowsticks_duration", "60")
  62. cv_round_sticks = register_cvar("glowsticks_round_limit", "4")
  63. cv_limit = register_cvar("glowsticks_map_limit", "64")
  64.  
  65.  
  66. }
  67.  
  68. public plugin_cfg()
  69. {
  70. server_cmd("exec addons/amxmodx/configs/glowsticks.cfg")
  71. reload_cvars()
  72. }
  73.  
  74. public reload_cvars()
  75. {
  76. g_radius_light = get_pcvar_num(cv_radius_light)
  77. g_frequency = get_pcvar_num(cv_frequency)
  78. g_duration = get_pcvar_num(cv_duration)
  79. g_round_sticks = get_pcvar_num(cv_round_sticks)
  80. g_limit = get_pcvar_num(cv_limit)
  81.  
  82. if(g_duration < g_frequency * 2)
  83. {
  84. g_duration = g_frequency * 2
  85. }
  86. }
  87.  
  88. public fw_clientPreThink(id)
  89. {
  90. if(!g_is_alive[id]) return;
  91. if(user_weapon[id] != CSW_KNIFE) return;
  92.  
  93. if(pev(id, pev_button) & IN_RELOAD)
  94. {
  95. if(!(pev(id, pev_oldbuttons) & IN_RELOAD))
  96. {
  97. cmd_place_glowstick(id)
  98. }
  99. }
  100. }
  101.  
  102. public cmd_place_glowstick(id)
  103. {
  104. if(active_sticks > g_limit)
  105. {
  106. client_print(id, print_center, "%s",Maximum)
  107. }
  108. else
  109. {
  110. if(i_glowsticks[id])
  111. {
  112. the_place_glowstick(id)
  113. i_glowsticks[id]--
  114. }
  115. else
  116. {
  117. client_print(id, print_center, "%s",Nincs)
  118. }
  119. }
  120. }
  121.  
  122. public the_place_glowstick(id)
  123. {
  124. place_glowstick(id, random_num(1, 4))
  125. }
  126.  
  127. ///// ///// ///// ///// ///// ///// ///// ///// /////
  128.  
  129. public place_glowstick(id, color)
  130. {
  131. static entity;
  132. entity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  133. set_pev(entity, pev_classname, GLOWSTICK_CLASSNAME)
  134.  
  135. engfunc(EngFunc_SetModel, entity, g_model_glowstick[color-1])
  136. set_pev(entity, pev_mins, Float:{ -0.660000, -0.660000, 0.000000 } )
  137. set_pev(entity, pev_maxs, Float:{ 0.660000, 0.660000, 10.170000 } )
  138. set_pev(entity, pev_size, Float:{ -0.660000, -0.660000, 0.000000, 0.660000, 0.660000, 10.170000 } )
  139.  
  140. set_pev(entity, pev_solid, SOLID_TRIGGER)
  141. set_pev(entity, pev_movetype, MOVETYPE_TOSS)
  142.  
  143. // // // // //
  144.  
  145. static rgb[3]
  146.  
  147. switch(color)
  148. {
  149. case 1: // green
  150. {
  151. rgb[0] = 28
  152. rgb[1] = 211
  153. rgb[2] = 45
  154. }
  155. case 2: // red
  156. {
  157. rgb[0] = 204
  158. rgb[1] = 27
  159. rgb[2] = 26
  160. }
  161. case 3: // blue
  162. {
  163. rgb[0] = 25
  164. rgb[1] = 71
  165. rgb[2] = 200
  166. }
  167. case 4: // orange
  168. {
  169. rgb[0] = 195
  170. rgb[1] = 108
  171. rgb[2] = 25
  172. }
  173. }
  174.  
  175. set_pev(entity, PEV_FLARE_COLOR, rgb)
  176.  
  177. static Float:my_origin[3], Float:my_angles[3]
  178. pev(id, pev_origin, my_origin)
  179. pev(id, pev_angles, my_angles)
  180. set_pev(entity, pev_origin, my_origin)
  181. my_angles[0] = 0.0
  182. set_pev(entity, pev_angles, my_angles)
  183.  
  184. set_task(1.5, "activate_stick", entity)
  185.  
  186. active_sticks++
  187. }
  188.  
  189. public activate_stick(entity)
  190. {
  191. if(pev_valid(entity))
  192. {
  193. static Float:origin[3]
  194. pev(entity, pev_origin, origin)
  195.  
  196. engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
  197. write_byte(TE_SPARKS) // TE id
  198. engfunc(EngFunc_WriteCoord, origin[0]) // x
  199. engfunc(EngFunc_WriteCoord, origin[1]) // y
  200. engfunc(EngFunc_WriteCoord, origin[2]) // z
  201. message_end()
  202.  
  203. emit_sound(entity, CHAN_WEAPON, sound_grenade_flare_explode, 1.0, ATTN_NORM, 0, PITCH_NORM)
  204.  
  205. flare_lighting(entity)
  206.  
  207. set_task(float(g_frequency), "flare_lighting", entity, _, _, "a", g_duration / g_frequency - 1)
  208. set_task(float(g_duration), "last_light", entity)
  209. set_task(float(g_duration) + float(g_frequency / 3), "remove_glowstick", entity)
  210. }
  211.  
  212. }
  213.  
  214. public flare_lighting(entity)
  215. {
  216. if(!pev_valid(entity)) return;
  217.  
  218. static Float:origin[3], color[3]
  219. pev(entity, pev_origin, origin)
  220. pev(entity, PEV_FLARE_COLOR, color)
  221.  
  222. engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, origin, 0)
  223. write_byte(TE_DLIGHT) // TE id
  224. engfunc(EngFunc_WriteCoord, origin[0]) // x
  225. engfunc(EngFunc_WriteCoord, origin[1]) // y
  226. engfunc(EngFunc_WriteCoord, origin[2]) // z
  227. write_byte(g_radius_light) // radius
  228. write_byte(color[0]) // r
  229. write_byte(color[1]) // g
  230. write_byte(color[2]) // b
  231. write_byte(g_frequency * 10) // life //
  232. write_byte(0) // decay rate
  233. message_end()
  234. }
  235.  
  236. public last_light(entity)
  237. {
  238. if(!pev_valid(entity)) return;
  239.  
  240. static Float:origin[3], color[3]
  241. pev(entity, pev_origin, origin)
  242. pev(entity, PEV_FLARE_COLOR, color)
  243.  
  244. engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, origin, 0)
  245. write_byte(TE_DLIGHT) // TE id
  246. engfunc(EngFunc_WriteCoord, origin[0]) // x
  247. engfunc(EngFunc_WriteCoord, origin[1]) // y
  248. engfunc(EngFunc_WriteCoord, origin[2]) // z
  249. write_byte(g_radius_light) // radius
  250. write_byte(color[0]) // r
  251. write_byte(color[1]) // g
  252. write_byte(color[2]) // b
  253. write_byte(g_frequency) // life
  254. write_byte(3) // decay rate
  255. message_end()
  256. }
  257.  
  258. public remove_glowstick(entity)
  259. {
  260. if(!pev_valid(entity)) return;
  261. engfunc(EngFunc_RemoveEntity, entity)
  262. active_sticks--
  263. }
  264.  
  265. ///// ///// ///// ///// ///// ///// ///// ///// /////
  266.  
  267. public event_round_start(id)
  268. {
  269.  
  270. reload_cvars()
  271. arrayset(i_glowsticks, g_round_sticks, 33)
  272. }
  273.  
  274.  
  275. public client_puinserver(id)
  276. {
  277. i_glowsticks[id] = g_round_sticks
  278. }
  279.  
  280. public client_disconnect(id)
  281. {
  282. i_glowsticks[id] = 0
  283. user_weapon[id] = 0
  284. g_is_alive[id] = false
  285. }
  286.  
  287. public CurWeapon(id)
  288. {
  289. user_weapon[id] = read_data(2)
  290. }
  291.  
  292. public fw_PlayerSpawn_Post(id)
  293. {
  294. if(is_user_alive(id))
  295. {
  296. g_is_alive[id] = true
  297. }
  298. }
  299.  
  300. public fw_PlayerKilled(id)
  301. {
  302. g_is_alive[id] = false
  303. }
  304.  
  305. ///// ///// ///// ///// ///// ///// ///// ///// /////
  306.  
  307. public plugin_natives()
  308. {
  309. register_native("glowstick", "native_glowstick", 1)
  310. }
  311.  
  312. public native_glowstick(id)
  313. {
  314. if(active_sticks > g_limit) return 0
  315. if(!g_is_alive[id]) return 0
  316.  
  317. the_place_glowstick(id)
  318.  
  319. return 1
  320. }
  321.