Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.40 KB | None | 0 0
  1. --Draw2Life - Created By Vaeb
  2.  
  3. wait(1/30)
  4. script.Parent = nil
  5.  
  6. --Settings
  7. local Plrs = game:GetService("Players")
  8. local UIS = game:GetService("UserInputService")
  9. local Pathfinding = game:GetService("PathfindingService")
  10. local Light = game:GetService("Lighting")
  11. local RS = game:GetService("RunService")
  12. local Utils = assert(LoadLibrary("RbxUtility"))
  13. local LP = Plrs.LocalPlayer
  14. local MainPlr = "EvanU2007"
  15. local Mouse = LP:GetMouse()
  16. local Width = 3
  17. local Squares = 30
  18. local BottomLeft = Vector3.new(-((Squares*Width)/2), 10, 15)
  19. local BottomLeftBuild = Vector3.new(-((Squares*Width)/2), 10, 15+(Squares*Width)+5)
  20. local BaseY = nil
  21. local isDown = false
  22. local EDown = false
  23. local CDown = false
  24. local NumKeyDown = {}
  25. local Slabs = nil
  26. local GetXZ = "(%d+)Z(%d+)"
  27. local Cons = {}
  28. local StopAll = false
  29.  
  30. if LP.Name == MainPlr then
  31. Slabs = {}
  32. end
  33.  
  34. --Numbers
  35. local Numbers = {
  36. ["one"] = 1;
  37. ["two"] = 2;
  38. ["three"] = 3;
  39. ["four"] = 4;
  40. ["five"] = 5;
  41. ["six"] = 6;
  42. ["seven"] = 7;
  43. ["eight"] = 8;
  44. }
  45.  
  46. --Height
  47. local Levels = {
  48. [0] = Color3.new(0, 0, 0); --Black : 0
  49. [1] = Color3.new(1, 1, 1); --White : 1
  50. [2] = Color3.new(1, 0, 0); --Red : 2
  51. [3] = Color3.new(0, 1, 0); --Green : 3
  52. [4] = Color3.new(0, 0, 1); --Blue : 4
  53. [5] = Color3.new(1, 0, 1); --Pink : 5
  54. [6] = Color3.new(0, 1, 1); --Toothpaste : 6
  55. [7] = Color3.new(1, 1, 0); --Yellow : 7
  56. [8] = Color3.new(0.5, 0.35, 0.275); --Brown : 8
  57. }
  58.  
  59. local function QuaternionFromCFrame(cf)
  60. local mx, my, mz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cf:components();
  61. local trace = m00 + m11 + m22 if trace > 0 then
  62. local s = math.sqrt(1 + trace);
  63. local recip = 0.5/s;
  64. return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5;
  65. else
  66. local i = 0;
  67. if m11 > m00 then
  68. i = 1;
  69. end;
  70. if m22 > (i == 0 and m00 or m11) then
  71. i = 2 end if i == 0 then
  72. local s = math.sqrt(m00-m11-m22+1);
  73. local recip = 0.5/s return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip;
  74. elseif i == 1 then
  75. local s = math.sqrt(m11-m22-m00+1);
  76. local recip = 0.5/s;
  77. return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip ;
  78. elseif i == 2 then
  79. local s = math.sqrt(m22-m00-m11+1);
  80. local recip = 0.5/s;
  81. return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip;
  82. end;
  83. end;
  84. end;
  85.  
  86. local function QuaternionToCFrame(px, py, pz, x, y, z, w)
  87. local xs, ys, zs = x + x, y + y, z + z;
  88. local wx, wy, wz = w*xs, w*ys, w*zs;
  89. local xx = x*xs;
  90. local xy = x*ys;
  91. local xz = x*zs;
  92. local yy = y*ys;
  93. local yz = y*zs;
  94. local zz = z*zs;
  95. return CFrame.new(px, py, pz,1-(yy+zz), xy - wz, xz + wy,xy + wz, 1-(xx+zz), yz - wx, xz - wy, yz + wx, 1-(xx+yy))
  96. end;
  97.  
  98. local function QuaternionSlerp(a, b, t)
  99. local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4];
  100. local startInterp, finishInterp;
  101. if cosTheta >= 0.0001 then
  102. if (1 - cosTheta) > 0.0001 then
  103. local theta = math.acos(cosTheta);
  104. local invSinTheta = 1/math.sin(theta);
  105. startInterp = math.sin((1-t)*theta)*invSinTheta;
  106. finishInterp = math.sin(t*theta)*invSinTheta;
  107. else
  108. startInterp = 1-t finishInterp = t;
  109. end;
  110. else
  111. if (1+cosTheta) > 0.0001 then
  112. local theta = math.acos(-cosTheta);
  113. local invSinTheta = 1/math.sin(theta);
  114. startInterp = math.sin((t-1)*theta)*invSinTheta;
  115. finishInterp = math.sin(t*theta)*invSinTheta;
  116. else startInterp = t-1 finishInterp = t;
  117. end;
  118. end;
  119. return a[1]*startInterp + b[1]*finishInterp, a[2]*startInterp + b[2]*finishInterp, a[3]*startInterp + b[3]*finishInterp, a[4]*startInterp + b[4]*finishInterp;
  120. end;
  121.  
  122. function CLerp(a,b,t)
  123. local qa={QuaternionFromCFrame(a)};
  124. local qb={QuaternionFromCFrame(b)};
  125. local ax,ay,az=a.x,a.y,a.z;
  126. local bx,by,bz=b.x,b.y,b.z;
  127. local _t=1-t;
  128. return QuaternionToCFrame(_t*ax+t*bx,_t*ay+t*by,_t*az+t*bz,QuaternionSlerp(qa, qb, t));
  129. end
  130.  
  131. if LP.Name == MainPlr then
  132. --Make drawing pad
  133. for iZ = 0, Squares*Width, Width do --Y
  134. for iX = 0, Squares*Width, Width do --X
  135. local Part = Instance.new("Part", workspace)
  136. Part.Name = "Slab" .. "X" .. tostring(iX) .. "Z" .. tostring(iZ)
  137. Part.FormFactor = "Custom"
  138. if iZ == 0 and iX == (Squares/2)*Width then
  139. Part.Color = Levels[1]
  140. else
  141. Part.Color = Levels[0]
  142. end
  143. Part.Anchored = true
  144. Part.CanCollide = true
  145. Part.TopSurface = "Smooth"
  146. Part.BottomSurface = "Smooth"
  147. Part.Size = Vector3.new(Width, 0.05, Width)
  148.  
  149. --Find Base's Y Pos
  150. local EndPos = BottomLeft + Vector3.new(iX, 0, iZ)
  151. if BaseY == nil then
  152. local DownPos = EndPos - Vector3.new(0, 1, 0)
  153. local CheckRay = Ray.new(EndPos, (DownPos - EndPos).unit * 50)
  154. local Hit, HitPos = Workspace:FindPartOnRay(CheckRay, LP.Character)
  155. BaseY = HitPos.Y
  156. BottomLeftBuild = Vector3.new(BottomLeftBuild.X, BaseY, BottomLeftBuild.Z)
  157. end
  158.  
  159. Part.CFrame = CFrame.new(EndPos.X, BaseY + Part.Size.Y/2, EndPos.Z)
  160.  
  161. local Surface = Instance.new("SurfaceGui")
  162. Surface.Name = "Surface"
  163. Surface.Adornee = Part
  164. Surface.CanvasSize = Vector2.new(Width * 40, Width * 40)
  165. Surface.Enabled = false
  166. Surface.Face = "Top"
  167. Surface.Parent = Part
  168.  
  169. local Label = Instance.new("TextLabel", Surface)
  170. Label.Name = "Label"
  171. if iZ == 0 and iX == (Squares/2)*Width then
  172. Label.Text = "1"
  173. Surface.Enabled = true
  174. else
  175. Label.Text = "0"
  176. end
  177. Label.TextColor3 = Color3.new(0, 0, 0)
  178. Label.Font = "SourceSansBold"
  179. Label.FontSize = "Size48"
  180. Label.TextStrokeTransparency = 1
  181. Label.BackgroundTransparency = 1
  182. Label.Size = UDim2.new(1, 0, 1, 0)
  183. Label.Position = UDim2.new(0, 0, 0, 0)
  184.  
  185. if iZ == 0 and iX == (Squares/2)*Width then
  186. Slabs[Part] = {Level = 1, X = iX, Z = iZ, Stick = false}
  187. else
  188. Slabs[Part] = {Level = 0, X = iX, Z = iZ, Stick = false}
  189. end
  190.  
  191. local replacePart = Part:Clone()
  192.  
  193. local StringVal = Instance.new("StringValue")
  194. StringVal.Name = "SlabData"
  195. local JSONString = Utils.EncodeJSON(Slabs[Part])
  196. StringVal.Value = JSONString
  197. StringVal.Parent = Part
  198.  
  199. local Prot; Prot = function(Obj)
  200. local SlabDataVal = Obj["SlabData"]
  201. local Con1; Con1 = SlabDataVal.Changed:connect(function(Value) --Later move below
  202. if SlabDataVal.Parent ~= nil and SlabDataVal.Parent.Parent ~= nil and Slabs[SlabDataVal.Parent] then
  203. local Data = Utils.DecodeJSON(Value)
  204. Slabs[SlabDataVal.Parent] = Data
  205. else
  206. Con1:disconnect()
  207. end
  208. end)
  209. local Con2; Con2 = Obj.Changed:connect(function(P)
  210. if StopAll == true then
  211. Con2:disconnect()
  212. elseif P:lower() == "parent" then
  213. Con2:disconnect()
  214. local newClone = replacePart:Clone()
  215. Slabs[newClone] = Slabs[Obj]
  216. Slabs[newClone].Stick = Slabs[Obj].Stick
  217. Slabs[Obj] = nil
  218. pcall(function() Obj:Destroy() end)
  219. newClone.Parent = workspace
  220. if Slabs[newClone].Level ~= 0 then
  221. newClone.Surface.Label.Text = tostring(Slabs[newClone].Level)
  222. newClone.Surface.Enabled = true
  223. else
  224. newClone.Surface.Enabled = false
  225. newClone.Surface.Label.Text = "0"
  226. end
  227. if Slabs[newClone].Stick == true then
  228. newClone.Surface.Label.Text = newClone.Surface.Label.Text .. "X"
  229. end
  230. local StringVal = Instance.new("StringValue")
  231. StringVal.Name = "SlabData"
  232. local JSONString = Utils.EncodeJSON(Slabs[newClone])
  233. StringVal.Value = JSONString
  234. StringVal.Parent = newClone
  235. newClone.Color = Levels[Slabs[newClone].Level]
  236. Prot(newClone)
  237. end
  238. end)
  239. end
  240. Prot(Part)
  241. end
  242. end
  243. end
  244.  
  245. --[[table.insert(Cons, Mouse.Button1Up:connect(function()
  246. isDown = false
  247. end))
  248.  
  249. table.insert(Cons, Mouse.Button1Down:connect(function()
  250. isDown = true
  251. local LastTarg = nil
  252. repeat
  253. if Mouse.Target and Mouse.Target ~= LastTarg and Mouse.Target.Name:sub(1, 4) == "Slab" then
  254. local Part = Mouse.Target
  255. LastTarg = Part
  256. local Data = Utils.DecodeJSON(Part["SlabData"].Value)
  257. if Levels[Data.Level+1] then
  258. Data.Level = Data.Level + 1
  259. Part.Surface.Label.Text = tostring(Data.Level)
  260. Part.Surface.Enabled = true
  261. else
  262. Data.Level = 0
  263. Part.Surface.Enabled = false
  264. Part.Surface.Label.Text = "0"
  265. end
  266. if Data.Stick == true then
  267. Part.Surface.Label.Text = Part.Surface.Label.Text .. "X"
  268. end
  269. Part.Color = Levels[Data.Level]
  270. local StringVal = Part["SlabData"]
  271. local JSONString = Utils.EncodeJSON(Data)
  272. StringVal.Value = JSONString
  273. end
  274. wait(1/30)
  275. until isDown == false
  276. end))]]
  277.  
  278. table.insert(Cons, Mouse.KeyUp:connect(function(Key)
  279. if Key:lower() == "e" then
  280. EDown = false
  281. elseif Key:lower() == "c" then
  282. CDown = false
  283. elseif tonumber(Key) then
  284. NumKeyDown[tonumber(Key)] = nil
  285. end
  286. end))
  287.  
  288. table.insert(Cons, Mouse.KeyDown:connect(function(Key) --Make it so can change number based on KeyDown number
  289. if Key:lower() == "e" then
  290. EDown = true
  291. local LastTarg = nil
  292. repeat
  293. if Mouse.Target and Mouse.Target ~= LastTarg and Mouse.Target.Name:sub(1, 4) == "Slab" then
  294. local Part = Mouse.Target
  295. LastTarg = Part
  296. local Data = Utils.DecodeJSON(Part["SlabData"].Value)
  297. Data.Level = 0
  298. Data.Stick = false
  299. Part.Surface.Enabled = false
  300. Part.Surface.Label.Text = "0"
  301. Part.Color = Levels[Data.Level]
  302. local StringVal = Part["SlabData"]
  303. local JSONString = Utils.EncodeJSON(Data)
  304. StringVal.Value = JSONString
  305. end
  306. wait(1/30)
  307. until EDown == false
  308. elseif Key:lower() == "c" then
  309. CDown = true
  310. local LastTarg = nil
  311. repeat
  312. if Mouse.Target and Mouse.Target ~= LastTarg and Mouse.Target.Name:sub(1, 4) == "Slab" then
  313. local Part = Mouse.Target
  314. LastTarg = Part
  315. local Data = Utils.DecodeJSON(Part["SlabData"].Value)
  316. if Data.Stick == true then
  317. Data.Stick = false
  318. Part.Surface.Label.Text = tostring(Data.Level)
  319. elseif Data.Stick == false then
  320. Data.Stick = true
  321. Part.Surface.Label.Text = tostring(Data.Level) .. "X"
  322. end
  323. local StringVal = Part["SlabData"]
  324. local JSONString = Utils.EncodeJSON(Data)
  325. StringVal.Value = JSONString
  326. end
  327. wait(1/30)
  328. until CDown == false
  329. end
  330. end))
  331.  
  332. table.insert(Cons, UIS.InputBegan:connect(function(Input, Processed) --Watch out - Fires when chatting
  333. local Key = tostring(Input.KeyCode):lower()
  334. if #Key > 4 and Key:sub(1, 4) == "enum" then
  335. Key = Key:sub(14)
  336. end
  337. if Numbers[Key] then
  338. local Num = Numbers[Key]
  339. NumKeyDown[Num] = true
  340. local LastTarg = nil
  341. repeat
  342. if Mouse.Target and Mouse.Target ~= LastTarg and Mouse.Target.Name:sub(1, 4) == "Slab" then
  343. local Part = Mouse.Target
  344. LastTarg = Part
  345. local Data = Utils.DecodeJSON(Part["SlabData"].Value)
  346. Data.Level = Num
  347. if Data.Level ~= 0 then
  348. Part.Surface.Label.Text = tostring(Data.Level)
  349. Part.Surface.Enabled = true
  350. else
  351. Part.Surface.Enabled = false
  352. Part.Surface.Label.Text = tostring(Data.Level)
  353. end
  354. if Data.Stick == true then
  355. Part.Surface.Label.Text = tostring(Data.Level) .. "X"
  356. end
  357. Part.Color = Levels[Data.Level]
  358. local StringVal = Part["SlabData"]
  359. local JSONString = Utils.EncodeJSON(Data)
  360. StringVal.Value = JSONString
  361. end
  362. wait(1/30)
  363. until NumKeyDown[Num] == nil
  364. end
  365. end))
  366.  
  367. table.insert(Cons, UIS.InputEnded:connect(function(Input, Processed)
  368. local Key = tostring(Input.KeyCode):lower()
  369. if #Key > 4 and Key:sub(1, 4) == "enum" then
  370. Key = Key:sub(14)
  371. end
  372. if Numbers[Key] then
  373. local Num = Numbers[Key]
  374. NumKeyDown[Num] = nil
  375. end
  376. end))
  377.  
  378. table.insert(Cons, LP.Chatted:connect(function(Msg)
  379. if Msg:lower() == "end" then
  380. StopAll = true
  381. for i,v in pairs(Cons) do
  382. v:disconnect()
  383. end
  384. print("Ended")
  385. elseif Msg:lower() == "reset" then
  386. if LP.Name == MainPlr then
  387. local Slabs = {}
  388. for _,v in pairs(workspace:GetChildren()) do
  389. if v.Name:sub(1, 4) == "Slab" then
  390. Slabs[v] = Utils.DecodeJSON(v["SlabData"].Value)
  391. end
  392. end
  393. for i,v in pairs(Slabs) do
  394. local StringVal = i["SlabData"]
  395. local Data = nil
  396. if v.Z == 0 and v.X == (Squares/2)*Width then
  397. Data = {Level = 1, X = v.X, Z = v.Z, Stick = false}
  398. i.Color = Levels[1]
  399. i.Surface.Enabled = true
  400. i.Surface.Label.Text = "1"
  401. else
  402. Data = {Level = 0, X = v.X, Z = v.Z, Stick = false}
  403. i.Color = Levels[0]
  404. i.Surface.Enabled = false
  405. i.Surface.Label.Text = "0"
  406. end
  407. local JSONString = Utils.EncodeJSON(Data)
  408. StringVal.Value = JSONString
  409. end
  410. print("Reset")
  411. else
  412. print("Only " .. MainPlr .. " Can Use This Command")
  413. end
  414. elseif Msg:lower() == "build" and LP.Character and LP.Character.Parent and LP.Character:findFirstChild("Torso") then
  415. print("Building")
  416. local Slabs = {}
  417. for _,v in pairs(workspace:GetChildren()) do
  418. if v.Name:sub(1, 4) == "Slab" then
  419. Slabs[v] = Utils.DecodeJSON(v["SlabData"].Value)
  420. end
  421. end
  422. pcall(function() workspace["BuildingMod"]:Destroy() end)
  423. local BuildingMod = Instance.new("Model", workspace)
  424. BuildingMod.Name = "BuildingMod"
  425. local Builders = {}
  426. local NumSlabs = 0
  427. for i,v in pairs(Slabs) do
  428. if v.Level ~= 0 then
  429. NumSlabs = NumSlabs + 1
  430. end
  431. end
  432. local IterNum = 0
  433. for i,v in pairs(Slabs) do
  434. local Part = i
  435. if Slabs[Part].Level ~= 0 then
  436. IterNum = IterNum + 1
  437. local iX, iZ = Part.Name:match(GetXZ)
  438.  
  439. local TorsoPos = LP.Character.Torso.Position
  440. local x = math.sin((math.pi*2)/NumSlabs*IterNum) * (NumSlabs+4)
  441. local z = math.cos((math.pi*2)/NumSlabs*IterNum) * (NumSlabs+4)
  442. local EndPos = Vector3.new(x, 0, z) + TorsoPos
  443.  
  444. local Builder = Instance.new("Part", BuildingMod)
  445. Builder.Name = "Slab" .. "X" .. iX .. "Z" .. iZ
  446. Builder.FormFactor = "Custom"
  447. Builder.Material = "Neon" --WoodPlanks
  448. Builder.Color = Levels[Slabs[Part].Level]
  449. Builder.Anchored = true
  450. Builder.CanCollide = false
  451. Builder.TopSurface = "Smooth"
  452. Builder.BottomSurface = "Smooth"
  453. Builder.Size = Vector3.new(0.5, 0.5, 0.5)
  454. Builder.CFrame = CFrame.new(EndPos, TorsoPos)
  455. table.insert(Builders, {Builder = Builder, Slab = Part, X = tonumber(iX), Z = tonumber(iZ)})
  456. if IterNum % 6 == 0 then
  457. wait(1/30)
  458. end
  459. end
  460. end
  461. wait(1/30)
  462. local LagNum = 0
  463. for _,v in pairs(Builders) do
  464. coroutine.wrap(function()
  465. local Part = v.Builder
  466. local Data = Slabs[v.Slab]
  467. local Height = Width*Data.Level
  468. if Data.Stick then
  469. Height = Width
  470. end
  471. local oldCF = Part.CFrame
  472. local endCF = CFrame.new(BottomLeftBuild.X + v.X, Height/2, BottomLeftBuild.Z + v.Z)
  473. if Data.Stick then
  474. local TrueHeight = Width*(Data.Level-1)
  475. endCF = endCF * CFrame.new(0, TrueHeight, 0)
  476. end
  477. local Path = Pathfinding:ComputeRawPathAsync(Part.Position, endCF.p, 500)
  478. local NumPoints = math.floor(((oldCF.p - endCF.p).magnitude)*(2/3))
  479. for i = 1, NumPoints, 1 do
  480. Part.CFrame = CLerp(oldCF, endCF, i/NumPoints)
  481. RS.Heartbeat:wait()
  482. end
  483. Part.CFrame = endCF
  484. wait(1/30)
  485. local oldSize = Part.Size
  486. local newSize = Vector3.new(Width, Height, Width)
  487. for i = 1, math.max(Height, Width), 0.5 do
  488. Part.Size = oldSize:lerp(newSize, i/math.max(Height, Width))
  489. RS.Heartbeat:wait()
  490. end
  491. Part.Size = newSize
  492. Part.Material = "Marble"
  493. Part.CanCollide = true
  494. end)()
  495. LagNum = LagNum + 1
  496. if LagNum % 2 == 0 then
  497. wait(1/30)
  498. end
  499. end
  500. end
  501. end))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement