Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Made By DexxterDax
- -- 1/21/2021
- local Player = game.Players.LocalPlayer
- local Mouse = Player:GetMouse()
- local Functions = require(game:GetService('ReplicatedStorage').Modules.TycoonFunctions)
- local Cam = workspace.CurrentCamera
- local UIS = game:GetService('UserInputService')
- local RunService = game:GetService('RunService')
- local Event = game:GetService('ReplicatedStorage').Event
- local Editing = false
- local EditCam = false
- local PlacingItem = false
- local Button2Down = false
- local OldMousePos
- local EditingWalls
- local CamRegion3
- local CurrentlyPlacing
- local PlotRegion3
- local WDown = false
- local ADown = false
- local SDown = false
- local DDown = false
- local QDown = false
- local EDown = false
- local RegionPoint1
- local RegionPoint2
- local Tycoons = workspace.TycoonHolder
- local Tycoon
- spawn(function()
- repeat wait() until Functions.PlayerHasTycoon(Player)
- Tycoon = Functions.GetTycoonFromPlayer(Player)
- end)
- function CreateRegion3FromLocAndSize(Position, Size)
- local SizeOffset = Size/2
- RegionPoint1 = Position - SizeOffset
- RegionPoint2 = Position + SizeOffset
- return Region3.new(RegionPoint1, RegionPoint2)
- end
- function CheckIfCamIsInRegion3(Region3)
- local CheckPart = Instance.new('Part', workspace)
- CheckPart.Anchored = true
- CheckPart.Transparency = 1
- CheckPart.CanCollide = false
- CheckPart.Size = Vector3.new(0.05,0.05,0.05)
- CheckPart.CFrame = Cam.CFrame
- for _,Part in pairs(game.Workspace:FindPartsInRegion3(CamRegion3,nil,math.huge)) do
- if Part == CheckPart then
- CheckPart:Destroy()
- return true
- end
- end
- CheckPart:Destroy()
- return false
- end
- function IsInTable(t,v)
- if t and v then
- for _,c in pairs(t) do
- if c == v then
- return true
- end
- end
- return false
- end
- end
- function CheckIfPartIsInRegion3(Part, Region3)
- if Part:IsA('BasePart') then
- for _,v in pairs(game.Workspace:FindPartsInRegion3(Region3,nil,math.huge)) do
- if Part == v then
- return true
- end
- end
- elseif Part:IsA('Model') then
- local Parts = {}
- local Real = {}
- for _,v in pairs(Part:GetDescendants()) do
- if v:IsA('BasePart') then
- table.insert(Real, v)
- end
- end
- local PartsInRegion3 = game.Workspace:FindPartsInRegion3(Region3,nil,math.huge)
- for _,v in pairs(PartsInRegion3) do
- if v:IsDescendantOf(Part) then
- table.insert(Parts,v)
- end
- end
- for _,v in pairs(Real) do
- if not IsInTable(Parts, v) then
- return false
- end
- end
- return true
- end
- end
- Mouse.Button2Down:connect(function() Button2Down = true end)
- Mouse.Button2Up:connect(function() Button2Down = false end)
- UIS.InputBegan:connect(function(Input, GPE)
- if not GPE then
- if Input then
- if Editing then
- if EditCam == true and CamRegion3 then
- if Input.KeyCode == Enum.KeyCode.W then WDown = true end
- if Input.KeyCode == Enum.KeyCode.A then ADown = true end
- if Input.KeyCode == Enum.KeyCode.S then SDown = true end
- if Input.KeyCode == Enum.KeyCode.D then DDown = true end
- if Input.KeyCode == Enum.KeyCode.Q then QDown = true end
- if Input.KeyCode == Enum.KeyCode.E then EDown = true end
- end
- end
- end
- end
- end)
- UIS.InputEnded:connect(function(Input, GPE)
- if not GPE then
- if Input then
- if Editing then
- if EditCam == true and PlotRegion3 then
- if Input.KeyCode == Enum.KeyCode.W then WDown = false end
- if Input.KeyCode == Enum.KeyCode.A then ADown = false end
- if Input.KeyCode == Enum.KeyCode.S then SDown = false end
- if Input.KeyCode == Enum.KeyCode.D then DDown = false end
- if Input.KeyCode == Enum.KeyCode.Q then QDown = false end
- if Input.KeyCode == Enum.KeyCode.E then EDown = false end
- end
- end
- end
- end
- end)
- RunService.RenderStepped:connect(function()
- if EditCam then
- if Editing then
- if PlotRegion3 then
- local Speed = 0.15
- if UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
- Speed = 0.05
- elseif UIS:IsKeyDown(Enum.KeyCode.RightShift) then
- Speed = 0.25
- end
- if WDown then
- Cam.CFrame = Cam.CFrame + Cam.CFrame.lookVector * Speed
- end
- if ADown then
- Cam.CFrame = Cam.CFrame + Cam.CFrame.rightVector * -Speed
- end
- if SDown then
- Cam.CFrame = Cam.CFrame + Cam.CFrame.lookVector * -Speed
- end
- if DDown then
- Cam.CFrame = Cam.CFrame + Cam.CFrame.rightVector * Speed
- end
- if EDown then
- Cam.CFrame = Cam.CFrame + Cam.CFrame.upVector * Speed
- end
- if QDown then
- Cam.CFrame = Cam.CFrame + Cam.CFrame.upVector * -Speed
- end
- local minCorner = RegionPoint1
- local maxCorner = RegionPoint2
- local camPos = Cam.CFrame.p
- Cam.CFrame = CFrame.new(Vector3.new(), Cam.CFrame.lookVector) + Vector3.new(
- math.clamp(camPos.X, minCorner.X, maxCorner.X),
- math.clamp(camPos.Y, minCorner.Y, maxCorner.Y),
- math.clamp(camPos.Z, minCorner.Z, maxCorner.Z)
- )
- end
- end
- end
- end)
- UIS.InputChanged:connect(function(inputObject)
- if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
- if EditCam then
- if Editing then
- if PlotRegion3 then
- if Button2Down then
- UIS.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
- --[[pcall(function()
- if inputObject.Delta.X < OldMousePos.X then
- Cam.CFrame = Cam.CFrame*CFrame.Angles(0, 0.05, 0)
- else
- Cam.CFrame = Cam.CFrame*CFrame.Angles(0, -0.05, 0)
- end
- end)]]
- Cam.CFrame = Cam.CFrame * CFrame.Angles(math.rad(-inputObject.Delta.y/25), math.rad(-inputObject.Delta.x/25),0)
- OldMousePos = Vector2.new(inputObject.Delta.x, inputObject.Delta.Y)
- else
- UIS.MouseBehavior = Enum.MouseBehavior.Default
- end
- end
- end
- end
- end
- end)
- UIS.InputChanged:connect(function(inputObject)
- if inputObject.UserInputType == Enum.UserInputType.MouseWheel then
- if EditCam then
- if Editing then
- if PlotRegion3 then
- if inputObject.Position.z == 1 then
- Cam.CFrame = Cam.CFrame + Cam.CFrame.lookVector * 5
- elseif inputObject.Position.z == -1 then
- Cam.CFrame = Cam.CFrame + Cam.CFrame.lookVector * -5
- end
- end
- end
- end
- end
- end)
- function EnterEditMode()
- if not Editing then
- if Tycoon and Tycoon.Parent == workspace.TycoonHolder then
- if Player.Character and Player.Character:FindFirstChild('HumanoidRootPart') and Player.Character:FindFirstChild('Humanoid').Health > 0 then
- Editing = true
- Mouse.TargetFilter = Tycoon.Purchases
- script.Parent.EditorOptions.Visible = true
- EditingWalls = Tycoon.EditingWalls
- PlotRegion3 = CreateRegion3FromLocAndSize(Tycoon.Base.Position+Vector3.new(0,40.7,0), Tycoon.Base.Size+Vector3.new(0,100,0)):ExpandToGrid(4)
- CamRegion3 = CreateRegion3FromLocAndSize(Tycoon.Base.Position+Vector3.new(0,50,0), Tycoon.Base.Size+Vector3.new(25,100,25)):ExpandToGrid(4)
- Event:FireServer('sdgfhfgjsdhgdflkbdgdfhfghghorsih4go4sdhgfhdafgidghdidfhigdfighdfuigushdhfisdiggibsgufdnbdifughsuidfidfdgfgfghfdgg')
- Tycoon.EditingWalls.Parent = nil
- Functions.CreateGrid(Tycoon.Base)
- Cam.CameraType = Enum.CameraType.Scriptable
- Cam:Interpolate(Tycoon.EditCamPart.CFrame,(Tycoon.EditCamPart.CFrame*CFrame.Angles(0,math.rad(90),0)+Vector3.new(-5,-5,0)), 3)
- Player.Character.HumanoidRootPart.CFrame = (Tycoon.EditPlayerTele.CFrame*CFrame.Angles(0,math.rad(90),0))
- Player.Character.LowerTorso.Anchored = true
- Player.Character.Humanoid.JumpPower = 0
- Player.Character.Humanoid.WalkSpeed = 0
- wait(3)
- EditCam = true
- end
- end
- else
- warn('You are already editing!')
- end
- end
- function RoundVector(vector, unit)
- return vector - Vector3.new(vector.X%unit, 0, vector.Z%unit)
- end
- function CancelPlacement(Place)
- if CurrentlyPlacing then
- if Place then
- local Clone = CurrentlyPlacing:Clone()
- if Clone:FindFirstChild('EditorSelectionBox') then
- Clone.EditorSelectionBox:Destroy()
- end
- Clone.Parent = Tycoon.Purchases
- end
- CurrentlyPlacing:Destroy()
- PlacingItem = false
- end
- end
- function StartPlacingItem(Item)
- if Item then
- if Editing and not PlacingItem then
- if CurrentlyPlacing == nil then
- PlacingItem = true
- CurrentlyPlacing = Item
- local SB = Instance.new('SelectionBox', Item)
- SB.Name = 'EditorSelectionBox'
- SB.Adornee = Item
- SB.Color3 = Color3.new(25,172,0)
- SB.LineThickness = 0.025
- Mouse.TargetFilter = Item
- local RenderStepped
- RenderStepped = RunService.RenderStepped:connect(function()
- if Item and Item.PrimaryPart then
- local MouseP = Mouse.Hit.p
- Item:SetPrimaryPartCFrame(CFrame.new(RoundVector(MouseP,1)+Vector3.new(0,(Item.PrimaryPart.Size.Y/2),0)))
- else
- RenderStepped:Disconnect()
- end
- end)
- local Click
- Click = Mouse.Button1Down:connect(function()
- print(CheckIfPartIsInRegion3(Item, PlotRegion3))
- print(Mouse.Target)
- if CheckIfPartIsInRegion3(Item, PlotRegion3) == true and Mouse.Target == Tycoon.Base or Mouse.Target == Tycoon.CurrentFloor then
- Click:disconnect()
- RenderStepped:Disconnect()
- CancelPlacement(false)
- Event:FireServer('fgdfhguiUHOHFOHDHOIHOHioobndofigiodhtodfoidfbhhiosngodfihIGHIHFIHTdfgdfhfbfdIIlllIIIddfsIIll434DSOIJGJIBILLllII', CurrentlyPlacing)
- PlacingItem = false
- CurrentlyPlacing = nil
- Mouse.TargetFilter = Tycoon.Purchases
- end
- end)
- end
- end
- end
- end
- function StartPlacingPath()
- if Editing and not PlacingItem then
- PlacingItem = true
- local StartedToPlacePath = false
- local RenderStepped
- local Model = Instance.new('Model', Tycoon.Purchases.Walls)
- Model.Name = 'Wall'
- local PathPart1 = Instance.new('Part', Model)
- PathPart1.Name = 'Pole1'
- PathPart1.Anchored = true
- PathPart1.Transparency = 0.2
- PathPart1.Material = Enum.Material.SmoothPlastic
- PathPart1.Shape = 'Cylinder'
- PathPart1.Size = Vector3.new(0.2, 3, 3)
- local PathPart2
- local PathPart
- local Click
- local nope
- local GeneratePath
- local RenderStepped = RunService.RenderStepped:connect(function()
- if not StartedToPlacePath then
- local MouseP = Mouse.Hit.p
- PathPart1.CFrame = CFrame.new(RoundVector(MouseP+Vector3.new(0,PathPart1.Size.X/2,0), 2)+Vector3.new(0.2,0,0.5))*CFrame.Angles(0,0,math.rad(90))
- else
- RenderStepped:disconnect()
- end
- end)
- Click = Mouse.Button1Down:connect(function()
- RenderStepped:disconnect()
- PathPart2 = Instance.new('Part', Model)
- PathPart2.Name = 'Pole2'
- PathPart2.Anchored = true
- PathPart2.Transparency = 0.2
- PathPart2.Material = Enum.Material.SmoothPlastic
- PathPart2.Shape = 'Cylinder'
- PathPart2.Size = Vector3.new(0.2, 3, 3)
- local RenderStepped = RunService.RenderStepped:connect(function()
- local MouseP = Mouse.Hit.p
- PathPart2.CFrame = CFrame.new(RoundVector(MouseP+Vector3.new(0,PathPart2.Size.X/2,0), 2)+Vector3.new(0.2,0,0.5))*CFrame.Angles(0,0,math.rad(90))
- end)
- nope = Mouse.Button1Up:connect(function()
- if not Editing and not EditCam and not PlacingItem then return end
- RenderStepped:disconnect()
- GeneratePath:disconnect()
- nope:disconnect()
- PlacingItem = false
- PathPart1.Transparency = 0
- PathPart2.Transparency = 0
- PathPart.Transparency = 0
- if Click then
- Click:disconnect()
- end
- --PathPart1:Destroy()
- --PathPart2:Destroy()
- PathPart.Name = 'Hitbox'
- PathPart.Parent = Model
- PathPart.Transparency = 0
- Model.PrimaryPart = PathPart
- Event:FireServer('fgdfhguiUHOHFOHDHOIHOHioobndofigiodhtodfoidfbhhiosngodfihIGHIHFIHTdfgdfhfbfdIIlllIIIddfsIIll434DSOIJGJIBILLllII', 'Path', PathPart1.CFrame, PathPart2.CFrame)
- Model:Destroy()
- end)
- end)
- PathPart = Instance.new('Part', Model)
- PathPart.Anchored = true
- PathPart.Transparency = 0.2
- PathPart.Material = Enum.Material.SmoothPlastic
- PathPart.Name = 'PathPart'
- PathPart.Orientation = Vector3.new(0,0,math.rad(90))
- PathPart.Size = Vector3.new(0.2, 3, 3)
- GeneratePath = RunService.RenderStepped:connect(function()
- if PathPart1 and PathPart2 then
- PathPart.Size = Vector3.new((PathPart1.Position - PathPart2.Position).Magnitude,0.2,3)
- PathPart.CFrame = CFrame.new(
- PathPart1.Position + 0.5*(PathPart2.Position - PathPart1.Position),
- PathPart1.Position + 0.5*(PathPart2.Position - PathPart1.Position) + (PathPart1.Position - PathPart2.Position).Unit:Cross(Vector3.new(0,1,0))
- )
- end
- end)
- end
- end
- function CheckForCollison(Thing, Tycoon)
- local Region
- if Thing and Tycoon then
- if Thing:IsA('Model') then
- if Thing.PrimaryPart then
- Region = CreateRegion3FromLocAndSize(Thing.PrimaryPart.Position, Thing.PrimaryPart.Size)
- else
- warn(Thing.Name..' has no PrimaryPart.')
- end
- elseif Thing:IsA('BasePart') then
- Region = CreateRegion3FromLocAndSize(Thing.Position, Thing.Size)
- else
- warn(Thing.Name..' is not Supported.')
- end
- if Region then
- for _,Part in pairs(game.Workspace:FindPartsInRegion3(Region,nil,math.huge)) do
- if Part:IsA('BasePart') then
- if Part:IsDescendantOf(Tycoon.Purchases) and not Part:IsDescendantOf(Thing) then
- return true
- end
- end
- end
- return false
- end
- end
- end
- function StartPlacingWall()
- if Editing and not PlacingItem then
- PlacingItem = true
- local StartedToPlaceWall = false
- local RenderStepped
- local Model = Instance.new('Model', Tycoon.Purchases.Walls)
- Model.Name = 'Wall'
- local WallPart1 = Instance.new('Part', Model)
- WallPart1.Name = 'Pole1'
- WallPart1.Anchored = true
- WallPart1.Transparency = 0.2
- WallPart1.Material = Enum.Material.SmoothPlastic
- WallPart1.Shape = 'Cylinder'
- WallPart1.Size = Vector3.new(9, 0.4, 0.4)
- local WallPart2
- local WallPart
- local Click
- local nope
- local GenerateWall
- local RenderStepped = RunService.RenderStepped:connect(function()
- if not StartedToPlaceWall then
- local MouseP = Mouse.Hit.p
- WallPart1.CFrame = CFrame.new(RoundVector(MouseP+Vector3.new(0,WallPart1.Size.X/2,0), 2)+Vector3.new(0.2,0,0.5))*CFrame.Angles(0,0,math.rad(90))
- else
- RenderStepped:disconnect()
- end
- end)
- Click = Mouse.Button1Down:connect(function()
- RenderStepped:disconnect()
- WallPart2 = Instance.new('Part', Model)
- WallPart2.Name = 'Pole2'
- WallPart2.Anchored = true
- WallPart2.Transparency = 0.2
- WallPart2.Material = Enum.Material.SmoothPlastic
- WallPart2.Shape = 'Cylinder'
- WallPart2.Size = Vector3.new(9, 0.4, 0.4)
- local RenderStepped = RunService.RenderStepped:connect(function()
- local MouseP = Mouse.Hit.p
- WallPart2.CFrame = CFrame.new(RoundVector(MouseP+Vector3.new(0,WallPart2.Size.X/2,0), 2)+Vector3.new(0.2,0,0.5))*CFrame.Angles(0,0,math.rad(90))
- end)
- nope = Mouse.Button1Up:connect(function()
- if not Editing and not EditCam and not PlacingItem then return end
- RenderStepped:disconnect()
- GenerateWall:disconnect()
- nope:disconnect()
- PlacingItem = false
- WallPart1.Transparency = 0
- WallPart2.Transparency = 0
- WallPart.Transparency = 0
- if Click then
- Click:disconnect()
- end
- WallPart1:Destroy()
- WallPart2:Destroy()
- WallPart.Name = 'Hitbox'
- WallPart.Parent = Model
- WallPart.Transparency = 0
- Model.PrimaryPart = WallPart
- Event:FireServer('fgdfhguiUHOHFOHDHOIHOHioobndofigiodhtodfoidfbhhiosngodfihIGHIHFIHTdfgdfhfbfdIIlllIIIddfsIIll434DSOIJGJIBILLllII', 'Wall', WallPart1.CFrame, WallPart2.CFrame)
- Model:Destroy()
- end)
- end)
- WallPart = Instance.new('Part', Model)
- WallPart.Anchored = true
- WallPart.Transparency = 0.2
- WallPart.Material = Enum.Material.SmoothPlastic
- WallPart.Name = 'WallPart'
- WallPart.Orientation = Vector3.new(0,0,math.rad(90))
- WallPart.Size = Vector3.new(9, 12, 0.4)
- GenerateWall = RunService.RenderStepped:connect(function()
- if WallPart1 and WallPart2 then
- WallPart.Size = Vector3.new((WallPart1.Position - WallPart2.Position).Magnitude,9,0.4)
- WallPart.CFrame = CFrame.new(
- WallPart1.Position + 0.5*(WallPart2.Position - WallPart1.Position),
- WallPart1.Position + 0.5*(WallPart2.Position - WallPart1.Position) + (WallPart1.Position - WallPart2.Position).Unit:Cross(Vector3.new(0,1,0))
- )
- end
- end)
- end
- end
- script.Parent.Back.Edit.MouseButton1Click:connect(function()
- if Functions.PlayerHasTycoon(Player) then
- EnterEditMode()
- else
- warn('You do not have a tycoon!')
- end
- end)
- script.Parent.Back.Save.MouseButton1Click:connect(function()
- Functions.SaveTycoon(Player)
- end)
- script.Parent.EditorOptions.ExitEditor.MouseButton1Click:connect(function()
- if Editing then
- CancelPlacement(false)
- Editing = false
- PlacingItem = false
- for _,v in pairs(EditingWalls:GetDescendants()) do
- if v:IsA('Decal') then
- v.Transparency = 1
- elseif v:IsA('BasePart') then
- v.CanCollide = false
- end
- end
- Tycoon.Base.EditorLines:Destroy()
- EditingWalls.Parent = Tycoon
- Player.Character.HumanoidRootPart.CFrame = (Tycoon.FinishPlayerTele.CFrame*CFrame.Angles(0,math.rad(90),0))
- Player.Character.LowerTorso.Anchored = false
- Player.Character.Humanoid.JumpPower = 50
- Player.Character.Humanoid.WalkSpeed = 16
- Cam.CameraSubject = Player.Character.Humanoid
- Cam.CameraType = Enum.CameraType.Custom
- EditCam = false
- script.Parent.EditorOptions.Visible = false
- end
- end)
- script.Parent.EditorOptions.PlaceItem.MouseButton1Click:connect(function()
- if not PlacingItem then
- local c = workspace.ModernFridge2:Clone()
- c.Parent = workspace
- StartPlacingItem(c)
- end
- end)
- script.Parent.EditorOptions.PlaceWall.MouseButton1Click:connect(function()
- if not PlacingItem then
- StartPlacingWall()
- end
- end)
- script.Parent.EditorOptions.PlacePath.MouseButton1Click:connect(function()
- if not PlacingItem then
- StartPlacingPath()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement