HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2.   Fordította: BBk - Death of Legend
  3. */
  4.  
  5. #include <amxmodx>
  6. #include <fakemeta>
  7.  
  8. new const Version[] = "1.0.1"
  9.  
  10. new MsgScreenFade, MsgScreenShake
  11. new FLenable, FLcolor, FLradius, FLlightcolor, FLsound
  12.  
  13. new const Sound[] = "sound/ultrasound.mp3"
  14.  
  15. public plugin_precache() {
  16. FLsound = register_cvar("amx_rfl_sound", "1")
  17.  
  18. if(get_pcvar_num(FLsound))
  19. precache_generic(Sound)
  20. }
  21.  
  22. public plugin_init()
  23. {
  24. register_plugin("Realistic FlashBang", Version, "GlaDiuS")
  25.  
  26. FLenable = register_cvar("amx_rfl_enable", "1")
  27. FLcolor = register_cvar("amx_rfl_color", "128 128 128")
  28. FLradius = register_cvar("amx_rfl_radius","50")
  29. FLlightcolor = register_cvar("amx_rfl_lightcolor","255 255 255")
  30.  
  31. register_event("ScreenFade","FlashEvent","b","4=255","5=255","6=255","7>199")
  32. register_forward(FM_EmitSound,"fw_emitsound")
  33.  
  34. MsgScreenFade = get_user_msgid("ScreenFade")
  35. MsgScreenShake = get_user_msgid("ScreenShake");
  36. }
  37.  
  38. public FlashEvent(id)
  39. {
  40. if(!get_pcvar_num(FLenable))
  41. return
  42.  
  43. // get color
  44. new Colores[12], rgb[3][4], Red, Green, Blue
  45. get_pcvar_string(FLcolor, Colores, charsmax(Colores))
  46. parse(Colores, rgb[0], 3, rgb[1], 3, rgb[2], 3)
  47. Red = clamp(str_to_num(rgb[0]), 0, 255)
  48. Green = clamp(str_to_num(rgb[1]), 0, 255)
  49. Blue = clamp(str_to_num(rgb[2]), 0, 255)
  50.  
  51. new Duration, HoldTime, Fade, Alpha
  52. Duration = read_data(1)
  53. HoldTime = read_data(2)
  54. Fade = read_data(3)
  55. Alpha = read_data(7)
  56.  
  57. message_begin(MSG_ONE, MsgScreenFade, {0,0,0}, id)
  58. write_short(Duration) // Duration
  59. write_short(HoldTime) // Hold time
  60. write_short(Fade) // Fade type
  61. write_byte(Red) // Red
  62. write_byte(Green) // Green
  63. write_byte(Blue) // Blue
  64. write_byte(Alpha) // Alpha
  65. message_end()
  66.  
  67. set_pev(id, pev_punchangle, Float:{125.0, 125.0, 125.0})
  68.  
  69. if(get_pcvar_num(FLsound)) {
  70. client_cmd(id, "mp3 play %s", Sound)
  71. set_task(8.0, "stoppedsound", id)
  72. }
  73.  
  74. set_task(3.0, "Shake", id)
  75. }
  76.  
  77. public Shake(id)
  78. {
  79. new Dura = UTIL_FixedUnsigned16(4.0, 1 << 12)
  80. new Freq = UTIL_FixedUnsigned16(0.7 , 1 << 8)
  81. new Ampl = UTIL_FixedUnsigned16(20.0, 1 << 12)
  82.  
  83. message_begin(MSG_ONE , MsgScreenShake , {0,0,0} ,id)
  84. write_short( Ampl ) // --| Shake amount.
  85. write_short( Dura ) // --| Shake lasts this long.
  86. write_short( Freq ) // --| Shake noise frequency.
  87. message_end ()
  88. }
  89.  
  90. public stoppedsound(id)
  91. client_cmd(id, "mp3 stop %s", Sound)
  92.  
  93. public fw_emitsound(entity,channel,const sample[],Float:volume,Float:attenuation,fFlags,pitch)
  94. {
  95. if(!get_pcvar_num(FLenable))
  96. return FMRES_IGNORED
  97.  
  98. // not a flashbang exploding
  99. if(!equali(sample,"weapons/flashbang-1.wav") && !equali(sample,"weapons/flashbang-2.wav"))
  100. return FMRES_IGNORED
  101.  
  102. // light effect
  103. flashbang_explode(entity)
  104.  
  105. return FMRES_IGNORED
  106. }
  107.  
  108. public flashbang_explode(greindex)
  109. {
  110. if(!pev_valid(greindex))
  111. return
  112.  
  113. // get origin of explosion
  114. new Float:origin[3]
  115. pev(greindex, pev_origin, origin)
  116.  
  117. // get color
  118. new Colores[12], rgb[3][4], Red, Green, Blue
  119. get_pcvar_string(FLlightcolor, Colores, charsmax(Colores))
  120. parse(Colores, rgb[0], 3, rgb[1], 3, rgb[2], 3)
  121. Red = clamp(str_to_num(rgb[0]), 0, 255)
  122. Green = clamp(str_to_num(rgb[1]), 0, 255)
  123. Blue = clamp(str_to_num(rgb[2]), 0, 255)
  124.  
  125. message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
  126. write_byte(TE_DLIGHT) // 27
  127. write_coord(floatround(origin[0])) // x
  128. write_coord(floatround(origin[1])) // y
  129. write_coord(floatround(origin[2])) // z
  130. write_byte(get_pcvar_num(FLradius)) // radius
  131. write_byte(Red) // Red
  132. write_byte(Green) // Green
  133. write_byte(Blue) // Blue
  134. write_byte(8) // life
  135. write_byte(60) // decay rate
  136. message_end()
  137. }
  138.  
  139. UTIL_FixedUnsigned16 ( const Float:Value, const Scale ) {
  140. return clamp( floatround( Value * Scale ), 0, 0xFFFF );
  141. }
  142.