Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function PlantHandler.InitializePlant(player, plantFolder, config, plantCircle)
- local circlePos = plantCircle.Position
- local plantCF = CFrame.new(circlePos) * CFrame.Angles(0, math.rad(math.random(-180, 180)), 0)
- local plantScale = math.random(config.MinScale * 100, config.MaxScale * 100)/100
- local mass = config.DefaultMass * plantScale
- mass = math.round(mass * 100)/100
- local plot = plotHandler.GetPlot(player)
- local mutation = determineMutation(plantFolder)
- if plantFolder:FindFirstChild(mutation) then
- plantFolder = plantFolder:FindFirstChild(mutation)
- else
- return nil
- end
- local plantStages = plantFolder:GetChildren()
- table.sort(plantStages, function(a, b)
- local aValue = a:FindFirstChild("Stage").Value
- local bValue = b:FindFirstChild("Stage").Value
- return aValue < bValue
- end)
- local timePerStage = config.GrowTime/(#plantStages + 1)
- local isFullGrown = false
- local currentStage = 0
- local plant = nil
- local finalStage = plantStages[#plantStages]:Clone()
- finalStage.Name = config.DisplayName
- finalStage.Parent = plot.Plants
- finalStage:PivotTo(plantCF)
- scaleModel(finalStage, plantScale)
- local finalStageParts = {}
- for _, part in pairs(finalStage:GetDescendants()) do
- if part:IsA("Part") then
- local defaultTr = part.Transparency
- local defaultCanCollide = part.CanCollide
- finalStageParts[part] = {}
- finalStageParts[part].Transparency = defaultTr
- finalStageParts[part].CanCollide = defaultCanCollide
- part.CanQuery = false
- part.Transparency = 1
- part.CanCollide = false
- end
- end
- if not PlantHandler.Plants[player] then
- PlantHandler.Plants[player] = {}
- end
- PlantHandler.Plants[player][finalStage] = {}
- PlantHandler.Plants[player][finalStage].GrowStartTime = os.time()
- task.spawn(function()
- while not isFullGrown do
- task.wait(timePerStage)
- if currentStage < #plantStages then
- currentStage += 1
- if plantCircle then
- plantCircle:Destroy()
- end
- if plant then
- plant:Destroy()
- end
- if currentStage == #plantStages then
- isFullGrown = true
- for _, part in pairs(finalStage:GetDescendants()) do
- if part:IsA("Part") then
- part.CanQuery = true
- if finalStageParts[part] then
- part.Transparency = finalStageParts[part].Transparency
- part.CanCollide = finalStageParts[part].CanCollide
- end
- end
- end
- else
- plant = plantStages[currentStage]:Clone()
- plant.Parent = plot:FindFirstChild("Plants")
- plant:PivotTo(plantCF * CFrame.new(0, plant.PrimaryPart.Size.Y/2, 0))
- scaleModel(plant, plantScale)
- end
- end
- end
- local harvestPrompt = templates.HarvestPrompt:Clone()
- harvestPrompt.Parent = finalStage
- harvestPrompt.Name = config.DisplayName
- local connection
- connection = harvestPrompt.Triggered:Connect(function(playerWhoTriggered)
- if playerWhoTriggered == player then
- harvestPlant(player, finalStage, mass)
- harvestPrompt:Destroy()
- connection:Disconnect()
- end
- end)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement