Advertisement
Bolodefchoco_LUAXML

[Script] Lightning

Dec 17th, 2016
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 17/12/2016
  3. --Last update: 17/12/2016
  4. --[[ Notes:
  5.     Does:
  6.         Invoca efeitos especiais semelhantes a raios
  7. ]]--
  8.  
  9. math.angle = function(x1,y1,x2,y2)
  10.     return math.atan2(y2-y1,x2-x1)
  11. end
  12. math.dist = function(x1,y1,x2,y2)
  13.     return (math.abs(x1-x2)^2 + math.abs(y1-y2)^2)^.5
  14. end
  15. table.random = function(x)
  16.     return x[math.random(#x)]
  17. end
  18.  
  19. draw = {}
  20.  
  21. draw.line = function(x1,y1,x2,y2,id)
  22.     local dist = math.dist(x1,y1,x2,y2)
  23.     local ang = math.angle(x1,y1,x2,y2)
  24.     for i = 0,math.floor(dist/7) do
  25.         local x = x1 + math.cos(ang) * (i * 7)
  26.         local y = y1 + math.sin(ang) * (i * 7)
  27.         tfm.exec.displayParticle(id,x,y,math.random() * ((3/10)/2),math.random() * ((3/10)/2))
  28.     end
  29. end
  30.  
  31. draw.ray = function(x1,y1,x2,y2)
  32.     local particles = table.random({0,1,2,9})
  33.     local dist = math.dist(x1,y1,x2,y2)
  34.     local ang = math.angle(x1,y1,x2,y2)
  35.     local randDist = function()
  36.         return math.random() * 25 + 25
  37.     end
  38.     local randAng = function()
  39.         return math.pi/(math.random() * 450 + 40)
  40.     end
  41.  
  42.     local w = {{x1,y1}}
  43.  
  44.     local t = 0
  45.     local randAngle = randAng() * ((dist - t)/70)
  46.     local z = table.random({-1,1})
  47.     local v = ang + randAngle * z
  48.  
  49.     local randDistance = randDist()
  50.     while randDistance < dist-t do
  51.         t = t + randDistance
  52.         local x = x1 + math.cos(v) * t
  53.         local y = y1 + math.sin(v) * t
  54.         w[#w+1] = {x,y}
  55.  
  56.         randDistance = randDist()
  57.         randAngle = randAng() * ((dist - t)/70)
  58.         z = z * -1
  59.         v = ang + randAngle * z
  60.     end
  61.    
  62.     w[#w+1] = {x2,y2}
  63.  
  64.     for i = 1,#w - 1 do
  65.         local w1 = w[i]
  66.         local w2 = w[i+1]
  67.         draw.line(w1[1],w1[2],w2[1],w2[2],particles)
  68.     end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement