Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _G.farming = true --Set this to false if you wanna buy seed or do other stuff
- _G.seed = "Hay" --Which seed you want to plant
- _G.OutBox = false --Set this to true if you have an outbox
- --Dunt mess dis down here >:C
- --// VARS //--
- local PlayerData = require(game.ReplicatedStorage:WaitForChild("PlayerData"))
- local plr = game:GetService("Players").LocalPlayer
- local selling = false
- --// FUNCTIONS //--
- local function fS(func, ...)
- assert(type(func) == "function")
- local args = {...}
- local bindable = Instance.new("BindableEvent")
- bindable.Event:Connect(
- function()
- func(unpack(args))
- end
- )
- bindable:Fire()
- bindable:Destroy()
- end
- local function isInTable(table, toFind)
- assert(type(table) == "table")
- assert(type(toFind) == "string")
- local found = false
- for _, v in pairs(table) do
- if v == toFind then
- found = true
- break
- end
- end
- return found
- end
- local function sellCrops()
- local data = PlayerData.get()
- if data.weight > 0 then
- selling = not selling
- if not _G.OutBox then
- plr.Character:MoveTo(Vector3.new(52, 5, -453))
- wait(3)
- end
- for crop, _ in pairs(_G.crops) do
- local cropType = crop
- local quantity = 0
- if cropType and cropType ~= "none" then
- quantity = data.crops[cropType]
- end
- game.ReplicatedStorage.UseMarket:FireServer("SellCrop", cropType, quantity, _G.OutBox)
- game.ReplicatedStorage.CropSold:Fire(cropType, quantity, _G.OutBox)
- end
- selling = not selling
- end
- end
- local function useWell()
- if selling then
- return
- end
- local well = _G.farm:FindFirstChild("Well")
- local wellPos = well.PrimaryPart.Position
- local plrPos = plr.Character.PrimaryPart.Position
- local distance = (plrPos - wellPos).magnitude
- if distance >= 14 then
- plr.Character:MoveTo(wellPos)
- wait(.6)
- end
- end
- local function createFarmPlots()
- _G.plots = {}
- _G.farm = nil
- _G.plotSize = 0
- for i = 1, 8 do
- if
- workspace:FindFirstChild("Farm" .. i) and workspace["Farm" .. i]:FindFirstChild("Owner") and
- workspace["Farm" .. i].Owner.Value == plr
- then
- _G.farm = workspace["Farm" .. i]
- end
- end
- for i = 1, 6 do
- if _G.farm:FindFirstChild("Plot" .. i) then
- table.insert(_G.plots, _G.farm["Plot" .. i])
- _G.plotSize = _G.plotSize + #_G.farm["Plot" .. i]:GetChildren()
- end
- end
- _G.farm.ChildAdded:Connect(function©
- _G.plots = {}
- for i = 1, 6 do
- if _G.farm:FindFirstChild("Plot" .. i) then
- table.insert(_G.plots, _G.farm["Plot" .. i])
- _G.plotSize = _G.plotSize + #_G.farm["Plot" .. i]:GetChildren()
- end
- end
- end)
- end
- local function harvest(v)
- local data = PlayerData.get()
- local type = v.CropType.Value
- local stage = v.CropStage.Value
- local reqStage = _G.crops[type]
- if type == "Corn" and reqStage - 1 == stage and data.seeds[type] < _G.plotSize then
- game.ReplicatedStorage.ManipulateCrop:FireServer(v, "Harvest")
- elseif reqStage == stage then
- game.ReplicatedStorage.ManipulateCrop:FireServer(v, "Harvest")
- end
- end
- local function plant(v)
- local data = PlayerData.get()
- if data.seeds[_G.seed] then
- game.ReplicatedStorage.ManipulateCrop:FireServer(v, "PlantSeed", _G.seed)
- end
- end
- local function water(v)
- game.ReplicatedStorage.ManipulateCrop:FireServer(v, "Water")
- useWell()
- game.ReplicatedStorage.UseItem:FireServer(_G.farm:FindFirstChild("Well"))
- end
- local function plotFarm(plot)
- assert(typeof(plot) == "Instance")
- for _, v in pairs(plot:GetChildren()) do
- if v.Name ~= "Camera1" and v.Name ~= "Camera2" and v.Name ~= "Plot" and v.Name ~= "HasGreenhouse" then
- if v.CropType.Value ~= "none" then
- harvest(v)
- else
- plant(v)
- end
- if v.WaterContent.Value <= 2 then
- water(v)
- end
- end
- end
- end
- local function autoFarm()
- while _G.KillSwitch do
- wait(5)
- if _G.farming then
- for _, plot in pairs(_G.plots) do
- fS(sellCrops)
- fS(plotFarm, plot)
- end
- end
- end
- end
- if _G.farm == nil then
- createFarmPlots()
- end
- if not _G.crops or not isInTable(_G.crops, "Hay") then
- _G.crops = {}
- for _, v in pairs(game:GetService("ReplicatedStorage").Assets.Farming.Crops:GetChildren()) do
- _G.crops[v.Name] = #v:GetChildren()
- end
- end
- --// INIT //--
- _G.KillSwitch = false -- Just in case if someone execute everything
- wait(6)
- _G.KillSwitch = true -- instead of just changing the _G vars up there
- autoFarm()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement