Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local BBA = {}
- Paused = script.Parent.Paused.Value
- local Humanoid = script.Parent.Humanoid
- local FoodInArea = 0
- local Population = nil
- BBA.Action = nil
- BBA.Genes = {}
- BBA.Genes.SearchArea = 20
- BBA.Genes.Speed = Humanoid.WalkSpeed
- BBA.Genes.Age = 1
- BBA.Genes.ChanceToShare = 75
- BBA.Genes.Energy = 100
- BBA.Genes.ReproductiveUrge = 5
- BBA.Genes.Food = 30
- BBA.Genes.Standards = 5 -- Max is 5
- BBA.Genes.Desirability = 5 -- Max is 5
- BBA.Genes.Water = 30
- BBA.Genes.Gender = nil
- BBA.Genes.Health = 100
- BBA.Genes.GestationDuration = 5
- BBA.Genes.Pregnant = false
- function BBA:MoveTo(Object, Action)
- local PathfindingService = game:GetService("PathfindingService")
- local Path = PathfindingService:FindPathAsync(script.Parent.HumanoidRootPart.Position, Object.Position)
- local Points = Path:GetWaypoints()
- if Path.Status ~= Enum.PathStatus.Success then return end
- for i, v in pairs(Points) do
- if Paused == false and Object.Parent ~= nil and Action == BBA.Action then
- Humanoid:MoveTo(v.Position)
- elseif Paused == true then
- return
- elseif BBA.Action ~= Action then
- print("Actions dont match")
- end
- end
- end
- function BBA:RequestMate(male)
- print("Message received")
- Paused = true
- BBA.Action = "Mating"
- spawn(function()
- repeat wait() until (male.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).magnitude < 2
- repeat wait() until BBA.Genes.Pregnant == true
- Paused = false
- end)
- end
- function BBA:FindMateInArea()
- for i, v in pairs(workspace.BeanBois:GetChildren()) do
- if (script.Parent.HumanoidRootPart.Position - v.HumanoidRootPart.Position).magnitude < BBA.Genes.SearchArea and require(v.BeanyBoiAI).Genes.Gender ~= BBA.Genes.Gender and require(v.BeanyBoiAI).Genes.Pregnant == false then
- local TargetAI = require(v.BeanyBoiAI)
- repeat wait() until TargetAI.Genes.Gender ~= nil
- if TargetAI.Genes.Gender == "Female" and TargetAI.Genes.Standards >= BBA.Genes.Desirability then
- Paused = true
- TargetAI.Paused = true
- TargetAI:RequestMate(script.Parent)
- print("Male making epic move with epic worminess he tries to impress her")
- BBA:MoveTo(v.HumanoidRootPart, BBA.Action)
- wait(1)
- Paused = false
- BBA.Action = nil
- TargetAI.Genes.Pregnant = true
- wait(TargetAI.Genes.GestationDuration)
- local Babies = math.random(TargetAI.Genes.GestationDuration, TargetAI.Genes.GestationDuration)
- Population = #workspace.BeanBois:GetChildren()
- if Population <= 30 then Babies = Babies * 2 end
- for i = 1, Babies do
- print(i)
- TargetAI.Action = nil
- local bb = game.ReplicatedStorage.BeanBoi:Clone()
- local bbAI = require(bb.BeanyBoiAI)
- bb.Parent = workspace.BeanBois
- spawn(function()
- bbAI:InheritGenes()
- bbAI:Update()
- end)
- end
- elseif TargetAI.Genes.Gender == "Male" and TargetAI.Genes.Standards >= BBA.Genes.Desirability then
- BBA:MoveTo(v.HumanoidRootPart)
- end
- end
- end
- end
- function BBA:Feed(FoodObject)
- FoodObject:Destroy()
- BBA.Genes.Food = 50
- Paused = false
- BBA.Action = nil
- end
- function BBA:Share()
- for i, v in pairs(workspace.BeanBois:GetChildren()) do
- local Target = v
- if (Humanoid.Parent.HumanoidRootPart.Position - v.HumanoidRootPart.Position).magnitude < BBA.Genes.SearchArea and Target == nil and require(v.BeanyBoiAI).Genes.Hunger == 0 and BBA.Genes.ChanceToShare > 25 then
- local TAI = require(Target.BeanyBoiAI)
- local foodgiven = math.random(1, 15)
- TAI.Genes.Food = TAI.Genes.Food + foodgiven
- BBA.Genes.Food = BBA.Genes.Food - foodgiven
- BBA.Action = nil
- end
- end
- end
- function BBA:WanderForFood()
- repeat
- local base = workspace.Baseplate
- local sizeX, sizeZ = base.Size.X/2, base.Size.Z/2
- local randomDisplacement = Vector3.new(math.random(-sizeX, sizeX), 0, math.random(-sizeZ, sizeZ))
- Humanoid:MoveTo(base.CFrame:vectorToWorldSpace(randomDisplacement) + base.Position)
- UpdateFoodArea()
- wait(math.random(1, 5))
- until FoodInArea > 0
- BBA:SearchForFoodInRadius()
- end
- function BBA:SearchForFood()
- for i, v in pairs(workspace.FoodFolder:GetChildren()) do
- if (v.Position - Humanoid.Parent.HumanoidRootPart.Position).magnitude < BBA.Genes.SearchArea then
- BBA:MoveTo(v, BBA.Action)
- wait(5)
- v:Destroy()
- BBA.Genes.Food = BBA.Genes.Food + 20
- Paused = false
- BBA.Action = nil
- BBA.Action = nil
- Paused = false
- end
- end
- Paused = false
- BBA.Action = nil
- end
- function UpdateFoodArea()
- local foodtable = {}
- for i, v in pairs(game.Workspace.FoodFolder:GetChildren()) do
- if (script.Parent.HumanoidRootPart.Position - v.Position).magnitude < BBA.Genes.SearchArea then
- table.insert(foodtable, i, v)
- end
- end
- FoodInArea = #foodtable
- end
- function BBA:InheritGenes()
- local PhysicsService = game:GetService("PhysicsService")
- PhysicsService:SetPartCollisionGroup(script.Parent.HumanoidRootPart, "BB")
- local Males = {}
- local Females = {}
- for i, v in pairs(workspace.BeanBois:GetChildren()) do
- if v ~= script.Parent and require(v.BeanyBoiAI).Genes.Gender == "Female" then
- table.insert(Females, v)
- elseif v~=script.Parent and require(v.BeanyBoiAI).Genes.Gender == "Male" then
- table.insert(Males, v)
- end
- end
- if #Males == 0 or #Males < #Females then
- BBA.Genes.Gender = "Male"
- elseif #Females == 0 or #Females < #Males then
- BBA.Genes.Gender = "Female"
- end
- Population = #game.Workspace.BeanBois:GetChildren()
- UpdateFoodArea()
- if Population <= 30 and FoodInArea >= 30 then
- BBA.Genes.Standards = BBA.Genes.Standards - 0.5
- BBA.Genes.Desirability = BBA.Genes.Desirability + 0.5
- BBA.Genes.Speed = BBA.Genes.Speed + 0.25
- BBA.Genes.SearchArea = BBA.Genes.SearchArea + 0.5
- if BBA.Genes.Gender == "Female" then
- BBA.Genes.GestationDuration = BBA.Genes.GestationDuration - 1
- end
- end
- end
- function BBA:SearchForWater()
- BBA:MoveTo(workspace.Water, BBA.Action)
- BBA.Genes.Water = 50
- wait(5)
- Paused = false
- BBA.Action = nil
- Paused = false
- end
- function CompleteAction()
- if BBA.Action == "SearchForFood" then
- BBA:SearchForFood()
- Paused = false
- elseif BBA.Action == "DrinkWater" then
- BBA:SearchForWater()
- Paused = false
- elseif BBA.Action == "Reproduce" then
- if BBA.Genes.Gender == "Male" then
- Paused = true
- BBA:FindMateInArea()
- Paused = false
- end
- Paused = false
- end
- end
- function BBA:Update()
- if BBA.Genes.Gender == nil then
- BBA:InheritGenes()
- end
- spawn(function()
- while wait(120) do
- BBA.Genes.Age = BBA.Genes.Age + 1
- end
- end)
- spawn(function()
- while wait(60) do
- BBA.Genes.Food = BBA.Genes.Food - 1
- wait(5)
- BBA.Genes.Water = BBA.Genes.Water - 1
- wait(2)
- if BBA.Genes.Pregnant == false and BBA.Genes.ReproductiveUrge ~= 5 then
- BBA.Genes.ReproductiveUrge = BBA.Genes.ReproductiveUrge + 1
- end
- end
- end)
- spawn(function()
- while wait() do
- if BBA.Genes.Food > 50 then BBA.Genes.Food = 50 end
- if BBA.Genes.Water > 50 then BBA.Genes.Water = 50 end
- if BBA.Genes.Food < 0 then BBA.Genes.Food = 0 end
- if BBA.Genes.Water < 0 then BBA.Genes.Water = 0 end
- end
- end)
- while wait() do
- while not Paused do
- Population = #game.Workspace.BeanBois:GetChildren()
- if BBA.Genes.Age > 50 then script.Parent:Destroy() end
- if BBA.Genes.Food < BBA.Genes.Water and BBA.Action == nil then
- BBA.Action = "SearchForFood"
- elseif BBA.Genes.Water < BBA.Genes.Food and BBA.Action == nil then
- BBA.Action = "DrinkWater"
- elseif BBA.Genes.ReproductiveUrge >= 5 and BBA.Action == nil and BBA.Genes.Pregnant == false and BBA.Genes.Gender == "Male" then
- BBA.Action = "Reproduce"
- BBA:FindMateInArea()
- end
- CompleteAction()
- wait()
- end
- end
- end
- return BBA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement