Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Draw2Life - Created By Vaeb
- wait(1/30)
- script.Parent = nil
- --Settings
- local Plrs = game:GetService("Players")
- local UIS = game:GetService("UserInputService")
- local Pathfinding = game:GetService("PathfindingService")
- local Light = game:GetService("Lighting")
- local RS = game:GetService("RunService")
- local Utils = assert(LoadLibrary("RbxUtility"))
- local LP = Plrs.LocalPlayer
- local MainPlr = "Vaeb"
- local Mouse = LP:GetMouse()
- local Width = 3
- local Squares = 30
- local BottomLeft = Vector3.new(-((Squares*Width)/2), 10, 15)
- local BottomLeftBuild = Vector3.new(-((Squares*Width)/2), 10, 15+(Squares*Width)+5)
- local BaseY = nil
- local isDown = false
- local EDown = false
- local CDown = false
- local NumKeyDown = {}
- local Slabs = nil
- local GetXZ = "(%d+)Z(%d+)"
- local Cons = {}
- local StopAll = false
- if LP.Name == MainPlr then
- Slabs = {}
- end
- --Numbers
- local Numbers = {
- ["one"] = 1;
- ["two"] = 2;
- ["three"] = 3;
- ["four"] = 4;
- ["five"] = 5;
- ["six"] = 6;
- ["seven"] = 7;
- ["eight"] = 8;
- }
- --Height
- local Levels = {
- [0] = Color3.new(0, 0, 0); --Black : 0
- [1] = Color3.new(1, 1, 1); --White : 1
- [2] = Color3.new(1, 0, 0); --Red : 2
- [3] = Color3.new(0, 1, 0); --Green : 3
- [4] = Color3.new(0, 0, 1); --Blue : 4
- [5] = Color3.new(1, 0, 1); --Pink : 5
- [6] = Color3.new(0, 1, 1); --Toothpaste : 6
- [7] = Color3.new(1, 1, 0); --Yellow : 7
- [8] = Color3.new(0.5, 0.35, 0.275); --Brown : 8
- }
- local function QuaternionFromCFrame(cf)
- local mx, my, mz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cf:components();
- local trace = m00 + m11 + m22 if trace > 0 then
- local s = math.sqrt(1 + trace);
- local recip = 0.5/s;
- return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5;
- else
- local i = 0;
- if m11 > m00 then
- i = 1;
- end;
- if m22 > (i == 0 and m00 or m11) then
- i = 2 end if i == 0 then
- local s = math.sqrt(m00-m11-m22+1);
- local recip = 0.5/s return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip;
- elseif i == 1 then
- local s = math.sqrt(m11-m22-m00+1);
- local recip = 0.5/s;
- return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip ;
- elseif i == 2 then
- local s = math.sqrt(m22-m00-m11+1);
- local recip = 0.5/s;
- return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip;
- end;
- end;
- end;
- local function QuaternionToCFrame(px, py, pz, x, y, z, w)
- local xs, ys, zs = x + x, y + y, z + z;
- local wx, wy, wz = w*xs, w*ys, w*zs;
- local xx = x*xs;
- local xy = x*ys;
- local xz = x*zs;
- local yy = y*ys;
- local yz = y*zs;
- local zz = z*zs;
- 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))
- end;
- local function QuaternionSlerp(a, b, t)
- local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4];
- local startInterp, finishInterp;
- if cosTheta >= 0.0001 then
- if (1 - cosTheta) > 0.0001 then
- local theta = math.acos(cosTheta);
- local invSinTheta = 1/math.sin(theta);
- startInterp = math.sin((1-t)*theta)*invSinTheta;
- finishInterp = math.sin(t*theta)*invSinTheta;
- else
- startInterp = 1-t finishInterp = t;
- end;
- else
- if (1+cosTheta) > 0.0001 then
- local theta = math.acos(-cosTheta);
- local invSinTheta = 1/math.sin(theta);
- startInterp = math.sin((t-1)*theta)*invSinTheta;
- finishInterp = math.sin(t*theta)*invSinTheta;
- else startInterp = t-1 finishInterp = t;
- end;
- end;
- 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;
- end;
- function CLerp(a,b,t)
- local qa={QuaternionFromCFrame(a)};
- local qb={QuaternionFromCFrame(b)};
- local ax,ay,az=a.x,a.y,a.z;
- local bx,by,bz=b.x,b.y,b.z;
- local _t=1-t;
- return QuaternionToCFrame(_t*ax+t*bx,_t*ay+t*by,_t*az+t*bz,QuaternionSlerp(qa, qb, t));
- end
- if LP.Name == MainPlr then
- --Make drawing pad
- for iZ = 0, Squares*Width, Width do --Y
- for iX = 0, Squares*Width, Width do --X
- local Part = Instance.new("Part", workspace)
- Part.Name = "Slab" .. "X" .. tostring(iX) .. "Z" .. tostring(iZ)
- Part.FormFactor = "Custom"
- if iZ == 0 and iX == (Squares/2)*Width then
- Part.Color = Levels[1]
- else
- Part.Color = Levels[0]
- end
- Part.Anchored = true
- Part.CanCollide = true
- Part.TopSurface = "Smooth"
- Part.BottomSurface = "Smooth"
- Part.Size = Vector3.new(Width, 0.05, Width)
- --Find Base's Y Pos
- local EndPos = BottomLeft + Vector3.new(iX, 0, iZ)
- if BaseY == nil then
- local DownPos = EndPos - Vector3.new(0, 1, 0)
- local CheckRay = Ray.new(EndPos, (DownPos - EndPos).unit * 50)
- local Hit, HitPos = Workspace:FindPartOnRay(CheckRay, LP.Character)
- BaseY = HitPos.Y
- BottomLeftBuild = Vector3.new(BottomLeftBuild.X, BaseY, BottomLeftBuild.Z)
- end
- Part.CFrame = CFrame.new(EndPos.X, BaseY + Part.Size.Y/2, EndPos.Z)
- local Surface = Instance.new("SurfaceGui")
- Surface.Name = "Surface"
- Surface.Adornee = Part
- Surface.CanvasSize = Vector2.new(Width * 40, Width * 40)
- Surface.Enabled = false
- Surface.Face = "Top"
- Surface.Parent = Part
- local Label = Instance.new("TextLabel", Surface)
- Label.Name = "Label"
- if iZ == 0 and iX == (Squares/2)*Width then
- Label.Text = "1"
- Surface.Enabled = true
- else
- Label.Text = "0"
- end
- Label.TextColor3 = Color3.new(0, 0, 0)
- Label.Font = "SourceSansBold"
- Label.FontSize = "Size48"
- Label.TextStrokeTransparency = 1
- Label.BackgroundTransparency = 1
- Label.Size = UDim2.new(1, 0, 1, 0)
- Label.Position = UDim2.new(0, 0, 0, 0)
- if iZ == 0 and iX == (Squares/2)*Width then
- Slabs[Part] = {Level = 1, X = iX, Z = iZ, Stick = false}
- else
- Slabs[Part] = {Level = 0, X = iX, Z = iZ, Stick = false}
- end
- local replacePart = Part:Clone()
- local StringVal = Instance.new("StringValue")
- StringVal.Name = "SlabData"
- local JSONString = Utils.EncodeJSON(Slabs[Part])
- StringVal.Value = JSONString
- StringVal.Parent = Part
- local Prot; Prot = function(Obj)
- local SlabDataVal = Obj["SlabData"]
- local Con1; Con1 = SlabDataVal.Changed:connect(function(Value) --Later move below
- if SlabDataVal.Parent ~= nil and SlabDataVal.Parent.Parent ~= nil and Slabs[SlabDataVal.Parent] then
- local Data = Utils.DecodeJSON(Value)
- Slabs[SlabDataVal.Parent] = Data
- else
- Con1:disconnect()
- end
- end)
- local Con2; Con2 = Obj.Changed:connect(function(P)
- if StopAll == true then
- Con2:disconnect()
- elseif P:lower() == "parent" then
- Con2:disconnect()
- local newClone = replacePart:Clone()
- Slabs[newClone] = Slabs[Obj]
- Slabs[newClone].Stick = Slabs[Obj].Stick
- Slabs[Obj] = nil
- pcall(function() Obj:Destroy() end)
- newClone.Parent = workspace
- if Slabs[newClone].Level ~= 0 then
- newClone.Surface.Label.Text = tostring(Slabs[newClone].Level)
- newClone.Surface.Enabled = true
- else
- newClone.Surface.Enabled = false
- newClone.Surface.Label.Text = "0"
- end
- if Slabs[newClone].Stick == true then
- newClone.Surface.Label.Text = newClone.Surface.Label.Text .. "X"
- end
- local StringVal = Instance.new("StringValue")
- StringVal.Name = "SlabData"
- local JSONString = Utils.EncodeJSON(Slabs[newClone])
- StringVal.Value = JSONString
- StringVal.Parent = newClone
- newClone.Color = Levels[Slabs[newClone].Level]
- Prot(newClone)
- end
- end)
- end
- Prot(Part)
- end
- end
- end
- --[[table.insert(Cons, Mouse.Button1Up:connect(function()
- isDown = false
- end))
- table.insert(Cons, Mouse.Button1Down:connect(function()
- isDown = true
- local LastTarg = nil
- repeat
- if Mouse.Target and Mouse.Target ~= LastTarg and Mouse.Target.Name:sub(1, 4) == "Slab" then
- local Part = Mouse.Target
- LastTarg = Part
- local Data = Utils.DecodeJSON(Part["SlabData"].Value)
- if Levels[Data.Level+1] then
- Data.Level = Data.Level + 1
- Part.Surface.Label.Text = tostring(Data.Level)
- Part.Surface.Enabled = true
- else
- Data.Level = 0
- Part.Surface.Enabled = false
- Part.Surface.Label.Text = "0"
- end
- if Data.Stick == true then
- Part.Surface.Label.Text = Part.Surface.Label.Text .. "X"
- end
- Part.Color = Levels[Data.Level]
- local StringVal = Part["SlabData"]
- local JSONString = Utils.EncodeJSON(Data)
- StringVal.Value = JSONString
- end
- wait(1/30)
- until isDown == false
- end))]]
- table.insert(Cons, Mouse.KeyUp:connect(function(Key)
- if Key:lower() == "e" then
- EDown = false
- elseif Key:lower() == "c" then
- CDown = false
- elseif tonumber(Key) then
- NumKeyDown[tonumber(Key)] = nil
- end
- end))
- table.insert(Cons, Mouse.KeyDown:connect(function(Key) --Make it so can change number based on KeyDown number
- if Key:lower() == "e" then
- EDown = true
- local LastTarg = nil
- repeat
- if Mouse.Target and Mouse.Target ~= LastTarg and Mouse.Target.Name:sub(1, 4) == "Slab" then
- local Part = Mouse.Target
- LastTarg = Part
- local Data = Utils.DecodeJSON(Part["SlabData"].Value)
- Data.Level = 0
- Data.Stick = false
- Part.Surface.Enabled = false
- Part.Surface.Label.Text = "0"
- Part.Color = Levels[Data.Level]
- local StringVal = Part["SlabData"]
- local JSONString = Utils.EncodeJSON(Data)
- StringVal.Value = JSONString
- end
- wait(1/30)
- until EDown == false
- elseif Key:lower() == "c" then
- CDown = true
- local LastTarg = nil
- repeat
- if Mouse.Target and Mouse.Target ~= LastTarg and Mouse.Target.Name:sub(1, 4) == "Slab" then
- local Part = Mouse.Target
- LastTarg = Part
- local Data = Utils.DecodeJSON(Part["SlabData"].Value)
- if Data.Stick == true then
- Data.Stick = false
- Part.Surface.Label.Text = tostring(Data.Level)
- elseif Data.Stick == false then
- Data.Stick = true
- Part.Surface.Label.Text = tostring(Data.Level) .. "X"
- end
- local StringVal = Part["SlabData"]
- local JSONString = Utils.EncodeJSON(Data)
- StringVal.Value = JSONString
- end
- wait(1/30)
- until CDown == false
- end
- end))
- table.insert(Cons, UIS.InputBegan:connect(function(Input, Processed) --Watch out - Fires when chatting
- local Key = tostring(Input.KeyCode):lower()
- if #Key > 4 and Key:sub(1, 4) == "enum" then
- Key = Key:sub(14)
- end
- if Numbers[Key] then
- local Num = Numbers[Key]
- NumKeyDown[Num] = true
- local LastTarg = nil
- repeat
- if Mouse.Target and Mouse.Target ~= LastTarg and Mouse.Target.Name:sub(1, 4) == "Slab" then
- local Part = Mouse.Target
- LastTarg = Part
- local Data = Utils.DecodeJSON(Part["SlabData"].Value)
- Data.Level = Num
- if Data.Level ~= 0 then
- Part.Surface.Label.Text = tostring(Data.Level)
- Part.Surface.Enabled = true
- else
- Part.Surface.Enabled = false
- Part.Surface.Label.Text = tostring(Data.Level)
- end
- if Data.Stick == true then
- Part.Surface.Label.Text = tostring(Data.Level) .. "X"
- end
- Part.Color = Levels[Data.Level]
- local StringVal = Part["SlabData"]
- local JSONString = Utils.EncodeJSON(Data)
- StringVal.Value = JSONString
- end
- wait(1/30)
- until NumKeyDown[Num] == nil
- end
- end))
- table.insert(Cons, UIS.InputEnded:connect(function(Input, Processed)
- local Key = tostring(Input.KeyCode):lower()
- if #Key > 4 and Key:sub(1, 4) == "enum" then
- Key = Key:sub(14)
- end
- if Numbers[Key] then
- local Num = Numbers[Key]
- NumKeyDown[Num] = nil
- end
- end))
- table.insert(Cons, LP.Chatted:connect(function(Msg)
- if Msg:lower() == "end" then
- StopAll = true
- for i,v in pairs(Cons) do
- v:disconnect()
- end
- print("Ended")
- elseif Msg:lower() == "reset" then
- if LP.Name == MainPlr then
- local Slabs = {}
- for _,v in pairs(workspace:GetChildren()) do
- if v.Name:sub(1, 4) == "Slab" then
- Slabs[v] = Utils.DecodeJSON(v["SlabData"].Value)
- end
- end
- for i,v in pairs(Slabs) do
- local StringVal = i["SlabData"]
- local Data = nil
- if v.Z == 0 and v.X == (Squares/2)*Width then
- Data = {Level = 1, X = v.X, Z = v.Z, Stick = false}
- i.Color = Levels[1]
- i.Surface.Enabled = true
- i.Surface.Label.Text = "1"
- else
- Data = {Level = 0, X = v.X, Z = v.Z, Stick = false}
- i.Color = Levels[0]
- i.Surface.Enabled = false
- i.Surface.Label.Text = "0"
- end
- local JSONString = Utils.EncodeJSON(Data)
- StringVal.Value = JSONString
- end
- print("Reset")
- else
- print("Only " .. MainPlr .. " Can Use This Command")
- end
- elseif Msg:lower() == "build" and LP.Character and LP.Character.Parent and LP.Character:findFirstChild("Torso") then
- print("Building")
- local Slabs = {}
- for _,v in pairs(workspace:GetChildren()) do
- if v.Name:sub(1, 4) == "Slab" then
- Slabs[v] = Utils.DecodeJSON(v["SlabData"].Value)
- end
- end
- pcall(function() workspace["BuildingMod"]:Destroy() end)
- local BuildingMod = Instance.new("Model", workspace)
- BuildingMod.Name = "BuildingMod"
- local Builders = {}
- local NumSlabs = 0
- for i,v in pairs(Slabs) do
- if v.Level ~= 0 then
- NumSlabs = NumSlabs + 1
- end
- end
- local IterNum = 0
- for i,v in pairs(Slabs) do
- local Part = i
- if Slabs[Part].Level ~= 0 then
- IterNum = IterNum + 1
- local iX, iZ = Part.Name:match(GetXZ)
- local TorsoPos = LP.Character.Torso.Position
- local x = math.sin((math.pi*2)/NumSlabs*IterNum) * (NumSlabs+4)
- local z = math.cos((math.pi*2)/NumSlabs*IterNum) * (NumSlabs+4)
- local EndPos = Vector3.new(x, 0, z) + TorsoPos
- local Builder = Instance.new("Part", BuildingMod)
- Builder.Name = "Slab" .. "X" .. iX .. "Z" .. iZ
- Builder.FormFactor = "Custom"
- Builder.Material = "Neon" --WoodPlanks
- Builder.Color = Levels[Slabs[Part].Level]
- Builder.Anchored = true
- Builder.CanCollide = false
- Builder.TopSurface = "Smooth"
- Builder.BottomSurface = "Smooth"
- Builder.Size = Vector3.new(0.5, 0.5, 0.5)
- Builder.CFrame = CFrame.new(EndPos, TorsoPos)
- table.insert(Builders, {Builder = Builder, Slab = Part, X = tonumber(iX), Z = tonumber(iZ)})
- if IterNum % 6 == 0 then
- wait(1/30)
- end
- end
- end
- wait(1/30)
- local LagNum = 0
- for _,v in pairs(Builders) do
- coroutine.wrap(function()
- local Part = v.Builder
- local Data = Slabs[v.Slab]
- local Height = Width*Data.Level
- if Data.Stick then
- Height = Width
- end
- local oldCF = Part.CFrame
- local endCF = CFrame.new(BottomLeftBuild.X + v.X, Height/2, BottomLeftBuild.Z + v.Z)
- if Data.Stick then
- local TrueHeight = Width*(Data.Level-1)
- endCF = endCF * CFrame.new(0, TrueHeight, 0)
- end
- local Path = Pathfinding:ComputeRawPathAsync(Part.Position, endCF.p, 500)
- local NumPoints = math.floor(((oldCF.p - endCF.p).magnitude)*(2/3))
- for i = 1, NumPoints, 1 do
- Part.CFrame = CLerp(oldCF, endCF, i/NumPoints)
- RS.Heartbeat:wait()
- end
- Part.CFrame = endCF
- wait(1/30)
- local oldSize = Part.Size
- local newSize = Vector3.new(Width, Height, Width)
- for i = 1, math.max(Height, Width), 0.5 do
- Part.Size = oldSize:lerp(newSize, i/math.max(Height, Width))
- RS.Heartbeat:wait()
- end
- Part.Size = newSize
- Part.Material = "Marble"
- Part.CanCollide = true
- end)()
- LagNum = LagNum + 1
- if LagNum % 2 == 0 then
- wait(1/30)
- end
- end
- end
- end))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement