Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --scripted by GreekForge
- local char = script.Parent
- local hum = char:WaitForChild("Humanoid")
- local buildComs = game.ReplicatedStorage.Build
- local plr = game.Players:WaitForChild(char.Name)
- local buildMess = plr.PlayerGui:WaitForChild("BuildMessage")
- local mouse = game:GetService("Players").LocalPlayer:GetMouse() --i need to know where he is going to build
- local ingame = plr.stats.isInGame
- local isBuilding = plr.PlayerGui.FlatUI.BuildMode.LocalScript.Building --from the gui
- local camera = workspace.CurrentCamera --so i can store our outline and make it client based
- local buildrange = 45
- local cost = 5
- local wood = plr.stats.ShopValues.Wood
- local woodHP = plr.stats.Attributes.WoodHP
- local rot = 0;
- local canBuild = false; --for the terrainlimitations
- local terrainLimit
- local debounce = true; --why its inverse is beyond me
- --char:WaitForChild("Humanoid").JumpPower = 10
- local function canBuildF(oPos, outline)
- if terrainLimit then
- local scorePartN = string.gsub(terrainLimit, "Terrain", "ScorePart")
- local prisonPartN = string.gsub(terrainLimit, "Terrain", "TeamJail")
- local prisonPart = workspace.Arena:FindFirstChild(prisonPartN)
- local scorePart = workspace.Arena:FindFirstChild(scorePartN)
- local dV = (outline.CFrame.upVector * -1).Unit * buildrange --(outline.CFrame.upVector - outline.Position).Unit * buildrange --(maybe)?
- local ray = Ray.new(outline.Position, dV)
- local part = workspace:FindPartOnRay(ray, outline)
- local downTest
- if part then
- downTest = (part.Name == terrainLimit)
- else
- downTest = false
- end
- return ((scorePart.Position - oPos).Magnitude > buildrange and (prisonPart.Position - oPos).Magnitude > buildrange and downTest)
- end
- end
- local function round(val)
- local c1 = math.floor(val)
- local s2 = val - c1
- if math.abs(s2) >= 0.5 then
- return math.ceil(val)
- else
- return c1
- end
- end
- local function grid(oVal, outline)
- local grid = 3.5 --this will need to be set in stone, it can't be dynamic sadly
- local s1 = round(oVal*100)/100 --rounded to the nearest hundredths (0.01)
- local s2 = math.abs(s1)
- if s2 % grid ~= 0 then --just griding it
- s2 = s2 - (s2 % grid)
- if s1 < 0 then --return it back to it's original sign
- return (-1 * s2)
- else --I can't use math.abs sadly
- return s2
- end
- end
- end
- local function checkOutline()
- local outline = camera:FindFirstChild(plr.Name.."_BuildOutline")
- if outline == nil then --set up if missing
- outline = script:WaitForChild("Buildables"):WaitForChild("Basic_Block"):Clone()
- outline.Parent = camera
- outline.Name = plr.Name.."_BuildOutline"
- outline.Transparency = 1
- outline.Anchored = true
- outline.CanCollide = false
- outline.BrickColor = BrickColor.new("Really blue")
- outline.Material = Enum.Material.SmoothPlastic
- end
- end
- local function blockOutline(outline)
- local ray = Ray.new(camera.CFrame.p, mouse.UnitRay.Direction*(buildrange*2))
- local part, rPosition = workspace:FindPartOnRay(ray, outline) --(hit) and (position of where the ray hit)
- local nPosition = Vector3.new(grid(rPosition.X, outline), rPosition.Y, grid(rPosition.Z, outline))
- if part then
- terrainLimit = tostring(plr.Team).."Terrain" --example: GreenTerrain
- local check = (rPosition - char.HumanoidRootPart.Position).Magnitude < buildrange
- if part.Name == terrainLimit and (wood.Value > cost)and canBuildF(rPosition, outline) and check then
- outline.Transparency = 0.8
- local posChange = nPosition + Vector3.new(0,(outline.Size.y/2),0)
- outline.Position = posChange
- outline.CFrame = CFrame.new(outline.Position) * CFrame.Angles(0, math.rad(rot), 0) --cframe wants rad
- outline.BrickColor = BrickColor.new("Really blue") --meaning you can build
- canBuild = true --for the other functions
- --
- elseif part:FindFirstChild("Team") ~= nil and check then
- if part.Team.Value == terrainLimit then
- outline.Transparency = 0.5
- local posChange = part.Position + Vector3.new(0,(part.Size.y/2 + outline.Size.y/2),0)
- outline.Position = posChange
- outline.CFrame = CFrame.new(outline.Position) * CFrame.Angles(0, math.rad(rot), 0) --cframe wants rad
- outline.BrickColor = BrickColor.new("Really blue") --meaning you can build
- canBuild = true --for the other functions
- end
- else
- outline.Transparency = 0.25
- outline.Position = nPosition + Vector3.new(0,(outline.Size.y/2),0)
- outline.CFrame = CFrame.new(outline.Position) * CFrame.Angles(0, math.rad(rot), 0) --cframe wants rad
- outline.BrickColor = BrickColor.new("Really red") --meaning you can't build
- canBuild = false
- end
- end
- end
- game:GetService("UserInputService").InputEnded:Connect(function(key, gpe)
- if not gpe and key.KeyCode == Enum.KeyCode.R then --rotational magic
- rot = rot + 90
- if rot >= 360 then
- rot = rot - 360
- end
- end
- end)
- mouse.Button1Up:Connect(function() --activates when clicked
- local outline = camera:FindFirstChild(plr.Name.."_BuildOutline")
- if ingame.Value == true and isBuilding.Value == true and outline then
- if canBuild and terrainLimit and (wood.Value > cost) and debounce then --should be checking for wood as well
- local sPos = outline.Position --send position
- local pass = "Building" --Password/what it needs to do
- local id = 1 --this will not change until we have more block types
- debounce = false
- --print("Click!")
- buildComs:FireServer(pass, sPos, rot, id, woodHP.Value, terrainLimit) --pass pos rot id woodHP, terrainLimit(gotta remember)
- elseif not canBuild then
- print("Sending message that can't build")
- buildMess:Fire("You cannot build in that location, red outline shows this.")
- print("Message fired!")
- end
- end
- end)
- local function datLoop()
- while wait() do
- checkOutline()
- local outline = camera:FindFirstChild(plr.Name.."_BuildOutline")
- if isBuilding.Value == true and outline then
- blockOutline(outline)
- elseif outline then
- outline.Transparency = 1
- else
- warn("Player is missing their outline!")
- end
- if not debounce then
- wait(0.1)
- debounce = true
- end
- end
- end
- coroutine.resume(coroutine.create(datLoop)) --coroutine time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement