Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function InitiatePlacing(ItemBtn)
- if false then
- -- script.Parent.ItemSettings.Visible = false
- else
- if game.ReplicatedStorage.HasItem:InvokeServer(ItemBtn.ItemId.Value) > 0 and ItemBtn.ItemId.Value > 0 and not Placing and UsingMouse then
- -- script.Parent.Cancel.Visible = true
- Placing = true
- if script.Parent.Hovering.Hover.Details.Value then
- script.Parent.Hovering.Hover.Close:Fire()
- end
- GoodPlacement = false
- if not InputService.GamepadEnabled then
- Mouse.Icon = "rbxassetid://209048202"
- end
- game.ContextActionService:BindAction("PlaceItem",Place,false,Enum.KeyCode.ButtonR2)
- script.Parent.YYCenter.ObjectPlacement.Visible = true
- -- script.Parent.Undo.Visible = true
- -- script.Parent.Place.Visible = (InputService.GamepadEnabled or (InputService.TouchEnabled and not InputService.MouseEnabled))
- if Mouse then
- Mouse.TargetFilter = workspace.Tycoons
- end
- script.Parent.YYLeft.Inventory.Visible = false
- if game:GetService("UserInputService").TouchEnabled then
- game.Players.LocalPlayer.PlayerGui.TouchGui.TouchControlFrame.Visible = true
- end
- local toClone = getItemById(ItemBtn.ItemId.Value)
- if toClone then
- Visual = toClone:clone()
- local LocalItemTag = Instance.new("BoolValue")
- LocalItemTag.Name = "LocalItem"
- LocalItemTag.Parent = Visual
- Visual.Parent = GetTycoon()
- if Visual then
- -- script.Parent.CurrentlyPlacing.Thumbnail.Image = "rbxassetid://" .. Visual.ThumbnailId.Value
- -- script.Parent.CurrentlyPlacing.Count.Text = "x" .. game.ReplicatedStorage.HasItem:InvokeServer(Visual.ItemId.Value)
- script.Parent.YYRight.Placement.Image.Image = "rbxassetid://" .. Visual.ThumbnailId.Value
- local Amount = "x" .. game.ReplicatedStorage.HasItem:InvokeServer(Visual.ItemId.Value)
- script.Parent.YYRight.Placement.Amount.Text = Amount
- script.Parent.YYRight.Placement.AmountDark.Text = Amount
- local EndPosition = UDim2.new(1,-300,0.6,0)
- if not game:GetService("UserInputService").TouchEnabled then
- -- script.Parent.CurrentlyPlacing:TweenPosition(EndPosition,Enum.EasingDirection.InOut,Enum.EasingStyle.Quart,0.5)
- script.Parent.YYRight.Placement:TweenPosition(UDim2.new(-0.235,0,0.6,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quart,0.5, true)
- end
- end
- for i, TycoonItem in pairs(GetTycoon():GetChildren()) do
- if game.ReplicatedStorage.Items:FindFirstChild(TycoonItem.Name) and TycoonItem:IsA("Model") then
- local SelBox = TycoonItem:FindFirstChild("SelectionBox")
- if SelBox then
- SelBox.Visible = true
- SelBox.Transparency = 0.6
- end
- end
- end
- for i,v in pairs(workspace.Boxes:GetChildren()) do
- v.Visible = true
- end
- Visual.Hitbox.Transparency = 0.6
- Visual.Hitbox.Reflectance = 0.2
- local bMesh = Instance.new("BlockMesh",Visual.Hitbox)
- bMesh.Scale = Vector3.new(1,1000,1)
- if Visual:FindFirstChild("SelectionBox") then
- Visual.SelectionBox.Visible = true
- Visual.SelectionBox.Transparency = 0
- end
- for ii,vv in pairs(Visual.Model:GetChildren()) do
- if vv:IsA("BasePart") then
- vv.CanCollide = false
- vv.Anchored = true
- if vv.Name == "Colored" then
- vv.BrickColor = game.Players.LocalPlayer.TeamColor
- end
- end
- end
- local TycoonBase = GetTycoon().Base
- local TycoonTopLeft = TycoonBase.CFrame * CFrame.new(Vector3.new(TycoonBase.Size.x/2, 0, TycoonBase.Size.z/2))
- local ModelItemId = Instance.new("IntValue", Visual)
- ModelItemId.Name = "ItemId"
- ModelItemId.Value = ItemBtn.ItemId.Value
- local Hitbox = getItemById(ItemBtn.ItemId.Value).Hitbox:clone()
- Hitbox.Parent = Visual
- Visual.PrimaryPart = Hitbox
- Visual:SetPrimaryPartCFrame(TycoonTopLeft * CFrame.new(Vector3.new(-Hitbox.Size.x/2, Hitbox.Size.y/2, -Hitbox.Size.z/2)))
- local TycoonBaseSizeX, TycoonBaseSizeZ
- local HitboxSizeX, HitboxSizeZ
- local Hitboxes
- local NewVector
- local LastPosition = CFrame.new()
- local function VerifyPos()
- local ModelColliding
- local function Argue()
- for i, Hitbox in pairs(Hitboxes) do
- if Hitbox.Name == "Hitbox" and not Hitbox:IsDescendantOf(Visual) then
- return false
- end
- end
- local CheckRay = Ray.new(Visual.Hitbox.Position, Vector3.new(0,-500,0))
- local Hit = workspace:FindPartOnRayWithIgnoreList(CheckRay,{GetTycoon()})
- if Hit and Hit:FindFirstChild("Base") and Hit.Name == GetTycoon().Name then
- return true
- end
- return false
- end
- local ModelColliding = not Argue()
- GoodPlacement = not ModelColliding
- Visual:SetPrimaryPartCFrame(NewVector * CFrame.Angles(0, math.rad(Rotation), 0))
- if GoodPlacement then
- LastPosition = NewVector * CFrame.Angles(0, math.rad(Rotation), 0)
- Visual.Hitbox.BrickColor = BrickColor.new("Bright blue")
- Visual.SelectionBox.Color3 = Color3.new(0.0509804, 0.411765, 0.67451)
- else
- Visual.Hitbox.BrickColor = BrickColor.new("Really red")
- Visual.SelectionBox.Color3 = Color3.new(1,0,0)
- end
- end
- local function CheckPos(xdisp,zdisp,placepos) -- placepos is Mouse.Hit.p on pc
- xdisp = xdisp or 0
- zdisp = zdisp or 0
- if Rotation % 180 == 0 then
- TycoonBaseSizeX, TycoonBaseSizeZ = TycoonBase.Size.x, TycoonBase.Size.z
- HitboxSizeX, HitboxSizeZ = Hitbox.Size.x, Hitbox.Size.z
- else
- TycoonBaseSizeX, TycoonBaseSizeZ = TycoonBase.Size.x, TycoonBase.Size.z
- HitboxSizeX, HitboxSizeZ = Hitbox.Size.z, Hitbox.Size.x
- end
- local TycoonTopLeft = TycoonBase.CFrame * CFrame.new(Vector3.new(TycoonBase.Size.x/2, 0, TycoonBase.Size.z/2))
- local BaseAngleX, BaseAngleY, BaseAngleZ = CFrame.new(TycoonBase.Position, (TycoonBase.CFrame*Vector3.new(1, 0, 0))):toEulerAnglesXYZ()
- local VectorRotation = CFrame.Angles(BaseAngleX, BaseAngleY, BaseAngleZ)
- local RoundByThreeX = RoundByThree(math.floor(placepos.x) + xdisp - math.ceil(TycoonTopLeft.x))
- local RoundByThreeZ = RoundByThree(math.floor(placepos.z) + zdisp - math.ceil(TycoonTopLeft.z))
- if RoundByThreeX < -TycoonBaseSizeX + HitboxSizeX then
- RoundByThreeX = RoundByThreeX + HitboxSizeX
- end
- if RoundByThreeZ < -TycoonBaseSizeZ + HitboxSizeZ then
- RoundByThreeZ = RoundByThreeZ + HitboxSizeZ
- end
- local VectorComponent1 = CFrame.new(Vector3.new(TycoonTopLeft.x, TycoonBase.Position.y, TycoonTopLeft.z))
- local VectorComponent2 = CFrame.new(Vector3.new(RoundByThreeX, TycoonBase.Size.y/2, RoundByThreeZ)) --*VectorRotation
- local VectorComponent3 = CFrame.new(Vector3.new(-HitboxSizeX/2, Hitbox.Size.y/2, -HitboxSizeZ/2))
- NewVector = VectorComponent1*VectorComponent2*VectorComponent3
- local RegionVectorMin = NewVector * CFrame.new(Vector3.new(HitboxSizeX/2, -Hitbox.Size.y/2, HitboxSizeZ/2))
- local RegionVectorMax = NewVector * CFrame.new(-Vector3.new(HitboxSizeX/2, -Hitbox.Size.y/2, HitboxSizeZ/2))
- Hitboxes = game.Workspace:FindPartsInRegion3(
- Region3.new(
- Vector3.new(
- math.min(RegionVectorMin.x, RegionVectorMax.x),
- math.min(RegionVectorMin.y, RegionVectorMax.y),
- math.min(RegionVectorMin.z, RegionVectorMax.z)
- ) + Vector3.new(0.1, 0, 0.1),
- Vector3.new(
- math.max(RegionVectorMin.x, RegionVectorMax.x),
- math.max(RegionVectorMin.y, RegionVectorMax.y),
- math.max(RegionVectorMin.z, RegionVectorMax.z)
- ) - Vector3.new(0.1, 0, 0.1)
- ), game.Workspace.Map, 100
- )
- return true
- end
- while Placing do
- GetTycoon().Base.Grid.Transparency = 0.5
- if TycoonBase ~= nil then
- local UIS = game:GetService("UserInputService")
- if UIS.GamepadEnabled or (UIS.TouchEnabled and not UIS.MouseEnabled) then
- local LookVector = workspace.CurrentCamera.CoordinateFrame.lookVector
- local xCo = 1
- local zCo = 1
- if LookVector.x > 0 then
- xCo = 2
- end
- if LookVector.z > 0 then
- zCo = 2
- end
- NewVector = Vector3.new(LookVector.x * xCo, LookVector.y, LookVector.z * zCo)
- local Pos = Player.Character.HumanoidRootPart.Position + (NewVector * 20)
- -- local Pos = Player.Character.Torso.Position + (NewVector * 20)
- CheckPos(0,0,Pos)
- VerifyPos()
- elseif Mouse ~= nil and Mouse.Target ~= nil and Mouse.Target.Name == GetTycoon().Name and Mouse.Target:FindFirstChild("Base") then
- CheckPos(0,0,Mouse.Hit.p)
- VerifyPos()
- --TransformModel(Visual:GetChildren(), Visual.PrimaryPart.CFrame, CFrame.new(VectorComponent3.p, VectorComponent3*CFrame.new(1, 0, 0)) + CFrame.new(LastPosition.p), true)
- end
- end
- game:GetService("RunService").Heartbeat:wait()
- end
- if Mouse then
- Mouse.TargetFilter = nil
- end
- --RemoveItem:InvokeServer(ItemBtn.ItemId.Value, 1)
- GetTycoon().Base.Grid.Transparency = 1
- --Mouse.Icon = ""
- --game:GetService("UserInputService").MouseIconEnabled = false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement