Scripting_King

My Script

Aug 10th, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.89 KB | Source Code | 0 0
  1. local TreeHandler = require(game:GetService("ServerStorage").Modules.TreeHandler)
  2. local CollectionService = game:GetService("CollectionService")
  3.  
  4. function getRandomInPart(part)
  5.     local random = Random.new()
  6.     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))
  7.     return randomCFrame
  8. end
  9.  
  10. function GetChildrenWhichAre(parent, class)
  11.     local a = {}
  12.    
  13.     for i,v in pairs(parent:GetChildren()) do
  14.         if v:IsA(class) then
  15.             table.insert(a, v)
  16.         end
  17.     end
  18.    
  19.     return a
  20. end
  21.  
  22.  
  23. local OreZones = {}
  24. local TreeZones = {}
  25.  
  26. local OreChances = {
  27.     Coal = {1, 20},
  28.     Copper = {1, 30},
  29.     Iron = {1, 40},
  30.     Gold = {1, 60},
  31.     Diamond = {1, 80}
  32. }
  33.  
  34. local TreeChances = {
  35.     Wood = {1, 20}
  36. }
  37.  
  38. coroutine.wrap(function()
  39.     while task.wait(10) do
  40.         OreZones = {}
  41.        
  42.         for i,v in pairs(CollectionService:GetTagged("PlacementZoneOre")) do
  43.             v.Transparency = 1
  44.             if v:FindFirstChild("SurfaceGui") then
  45.                 v.SurfaceGui:Destroy()
  46.             end
  47.            
  48.             table.insert(OreZones, v)
  49.         end
  50.        
  51.         TreeZones = {}
  52.  
  53.         for i,v in pairs(CollectionService:GetTagged("PlacementZoneTree")) do
  54.             v.Transparency = 1
  55.             if v:FindFirstChild("SurfaceGui") then
  56.                 v.SurfaceGui:Destroy()
  57.             end
  58.  
  59.             table.insert(TreeZones, v)
  60.         end
  61.     end
  62. end)()
  63.  
  64. coroutine.wrap(function()
  65.     while task.wait(10) do
  66.         -- Ore generator
  67.        
  68.         for i,v in pairs(OreZones) do
  69.             if #GetChildrenWhichAre(v, "BasePart") < 5 then
  70.                 local OreType = v:GetAttribute("Ore")
  71.                 if OreType then
  72.                     local Chance = math.random(OreChances[OreType][1], OreChances[OreType][2])
  73.                     if Chance == 1 then
  74.                         local OreCloneCFrame = getRandomInPart(v)
  75.  
  76.                         local OreClone = game:GetService("ServerStorage").Ores:FindFirstChild(OreType):Clone()
  77.                         if OreClone then
  78.                             OreClone.Parent = v
  79.                             OreClone.CFrame = OreCloneCFrame
  80.                             OreClone.Orientation = Vector3.new(math.random(0, 10), 0, math.random(0, 10))
  81.                         end
  82.                     end
  83.                 end
  84.             end
  85.         end
  86.        
  87.         -- Tree generator
  88.        
  89.         for i,v in pairs(TreeZones) do
  90.             if #GetChildrenWhichAre(v, "Model") < 5 then
  91.                 local TreeType = v:GetAttribute("Tree")
  92.                
  93.                 if TreeType then
  94.                     local Chance = math.random(TreeChances[TreeType][1], TreeChances[TreeType][2])
  95.                     if Chance == 1 then
  96.                         local TreeCloneCFrame = getRandomInPart(v)
  97.  
  98.                         local TreeClone = TreeHandler.new(TreeHandler.Trees[TreeType])
  99.  
  100.                         local TreeModel = TreeClone:Generate(TreeCloneCFrame.Position, workspace, v)
  101.  
  102.                         TreeModel:SetAttribute("Health", 100)
  103.                         TreeModel:SetAttribute("Debounce", false)
  104.                         TreeModel:SetAttribute("Drop", TreeType)
  105.                         TreeModel:SetAttribute("TreeInstance", true)
  106.                         TreeModel.Parent = v
  107.                     end
  108.                 end
  109.             end
  110.         end
  111.        
  112.         -- Stick generator
  113.        
  114.         for i,v in pairs(TreeZones) do
  115.             if v.Name == "TreePlacementZone" then
  116.                 local NumberOfSticks = 0
  117.                 local GetTouchingParts = workspace:GetPartsInPart(v)
  118.                 for i,v in pairs(GetTouchingParts) do
  119.                     if v.Name == "Stick" then
  120.                         NumberOfSticks += 1
  121.                     end
  122.                 end
  123.                
  124.                
  125.                 local Chance = math.random(1, 10)
  126.  
  127.                 if Chance == 1 and NumberOfSticks < 10 then
  128.                     local StickClone = game:GetService("ReplicatedStorage").Items:FindFirstChild("Stick", true):Clone()
  129.                     StickClone.CFrame = getRandomInPart(v) * CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360))
  130.                     StickClone.Parent = workspace.Drops
  131.                 end
  132.            
  133.             end
  134.         end
  135.        
  136.         -- Apple generator :scream:
  137.        
  138.         for i,v in pairs(TreeZones) do
  139.             if v.Name == "TreePlacementZone" then
  140.                 local NumberOfApples = 0
  141.                 local GetTouchingParts = workspace:GetPartsInPart(v)
  142.                 for i,v in pairs(GetTouchingParts) do
  143.                     if v.Name == "Apple" then
  144.                         NumberOfApples += 1
  145.                     end
  146.                 end
  147.  
  148.                 local Chance = math.random(1, 10)
  149.  
  150.                 if Chance == 1 and NumberOfApples < 5 then
  151.                     local AppleClone = game:GetService("ReplicatedStorage").Items:FindFirstChild("Apple", true):Clone()
  152.                     AppleClone.Handle.CFrame = getRandomInPart(v) * CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360))
  153.                     AppleClone.Parent = workspace.Drops
  154.                 end
  155.  
  156.             end
  157.         end
  158.        
  159.         -- Stone Generator
  160.        
  161.         --for i,v in pairs(OreZones) do
  162.         --  if v.Name == "OrePlacementZone" then
  163.         --      local NumberOfStone = 0
  164.         --      local GetTouchingParts = workspace:GetPartsInPart(v)
  165.         --      for i,v in pairs(GetTouchingParts) do
  166.         --          if v.Name == "Stone" then
  167.         --              NumberOfStone += 1
  168.         --          end
  169.         --      end
  170.  
  171.  
  172.         --      local Chance = math.random(1, 8)
  173.  
  174.         --      if Chance == 1 and NumberOfStone < 4 then
  175.         --          local StoneClone = game:GetService("ReplicatedStorage").Items:FindFirstChild("Stone", true):Clone()
  176.         --          StoneClone.CFrame = getRandomInPart(v) * CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360))
  177.         --          StoneClone.Parent = workspace.Drops
  178.         --      end
  179.  
  180.         --  end
  181.         --end
  182.     end
  183. end)()
Add Comment
Please, Sign In to add comment