Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1.  
  2. local function GetRandomPositionInBox( mins, maxs, ang )
  3. return ang:Up() * math.random( mins.z, maxs.z ) + ang:Right() * math.random( mins.y, maxs.y ) + ang:Forward() * math.random( mins.x, maxs.x )
  4. end
  5.  
  6. local function GenerateLighting( from, to, deviations, power )
  7. local start = from
  8. if ( isentity( start ) ) then start = from:GetPos() end
  9. local endpos = to:GetPos()
  10. endpos = endpos + GetRandomPositionInBox( to:OBBMins(), to:OBBMaxs(), to:GetAngles() )
  11.  
  12. local right = (start - endpos):Angle():Right()
  13. local up = (start - endpos):Angle():Up()
  14. local segments = {
  15. { start, endpos }
  16. }
  17. for i = 0, power do
  18. local newsegs = {}
  19. for id, seg in pairs( segments ) do
  20. local mid = Vector( (seg[1].x + seg[2].x) / 2, (seg[1].y + seg[2].y) / 2, (seg[1].z + seg[2].z) / 2 )
  21. local offsetpos = mid + right * math.random( -deviations, deviations ) + up * math.random( -deviations, deviations )
  22. table.insert( newsegs, {seg[1], offsetpos} )
  23. table.insert( newsegs, {offsetpos, seg[2]} )
  24. end
  25. segments = newsegs
  26. end
  27. return segments
  28. end
  29.  
  30. local function GenerateLightingSegs( from, to, deviations, segs )
  31. local start = from
  32. if ( isentity( start ) ) then start = from:GetPos() end
  33. local endpos = to:GetPos()
  34. endpos = endpos + GetRandomPositionInBox( to:OBBMins(), to:OBBMaxs(), to:GetAngles() )
  35.  
  36. local right = (start - endpos):Angle():Right()
  37. local up = (start - endpos):Angle():Up()
  38. local fwd = (start - endpos):Angle():Forward()
  39. local step = (1 / segs) * start:Distance( endpos )
  40.  
  41. local lastpos = start
  42. local segments = {}
  43. for i = 1, segs do
  44. local a = lastpos - fwd * step
  45. table.insert( segments, { lastpos, a } )
  46. lastpos = a
  47. end
  48.  
  49. for k, v in pairs( segments ) do
  50. if ( k == 1 || k == #segments ) then continue end
  51.  
  52. segments[ k ][ 1 ] = segments[ k ][ 1 ] + right * math.random( -deviations, deviations ) + up * math.random( -deviations, deviations )
  53. segments[ k - 1 ][ 2 ] = segments[ k ][ 1 ]
  54. end
  55.  
  56. for k, v in pairs( segments ) do
  57. if ( k == 1 || k == #segments ) then continue end
  58.  
  59. if ( math.random( 0, 100 ) > 75 ) then
  60. local dir = AngleRand():Forward()
  61. table.insert( segments, { segments[ k ][ 1 ], segments[ k ][ 1 ] + dir * ( step * math.Rand( 0.2, 0.6 ) ) } )
  62. end
  63. end
  64.  
  65. return segments
  66. end
  67.  
  68. local mats = {
  69. (Material( "cable/blue_elec" )),
  70. }
  71.  
  72. local mats2 = {
  73. (Material( "cable/hydra" )),
  74. }
  75.  
  76. local segments = {}
  77.  
  78. local tiem = .2
  79. hook.Add( "PostDrawTranslucentRenderables", "", function()
  80. for id, t in pairs( segments ) do
  81. if ( t.time < CurTime() ) then table.remove( segments, id ) continue end
  82. render.SetMaterial( t.mat )
  83. for id, seg in pairs( t.segs ) do
  84. render.DrawBeam( seg[1], seg[2], ( math.max( t.startpos:Distance( t.endpos ) - seg[1]:Distance( t.endpos ), 20) / ( t.startpos:Distance( t.endpos ) ) * t.w ) * ( (t.time - CurTime() ) / tiem ), 0, seg[1]:Distance( seg[2] ) / 25, Color( 255, 255, 255 ) )
  85. end
  86. end
  87. end )
  88.  
  89. function EFFECT:Init( data )
  90. local pos = data:GetOrigin()
  91. local ent = data:GetEntity()
  92. local fac = data:GetDamageType()
  93. if ( !IsValid( ent ) ) then return end
  94. if fac == DMG_FALL then
  95. mat_tbl = mats
  96. else
  97. mat_tbl = mats2
  98. end
  99. table.insert( segments, {
  100. segs = GenerateLightingSegs( pos, ent, math.random( 10, 20 ), pos:Distance( ent:GetPos() ) / 48 ), --math.random( 5, 10 ) ),
  101. mat = table.Random( mat_tbl ),
  102. time = CurTime() + tiem,
  103. w = math.random( 20, 50 ),
  104. startpos = pos,
  105. endpos = ent:GetPos()
  106. } )
  107. end
  108.  
  109. function EFFECT:Think()
  110. return false
  111. end
  112.  
  113.  
  114.  
  115. function EFFECT:Render()
  116.  
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement