Dark_EccentricYT

Untitled

Jul 25th, 2017
5,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. local host = game:service'Players'.LocalPlayer;
  2. local cache = {};
  3.  
  4. --// Setup
  5.  
  6. local ArtificialHB = Instance.new('BindableEvent')
  7. ArtificialHB.Name = 'Heartbeat'
  8.  
  9. delay_per_second,tf,allowframeloss,allowframeloss,lastframe = 130,0,false,false,tick()
  10. tossremainder = false
  11. frame = 1 / delay_per_second
  12.  
  13. game:GetService("RunService").Heartbeat:connect(function(s, p)
  14. tf = tf + s
  15. if tf >= frame then
  16. if allowframeloss then
  17. ArtificialHB:Fire()
  18. lastframe = tick()
  19. else
  20. for i = 1, math.floor(tf / frame) do
  21. ArtificialHB:Fire()
  22. end
  23. lastframe = tick()
  24. end
  25. if tossremainder then
  26. tf = 0
  27. else
  28. tf = tf - frame * math.floor(tf / frame)
  29. end
  30. end
  31. end)
  32.  
  33. --// Cache
  34. cache['mouse'] = host:GetMouse();
  35. cache['hb'] = ArtificialHB;
  36. cache['assets'] = Instance.new('Folder', host.Character);
  37. cache['storage'] = Instance.new('Folder', cache['assets']);
  38. cache['preview'] = Instance.new('Folder', cache['assets']);
  39. cache['points'] = {};
  40. cache['segments'] = {};
  41. cache['settings'] = {
  42. Wrap = {Value = false, Description = 'Wrap to the beginning from the end when generating plot segments'};
  43. Width = {Value = .2, Description = 'The width of the segment as a whole'};
  44. LerpSpeed = {Value = .05, Description = 'The speed of the 3D cursor {0 to 1}'};
  45. Preview = {Value = true, Description = 'While plotting a segment, do you want there to be a preview of how it will turn out?'};
  46. };
  47.  
  48. function cache:swait(num)
  49. if num == 0 or num == nil then
  50. ArtificialHB.Event:wait()
  51. else
  52. for i = 0, num+2 do
  53. ArtificialHB.Event:wait()
  54. end
  55. end
  56. end
  57.  
  58. function cache:ni(name,prnt)
  59. return Instance.new(tostring(name),prnt)
  60. end
  61.  
  62. function cache:new(type, prnt, others)
  63. if not prnt then prnt = workspace end
  64. local new = cache:ni(type)
  65. if new:IsA'BasePart' then
  66. new.Anchored = true
  67. new.Size = Vector3.new(1,1,1)
  68. new.Color = Color3.new(1,1,1)
  69. new.CanCollide = false
  70. new.Material = 'SmoothPlastic'
  71. new.TopSurface = 10
  72. new.BottomSurface = 10
  73. new.LeftSurface = 10
  74. new.RightSurface = 10
  75. new.FrontSurface = 10
  76. new.BackSurface = 10
  77. end
  78. for i,v in next, others do
  79. local suc,err = pcall(function()
  80. new[i] = v
  81. end)
  82. if not suc then
  83. print(err)
  84. end
  85. end
  86. new.Parent = prnt
  87. return new
  88. end
  89.  
  90. function cache:cylinder(prnt, cf)
  91. return cache:new('Part', prnt,{
  92. Shape = 'Cylinder',
  93. Size = Vector3.new(.4,.4,.4),
  94. CFrame = cf,
  95. });
  96. end
  97.  
  98. function cache:part(prnt, cf)
  99. return cache:new('Part', prnt,{
  100. Size = Vector3.new(.4,.4,.4),
  101. CFrame = cf,
  102. });
  103. end
  104.  
  105. function cache:plot(cf)
  106. local plot = cache:cylinder(cache['storage'], CFrame.new(cf.p)*CFrame.Angles(0,0,math.pi/2))
  107. cache.points[#cache.points+1] = plot
  108. end
  109.  
  110. function cache:generate(rate)
  111. local stuff = cache.points
  112. local last = stuff[1]
  113. if cache.settings.Wrap.Value == true then
  114. stuff[#stuff+1]=stuff[1]
  115. end
  116. for i, plot in next, stuff do
  117. cache:swait(rate or nil);
  118. if i >= 2 then
  119. local range = (last.CFrame.p - plot.CFrame.p)
  120. local distance = range.magnitude
  121. local base = cache:part(cache.storage, CFrame.new(last.CFrame.p, plot.CFrame.p))
  122. base.Size = Vector3.new(cache.settings.Width.Value,cache.settings.Width.Value,distance);
  123. base.CFrame = CFrame.new(last.CFrame.p,plot.CFrame.p) * CFrame.new(0,0,-distance/2);
  124. local edge = cache:cylinder(cache['storage'], CFrame.new(last.CFrame.p, plot.CFrame.p))
  125. edge.Size = Vector3.new(cache.settings.Width.Value,cache.settings.Width.Value,cache.settings.Width.Value)
  126. edge.CFrame = CFrame.new(last.CFrame.p,plot.CFrame.p) * CFrame.new(0,0,-distance) * CFrame.Angles(0,0,math.pi/2);
  127. plot.Transparency = 1
  128. last = plot
  129. else
  130. local edge = cache:cylinder(cache['storage'], CFrame.new(last.CFrame.p, plot.CFrame.p))
  131. edge.Size = Vector3.new(cache.settings.Width.Value,cache.settings.Width.Value,cache.settings.Width.Value)
  132. edge.CFrame = plot.CFrame * CFrame.new(0,0,distance);
  133. plot.Transparency = 1
  134. end
  135. end
  136. for i, plot in next, stuff do
  137. pcall(game.Destroy, plot)
  138. end
  139. points = {};
  140. end
  141.  
  142. local md, old = false, CFrame.new(0,9e9,0)
  143. local cur = cache.mouse.Hit
  144.  
  145. function cache:update()
  146. cache['follow'] = cache:cylinder(cache['assets'], CFrame.new(cache.mouse.Hit.p)*CFrame.Angles(0,0,math.pi/2))
  147. while true do
  148. cache['follow'].CFrame = cache['follow'].CFrame:lerp(CFrame.new(cache.mouse.Hit.p)*CFrame.Angles(0,0,math.pi/2), .1)
  149. for i, plot in next, cache.points do
  150. if plot.Parent == nil or plot == nil then
  151. table.remove(cache.points, index)
  152. end
  153. end
  154. cache:swait()
  155. end
  156. end
  157.  
  158. cache.mouse.Button1Down:connect(function()
  159. md = true
  160. cache['follow'].Transparency = .8
  161. while md do
  162. cur = cache.follow.CFrame
  163. local distance = (old.p - cur.p).magnitude
  164. if distance > cache.settings.Width.Value then
  165. cache:plot(cur)
  166. old = cur
  167. end
  168. cache:swait()
  169. end
  170. end)
  171.  
  172. cache.mouse.Button1Up:connect(function()
  173. cache['follow'].Transparency = 0
  174. md = false
  175. cache:generate()
  176. end)
  177.  
  178. cache.mouse.KeyDown:connect(function(key)
  179. if key == 'c' then
  180. local new = Instance.new('Folder',workspace.Terrain)
  181. game.Debris:AddItem(new, 20)
  182. for i,v in next, cache.storage:children() do
  183. v.Parent=new
  184. end
  185. cache.storage:ClearAllChildren()
  186. for i,v in next, new:children() do
  187. if v:IsA'BasePart' then
  188. spawn(function()
  189. delay((math.random()/(math.random()+.2)) / 10, function()
  190. for i = 0,1.025,.025 do
  191. v.Transparency=i
  192. cache:swait()
  193. end
  194. end)
  195. end)
  196. end
  197. end
  198. end
  199. end)
  200.  
  201. spawn(cache.update)
Add Comment
Please, Sign In to add comment