Advertisement
Guest User

Untitled

a guest
May 28th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1.  
  2. local shockDistance = 100 --Maximum distance, within which you will be effected.
  3. local maxShock = 30 --Maximum shocked you can be. Probably don't change this.
  4. local defaultFadeSpeed = 0.35 --Speed at which shock goes away.
  5. local minCrack = 1 --Minimum time between "crack" shots
  6.  
  7.  
  8.  
  9. if SERVER then
  10.  
  11. CreateConVar( "shell_fadespeed", defaultFadeSpeed, _, "How quickly should shellshock fade away?" )
  12. CreateConVar( "shell_enabled", 1, _, "Should shellshock be active?" )
  13.  
  14. util.AddNetworkString( "ShotAt" )
  15.  
  16. --Handles whether or not a player or NPC should be effected by a bullet
  17. hook.Add( "EntityFireBullets", "ShellshockGettingBullets", function( ent, data)
  18. if ( not IsValid( ent ) or not GetConVar( "shell_enabled" ):GetBool() ) then return end
  19. data.Callback = function( ply, tr, dmginfo )
  20.  
  21. --Handles players getting shot at
  22. for k,v in pairs( player.GetAll() ) do
  23. if v != ent then
  24. local dist = util.DistanceToLine( tr.StartPos, tr.HitPos, v:EyePos() )
  25. if dist <= shockDistance then
  26. local shock = math.Clamp( ( v:GetNWFloat( "ShellshockLevel", 0 ) + ( ( shockDistance - dist ) / shockDistance ) ) * ( 1 + dmginfo:GetDamage()/750 ), 0, maxShock )
  27. v:SetNWFloat( "ShellshockLevel", shock )
  28.  
  29. net.Start( "ShotAt" )
  30. net.Send( v )
  31.  
  32. v:ViewPunch( Angle( math.random( -1, 1 )/( ( maxShock + 1 ) - shock ), math.random( -1, 1 )/( ( maxShock + 1 ) - shock ), math.random( -1, 1 )/( ( maxShock + 1 ) - shock ) ) )
  33.  
  34. timer.Create( "Shellshock"..v:EntIndex(), 0.25, 0, function()
  35. if not IsValid( v ) then return end
  36. local shock = math.max( v:GetNWFloat( "ShellshockLevel", 0 ) - GetConVar( "shell_fadespeed" ):GetFloat(), 0 )
  37. v:SetNWFloat( "ShellshockLevel", shock )
  38.  
  39. end)
  40. end
  41. end
  42. end
  43. end
  44. return true
  45. end)
  46.  
  47. --Removes the effect on death
  48. hook.Add( "PlayerSpawn", "ShellshockReset", function( ply )
  49. ply:SetNWFloat( "ShellshockLevel", 0 )
  50. end)
  51. else
  52.  
  53. local nearMissSounds = {
  54. "weapons/fx/nearmiss/bulletLtoR03.wav",
  55. "weapons/fx/nearmiss/bulletLtoR04.wav",
  56. "weapons/fx/nearmiss/bulletLtoR05.wav",
  57. "weapons/fx/nearmiss/bulletLtoR06.wav",
  58. "weapons/fx/nearmiss/bulletLtoR07.wav",
  59. "weapons/fx/nearmiss/bulletLtoR09.wav",
  60. "weapons/fx/nearmiss/bulletLtoR10.wav",
  61. "weapons/fx/nearmiss/bulletLtoR11.wav",
  62. "weapons/fx/nearmiss/bulletLtoR12.wav",
  63. "weapons/fx/nearmiss/bulletLtoR13.wav",
  64. "weapons/fx/nearmiss/bulletLtoR14.wav"
  65. }
  66.  
  67. --Handles near miss sounds
  68. net.Receive( "ShotAt", function()
  69. if not IsValid( LocalPlayer() ) then return end
  70.  
  71. if not LocalPlayer().SuppressNearMiss then
  72. LocalPlayer():EmitSound( nearMissSounds[ math.random( 1, #nearMissSounds ) ], LocalPlayer():EyePos(), 180, 100, 1 )
  73. LocalPlayer().SuppressNearMiss = true
  74. timer.Simple( minCrack, function()
  75. if not IsValid( LocalPlayer() ) then return end
  76.  
  77. LocalPlayer().SuppressNearMiss = false
  78. end)
  79. end
  80. end)
  81.  
  82. --Draws the screen effects
  83. hook.Add( "RenderScreenspaceEffects", "ShellshockDrawEffects", function()
  84. if not IsValid( LocalPlayer() ) then return end
  85. local level = LocalPlayer():GetNWFloat( "ShellshockLevel", 0 )
  86.  
  87. if level > 0 then
  88. DrawSharpen( level, 0.25 )
  89. local tab = {
  90. [ "$pp_colour_addr" ] = 0,
  91. [ "$pp_colour_addg" ] = 0,
  92. [ "$pp_colour_addb" ] = 0,
  93. [ "$pp_colour_brightness" ] = 0,
  94. [ "$pp_colour_contrast" ] = 1,
  95. [ "$pp_colour_colour" ] = ( 1 - ( level/maxShock ) ),
  96. [ "$pp_colour_mulr" ] = 0,
  97. [ "$pp_colour_mulg" ] = 0.02,
  98. [ "$pp_colour_mulb" ] = 0
  99. }
  100. DrawColorModify( tab )
  101. end
  102.  
  103. end)
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement