Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TreeHandler = require(game:GetService("ServerStorage").Modules.TreeHandler)
- local CollectionService = game:GetService("CollectionService")
- function getRandomInPart(part)
- local random = Random.new()
- local randomCFrame = part.CFrame * CFrame.new(random:NextNumber(-part.Size.X/2,part.Size.X/2), random:NextNumber(-part.Size.Y/2,part.Size.Y/2), random:NextNumber(-part.Size.Z/2,part.Size.Z/2))
- return randomCFrame
- end
- function GetChildrenWhichAre(parent, class)
- local a = {}
- for i,v in pairs(parent:GetChildren()) do
- if v:IsA(class) then
- table.insert(a, v)
- end
- end
- return a
- end
- local OreZones = {}
- local TreeZones = {}
- local OreChances = {
- Coal = {1, 20},
- Copper = {1, 30},
- Iron = {1, 40},
- Gold = {1, 60},
- Diamond = {1, 80}
- }
- local TreeChances = {
- Wood = {1, 20}
- }
- coroutine.wrap(function()
- while task.wait(10) do
- OreZones = {}
- for i,v in pairs(CollectionService:GetTagged("PlacementZoneOre")) do
- v.Transparency = 1
- if v:FindFirstChild("SurfaceGui") then
- v.SurfaceGui:Destroy()
- end
- table.insert(OreZones, v)
- end
- TreeZones = {}
- for i,v in pairs(CollectionService:GetTagged("PlacementZoneTree")) do
- v.Transparency = 1
- if v:FindFirstChild("SurfaceGui") then
- v.SurfaceGui:Destroy()
- end
- table.insert(TreeZones, v)
- end
- end
- end)()
- coroutine.wrap(function()
- while task.wait(10) do
- -- Ore generator
- for i,v in pairs(OreZones) do
- if #GetChildrenWhichAre(v, "BasePart") < 5 then
- local OreType = v:GetAttribute("Ore")
- if OreType then
- local Chance = math.random(OreChances[OreType][1], OreChances[OreType][2])
- if Chance == 1 then
- local OreCloneCFrame = getRandomInPart(v)
- local OreClone = game:GetService("ServerStorage").Ores:FindFirstChild(OreType):Clone()
- if OreClone then
- OreClone.Parent = v
- OreClone.CFrame = OreCloneCFrame
- OreClone.Orientation = Vector3.new(math.random(0, 10), 0, math.random(0, 10))
- end
- end
- end
- end
- end
- -- Tree generator
- for i,v in pairs(TreeZones) do
- if #GetChildrenWhichAre(v, "Model") < 5 then
- local TreeType = v:GetAttribute("Tree")
- if TreeType then
- local Chance = math.random(TreeChances[TreeType][1], TreeChances[TreeType][2])
- if Chance == 1 then
- local TreeCloneCFrame = getRandomInPart(v)
- local TreeClone = TreeHandler.new(TreeHandler.Trees[TreeType])
- local TreeModel = TreeClone:Generate(TreeCloneCFrame.Position, workspace, v)
- TreeModel:SetAttribute("Health", 100)
- TreeModel:SetAttribute("Debounce", false)
- TreeModel:SetAttribute("Drop", TreeType)
- TreeModel:SetAttribute("TreeInstance", true)
- TreeModel.Parent = v
- end
- end
- end
- end
- -- Stick generator
- for i,v in pairs(TreeZones) do
- if v.Name == "TreePlacementZone" then
- local NumberOfSticks = 0
- local GetTouchingParts = workspace:GetPartsInPart(v)
- for i,v in pairs(GetTouchingParts) do
- if v.Name == "Stick" then
- NumberOfSticks += 1
- end
- end
- local Chance = math.random(1, 10)
- if Chance == 1 and NumberOfSticks < 10 then
- local StickClone = game:GetService("ReplicatedStorage").Items:FindFirstChild("Stick", true):Clone()
- StickClone.CFrame = getRandomInPart(v) * CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360))
- StickClone.Parent = workspace.Drops
- end
- end
- end
- -- Apple generator :scream:
- for i,v in pairs(TreeZones) do
- if v.Name == "TreePlacementZone" then
- local NumberOfApples = 0
- local GetTouchingParts = workspace:GetPartsInPart(v)
- for i,v in pairs(GetTouchingParts) do
- if v.Name == "Apple" then
- NumberOfApples += 1
- end
- end
- local Chance = math.random(1, 10)
- if Chance == 1 and NumberOfApples < 5 then
- local AppleClone = game:GetService("ReplicatedStorage").Items:FindFirstChild("Apple", true):Clone()
- AppleClone.Handle.CFrame = getRandomInPart(v) * CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360))
- AppleClone.Parent = workspace.Drops
- end
- end
- end
- -- Stone Generator
- --for i,v in pairs(OreZones) do
- -- if v.Name == "OrePlacementZone" then
- -- local NumberOfStone = 0
- -- local GetTouchingParts = workspace:GetPartsInPart(v)
- -- for i,v in pairs(GetTouchingParts) do
- -- if v.Name == "Stone" then
- -- NumberOfStone += 1
- -- end
- -- end
- -- local Chance = math.random(1, 8)
- -- if Chance == 1 and NumberOfStone < 4 then
- -- local StoneClone = game:GetService("ReplicatedStorage").Items:FindFirstChild("Stone", true):Clone()
- -- StoneClone.CFrame = getRandomInPart(v) * CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360))
- -- StoneClone.Parent = workspace.Drops
- -- end
- -- end
- --end
- end
- end)()
Add Comment
Please, Sign In to add comment