Advertisement
MooBoi

Untitled

Aug 13th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.14 KB | None | 0 0
  1. local BBA = {}
  2. Paused = script.Parent.Paused.Value
  3. local Humanoid = script.Parent.Humanoid
  4. local FoodInArea = 0
  5. local Population = nil
  6. BBA.Action = nil
  7. BBA.Genes = {}
  8. BBA.Genes.SearchArea = 20
  9. BBA.Genes.Speed = Humanoid.WalkSpeed
  10. BBA.Genes.Age = 1
  11. BBA.Genes.ChanceToShare = 75
  12. BBA.Genes.Energy = 100
  13. BBA.Genes.ReproductiveUrge = 5
  14. BBA.Genes.Food = 30
  15. BBA.Genes.Standards = 5 -- Max is 5
  16. BBA.Genes.Desirability = 5 -- Max is 5
  17. BBA.Genes.Water = 30
  18. BBA.Genes.Gender = nil
  19. BBA.Genes.Health = 100
  20. BBA.Genes.GestationDuration = 5
  21. BBA.Genes.Pregnant = false
  22. function BBA:MoveTo(Object, Action)
  23.  
  24. local PathfindingService = game:GetService("PathfindingService")
  25. local Path = PathfindingService:FindPathAsync(script.Parent.HumanoidRootPart.Position, Object.Position)
  26. local Points = Path:GetWaypoints()
  27.  
  28. if Path.Status ~= Enum.PathStatus.Success then return end
  29.  
  30. for i, v in pairs(Points) do
  31.  
  32. if Paused == false and Object.Parent ~= nil and Action == BBA.Action then
  33.  
  34. Humanoid:MoveTo(v.Position)
  35.  
  36. elseif Paused == true then
  37.  
  38. return
  39.  
  40. elseif BBA.Action ~= Action then
  41.  
  42. print("Actions dont match")
  43.  
  44. end
  45.  
  46. end
  47.  
  48. end
  49.  
  50. function BBA:RequestMate(male)
  51.  
  52. print("Message received")
  53. Paused = true
  54. BBA.Action = "Mating"
  55. spawn(function()
  56.  
  57. repeat wait() until (male.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).magnitude < 2
  58. repeat wait() until BBA.Genes.Pregnant == true
  59. Paused = false
  60.  
  61. end)
  62.  
  63. end
  64.  
  65. function BBA:FindMateInArea()
  66.  
  67. for i, v in pairs(workspace.BeanBois:GetChildren()) do
  68.  
  69. 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
  70.  
  71. local TargetAI = require(v.BeanyBoiAI)
  72.  
  73. repeat wait() until TargetAI.Genes.Gender ~= nil
  74. if TargetAI.Genes.Gender == "Female" and TargetAI.Genes.Standards >= BBA.Genes.Desirability then
  75.  
  76. Paused = true
  77. TargetAI.Paused = true
  78. TargetAI:RequestMate(script.Parent)
  79. print("Male making epic move with epic worminess he tries to impress her")
  80. BBA:MoveTo(v.HumanoidRootPart, BBA.Action)
  81. wait(1)
  82. Paused = false
  83. BBA.Action = nil
  84. TargetAI.Genes.Pregnant = true
  85. wait(TargetAI.Genes.GestationDuration)
  86. local Babies = math.random(TargetAI.Genes.GestationDuration, TargetAI.Genes.GestationDuration)
  87. Population = #workspace.BeanBois:GetChildren()
  88. if Population <= 30 then Babies = Babies * 2 end
  89. for i = 1, Babies do
  90.  
  91. print(i)
  92. TargetAI.Action = nil
  93. local bb = game.ReplicatedStorage.BeanBoi:Clone()
  94. local bbAI = require(bb.BeanyBoiAI)
  95. bb.Parent = workspace.BeanBois
  96. spawn(function()
  97.  
  98. bbAI:InheritGenes()
  99. bbAI:Update()
  100.  
  101. end)
  102.  
  103. end
  104.  
  105. elseif TargetAI.Genes.Gender == "Male" and TargetAI.Genes.Standards >= BBA.Genes.Desirability then
  106.  
  107. BBA:MoveTo(v.HumanoidRootPart)
  108.  
  109. end
  110.  
  111. end
  112.  
  113. end
  114.  
  115. end
  116.  
  117. function BBA:Feed(FoodObject)
  118.  
  119. FoodObject:Destroy()
  120. BBA.Genes.Food = 50
  121. Paused = false
  122. BBA.Action = nil
  123.  
  124. end
  125.  
  126. function BBA:Share()
  127.  
  128. for i, v in pairs(workspace.BeanBois:GetChildren()) do
  129.  
  130. local Target = v
  131. 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
  132.  
  133. local TAI = require(Target.BeanyBoiAI)
  134. local foodgiven = math.random(1, 15)
  135. TAI.Genes.Food = TAI.Genes.Food + foodgiven
  136. BBA.Genes.Food = BBA.Genes.Food - foodgiven
  137. BBA.Action = nil
  138.  
  139. end
  140.  
  141. end
  142.  
  143. end
  144.  
  145. function BBA:WanderForFood()
  146. repeat
  147. local base = workspace.Baseplate
  148. local sizeX, sizeZ = base.Size.X/2, base.Size.Z/2
  149. local randomDisplacement = Vector3.new(math.random(-sizeX, sizeX), 0, math.random(-sizeZ, sizeZ))
  150. Humanoid:MoveTo(base.CFrame:vectorToWorldSpace(randomDisplacement) + base.Position)
  151. UpdateFoodArea()
  152. wait(math.random(1, 5))
  153. until FoodInArea > 0
  154.  
  155. BBA:SearchForFoodInRadius()
  156.  
  157. end
  158.  
  159. function BBA:SearchForFood()
  160.  
  161. for i, v in pairs(workspace.FoodFolder:GetChildren()) do
  162.  
  163. if (v.Position - Humanoid.Parent.HumanoidRootPart.Position).magnitude < BBA.Genes.SearchArea then
  164.  
  165. BBA:MoveTo(v, BBA.Action)
  166. wait(5)
  167. v:Destroy()
  168. BBA.Genes.Food = BBA.Genes.Food + 20
  169. Paused = false
  170. BBA.Action = nil
  171. BBA.Action = nil
  172. Paused = false
  173.  
  174. end
  175.  
  176. end
  177.  
  178. Paused = false
  179. BBA.Action = nil
  180.  
  181. end
  182.  
  183. function UpdateFoodArea()
  184.  
  185. local foodtable = {}
  186. for i, v in pairs(game.Workspace.FoodFolder:GetChildren()) do
  187. if (script.Parent.HumanoidRootPart.Position - v.Position).magnitude < BBA.Genes.SearchArea then
  188. table.insert(foodtable, i, v)
  189. end
  190. end
  191.  
  192. FoodInArea = #foodtable
  193.  
  194. end
  195.  
  196. function BBA:InheritGenes()
  197.  
  198. local PhysicsService = game:GetService("PhysicsService")
  199. PhysicsService:SetPartCollisionGroup(script.Parent.HumanoidRootPart, "BB")
  200.  
  201. local Males = {}
  202. local Females = {}
  203. for i, v in pairs(workspace.BeanBois:GetChildren()) do
  204.  
  205. if v ~= script.Parent and require(v.BeanyBoiAI).Genes.Gender == "Female" then
  206. table.insert(Females, v)
  207. elseif v~=script.Parent and require(v.BeanyBoiAI).Genes.Gender == "Male" then
  208. table.insert(Males, v)
  209. end
  210.  
  211. end
  212.  
  213. if #Males == 0 or #Males < #Females then
  214.  
  215. BBA.Genes.Gender = "Male"
  216.  
  217. elseif #Females == 0 or #Females < #Males then
  218.  
  219. BBA.Genes.Gender = "Female"
  220.  
  221. end
  222.  
  223. Population = #game.Workspace.BeanBois:GetChildren()
  224. UpdateFoodArea()
  225. if Population <= 30 and FoodInArea >= 30 then
  226.  
  227. BBA.Genes.Standards = BBA.Genes.Standards - 0.5
  228. BBA.Genes.Desirability = BBA.Genes.Desirability + 0.5
  229. BBA.Genes.Speed = BBA.Genes.Speed + 0.25
  230. BBA.Genes.SearchArea = BBA.Genes.SearchArea + 0.5
  231.  
  232. if BBA.Genes.Gender == "Female" then
  233.  
  234. BBA.Genes.GestationDuration = BBA.Genes.GestationDuration - 1
  235.  
  236. end
  237.  
  238. end
  239.  
  240. end
  241.  
  242. function BBA:SearchForWater()
  243.  
  244. BBA:MoveTo(workspace.Water, BBA.Action)
  245. BBA.Genes.Water = 50
  246. wait(5)
  247. Paused = false
  248. BBA.Action = nil
  249. Paused = false
  250.  
  251. end
  252.  
  253. function CompleteAction()
  254.  
  255. if BBA.Action == "SearchForFood" then
  256.  
  257. BBA:SearchForFood()
  258. Paused = false
  259.  
  260. elseif BBA.Action == "DrinkWater" then
  261.  
  262. BBA:SearchForWater()
  263. Paused = false
  264.  
  265. elseif BBA.Action == "Reproduce" then
  266.  
  267. if BBA.Genes.Gender == "Male" then
  268.  
  269. Paused = true
  270. BBA:FindMateInArea()
  271. Paused = false
  272.  
  273. end
  274.  
  275. Paused = false
  276.  
  277. end
  278.  
  279. end
  280.  
  281. function BBA:Update()
  282.  
  283. if BBA.Genes.Gender == nil then
  284.  
  285. BBA:InheritGenes()
  286.  
  287. end
  288.  
  289. spawn(function()
  290.  
  291. while wait(120) do
  292.  
  293. BBA.Genes.Age = BBA.Genes.Age + 1
  294.  
  295. end
  296.  
  297. end)
  298.  
  299. spawn(function()
  300.  
  301. while wait(60) do
  302.  
  303. BBA.Genes.Food = BBA.Genes.Food - 1
  304. wait(5)
  305. BBA.Genes.Water = BBA.Genes.Water - 1
  306. wait(2)
  307. if BBA.Genes.Pregnant == false and BBA.Genes.ReproductiveUrge ~= 5 then
  308.  
  309. BBA.Genes.ReproductiveUrge = BBA.Genes.ReproductiveUrge + 1
  310.  
  311. end
  312.  
  313. end
  314.  
  315. end)
  316.  
  317. spawn(function()
  318.  
  319. while wait() do
  320.  
  321. if BBA.Genes.Food > 50 then BBA.Genes.Food = 50 end
  322. if BBA.Genes.Water > 50 then BBA.Genes.Water = 50 end
  323. if BBA.Genes.Food < 0 then BBA.Genes.Food = 0 end
  324. if BBA.Genes.Water < 0 then BBA.Genes.Water = 0 end
  325.  
  326. end
  327.  
  328. end)
  329.  
  330. while wait() do
  331.  
  332. while not Paused do
  333.  
  334. Population = #game.Workspace.BeanBois:GetChildren()
  335.  
  336. if BBA.Genes.Age > 50 then script.Parent:Destroy() end
  337.  
  338. if BBA.Genes.Food < BBA.Genes.Water and BBA.Action == nil then
  339.  
  340. BBA.Action = "SearchForFood"
  341.  
  342. elseif BBA.Genes.Water < BBA.Genes.Food and BBA.Action == nil then
  343.  
  344. BBA.Action = "DrinkWater"
  345.  
  346. elseif BBA.Genes.ReproductiveUrge >= 5 and BBA.Action == nil and BBA.Genes.Pregnant == false and BBA.Genes.Gender == "Male" then
  347.  
  348. BBA.Action = "Reproduce"
  349. BBA:FindMateInArea()
  350.  
  351. end
  352.  
  353. CompleteAction()
  354.  
  355. wait()
  356.  
  357. end
  358.  
  359. end
  360.  
  361. end
  362.  
  363. return BBA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement