Advertisement
Guest User

Untitled

a guest
May 26th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. _G.farming = true --Set this to false if you wanna buy seed or do other stuff
  2. _G.seed = "Carrot" --Which seed you want to plant
  3. _G.OutBox = true --Set this to true if you have an outbox
  4.  
  5. --Dunt mess dis down here >:C
  6.  
  7. --// VARS //--
  8. local PlayerData = require(game.ReplicatedStorage:WaitForChild("PlayerData"))
  9. local plr = game:GetService("Players").LocalPlayer
  10. local selling = false
  11.  
  12. --// FUNCTIONS //--
  13. local function fS(func, ...)
  14. assert(type(func) == "function")
  15. local args = {...}
  16. local bindable = Instance.new("BindableEvent")
  17. bindable.Event:Connect(
  18. function()
  19. func(unpack(args))
  20. end
  21. )
  22. bindable:Fire()
  23. bindable:Destroy()
  24. end
  25.  
  26. local function isInTable(table, toFind)
  27. assert(type(table) == "table")
  28. assert(type(toFind) == "string")
  29. local found = false
  30. for _, v in pairs(table) do
  31. if v == toFind then
  32. found = true
  33. break
  34. end
  35. end
  36. return found
  37. end
  38.  
  39. local function sellCrops()
  40. local data = PlayerData.get()
  41. if data.weight > 0 then
  42. selling = not selling
  43. if not _G.OutBox then
  44. plr.Character:MoveTo(Vector3.new(52, 5, -453))
  45. wait(2)
  46. end
  47. for crop, _ in pairs(_G.crops) do
  48. local cropType = crop
  49. local quantity = 0
  50. if cropType and cropType ~= "none" then
  51. quantity = data.crops[cropType]
  52. end
  53. game.ReplicatedStorage.UseMarket:FireServer("SellCrop", cropType, quantity, _G.OutBox)
  54. game.ReplicatedStorage.CropSold:Fire(cropType, quantity, _G.OutBox)
  55. end
  56. selling = not selling
  57. end
  58. end
  59.  
  60. local function useWell()
  61. if selling then
  62. return
  63. end
  64.  
  65. local well = _G.farm:FindFirstChild("Well")
  66.  
  67. local wellPos = well.PrimaryPart.Position
  68. local plrPos = plr.Character.PrimaryPart.Position
  69.  
  70. local distance = (plrPos - wellPos).magnitude
  71.  
  72. if distance >= 14 then
  73. plr.Character:MoveTo(wellPos)
  74. wait(.4)
  75. end
  76. end
  77.  
  78. local function createFarmPlots()
  79. _G.plots = {}
  80. _G.farm = nil
  81.  
  82. for i = 1, 8 do
  83. if
  84. workspace:FindFirstChild("Farm" .. i) ~= nil and
  85. workspace["Farm" .. i]:FindFirstChild("Owner") and
  86. workspace["Farm" .. i].Owner.Value == plr
  87. then
  88. _G.farm = workspace["Farm" .. i]
  89. end
  90. end
  91.  
  92. for i = 1, 6 do
  93. if _G.farm:FindFirstChild("Plot" .. i) ~= nil then
  94. table.insert(_G.plots, _G.farm["Plot" .. i])
  95. end
  96. end
  97. end
  98.  
  99. local function plotFarm(plot)
  100. assert(typeof(plot) == "Instance")
  101. local data = PlayerData.get()
  102.  
  103. for _, v in pairs(plot:GetChildren()) do
  104. if v.Name ~= "Camera1" and v.Name ~= "Camera2" and v.Name ~= "Plot" and v.Name ~= "HasGreenhouse" then
  105. wait()
  106. if v.CropType.Value ~= "none" and _G.crops[v.CropType.Value] == v.CropStage.Value then
  107. game.ReplicatedStorage.ManipulateCrop:FireServer(v, "Harvest")
  108. end
  109. if v.CropType.Value == "none" and data.seeds[_G.seed] then
  110. game.ReplicatedStorage.ManipulateCrop:FireServer(v, "PlantSeed", _G.seed)
  111. end
  112. end
  113. end
  114. end
  115.  
  116. local function plotWater(plot)
  117. assert(typeof(plot) == "Instance")
  118. for _, v in pairs(plot:GetChildren()) do
  119. if v.Name ~= "Camera1" and v.Name ~= "Camera2" and v.Name ~= "Plot" and v.Name ~= "HasGreenhouse" then
  120. wait()
  121. if v.WaterContent.Value <= 2 then
  122. game.ReplicatedStorage.ManipulateCrop:FireServer(v, "Water")
  123. useWell()
  124. game.ReplicatedStorage.UseItem:FireServer(_G.farm:FindFirstChild("Well"))
  125. end
  126. end
  127. end
  128. end
  129.  
  130. local function autoFarm()
  131. while _G.KillSwitch and wait(5) do
  132. if _G.farming then
  133. for _, plot in pairs(_G.plots) do
  134. sellCrops()
  135. fS(plotFarm, plot)
  136. fS(plotWater, plot)
  137. end
  138. end
  139. end
  140. end
  141.  
  142. if _G.farm == nil then
  143. createFarmPlots()
  144. end
  145.  
  146. if not _G.crops or not isInTable(_G.crops, "Hay") then
  147. _G.crops = {}
  148. for _, v in pairs(game:GetService("ReplicatedStorage").Assets.Farming.Crops:GetChildren()) do
  149. _G.crops[v.Name] = #v:GetChildren()
  150. end
  151. end
  152.  
  153. --// INIT //--
  154. _G.KillSwitch = false -- Just in case if someone execute everything
  155. wait(6)
  156. _G.KillSwitch = true -- instead of just changing the _G vars up there
  157.  
  158. autoFarm()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement