Roblox-Bot-Lua/Main/GaG/CompleteFarmSystem.lua
2025-07-21 10:41:54 +07:00

1177 lines
39 KiB
Lua

-- Complete Farm System - ระบบฟาร์มแบบเต็มรูปแบบ
-- รวมการเดิน เก็บ ปลูก ขาย และเลี้ยงสัตว์
print("🌱 Loading Complete Farm System...")
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local Leaderstats = LocalPlayer:WaitForChild("leaderstats")
local Backpack = LocalPlayer:WaitForChild("Backpack")
print("✅ Services loaded")
-- ป้องกันการรันซ้ำ
if _G.CompleteFarmSystemLoaded then
print("⚠️ Complete Farm System already loaded, removing old one...")
if _G.CompleteFarmSystemUI then
_G.CompleteFarmSystemUI:Destroy()
end
end
_G.CompleteFarmSystemLoaded = true
-- Game Objects
local GameEvents = ReplicatedStorage:WaitForChild("GameEvents")
local Farms = workspace:WaitForChild("Farm")
print("✅ Game objects found")
-- Complete Farm Settings
local FarmSettings = {
-- Auto Farm Settings
AutoWalk = true,
AutoHarvest = true,
AutoPlant = true,
AutoSell = true,
AutoBuySeeds = true,
AutoHatchEgg = true,
AutoFeedPets = true,
AutoBuyEggs = true,
-- Walk Settings
WalkSpeed = "ปกติ",
WalkRandomness = true,
WalkRadius = 20,
WalkInterval = 5, -- เดินทุก 5 วินาที
-- Harvest Settings
HarvestDelay = 1, -- เก็บ 1 วินาที
HarvestUntilFull = true, -- เก็บจนเต็มกระเป๋า
MaxInventorySlots = 200,
HarvestAll = true,
-- Plant Settings
SelectedSeed = "Carrot", -- เมล็ดปกติ
PlantRandom = true,
PlantInterval = 10, -- ปลูกทุก 10 วินาที
MaxPlantsPerLoop = 20,
-- Sell Settings
SellWhenFull = true, -- ขายเมื่อเต็มกระเป๋า
SellThreshold = 80, -- ขายเมื่อเหลือ 80%
SellDelay = 0.5,
-- Buy Seeds Settings
BuyRareSeeds = true, -- ซื้อเมล็ดหายาก
RareSeeds = {"Tomato", "Corn", "Wheat", "Potato"},
BuyInterval = 60, -- ซื้อทุก 1 นาที
-- Pet Settings
SelectedEggType = "Common Egg",
MaxPetsToHatch = 5,
HatchInterval = 30, -- ฟักไข่ทุก 30 วินาที
FeedInterval = 60, -- ให้อาหารทุก 60 วินาที
BuyEggInterval = 120, -- ซื้อไข่ทุก 2 นาที
PetGrowthTime = 300, -- เวลาให้สัตว์โต 5 นาที
-- Performance Settings
UseSmoothAnimations = true,
AnimationDuration = 0.5,
UseThreading = true,
MaxThreads = 4
}
-- Performance Variables
local IsWalking = false
local IsHarvesting = false
local IsPlanting = false
local IsSelling = false
local IsBuying = false
local IsProcessingPets = false
local LastWalkTime = 0
local LastHarvestTime = 0
local LastPlantTime = 0
local LastSellTime = 0
local LastBuyTime = 0
local LastHatchTime = 0
local LastFeedTime = 0
local LastBuyEggTime = 0
-- Pet Data
local PetEggTypes = {
["Common Egg"] = { HatchTime = 600, Price = 100, GrowthTime = 300 },
["Uncommon Egg"] = { HatchTime = 1200, Price = 500, GrowthTime = 600 },
["Rare Egg"] = { HatchTime = 7200, Price = 2500, GrowthTime = 1800 },
["Legendary Egg"] = { HatchTime = 14400, Price = 10000, GrowthTime = 3600 },
["Mythical Egg"] = { HatchTime = 18400, Price = 50000, GrowthTime = 7200 }
}
local PetEvents = {}
-- Find Player's Farm
local function GetFarm(PlayerName)
local AllFarms = Farms:GetChildren()
for _, Farm in pairs(AllFarms) do
local Important = Farm:FindFirstChild("Important")
if Important then
local Data = Important:FindFirstChild("Data")
if Data then
local Owner = Data:FindFirstChild("Owner")
if Owner and Owner.Value == PlayerName then
return Farm
end
end
end
end
return nil
end
local MyFarm = GetFarm(LocalPlayer.Name)
if not MyFarm then
warn("❌ Cannot find player's farm!")
game:GetService("StarterGui"):SetCore("SendNotification", {
Title = "Complete Farm System",
Text = "ไม่พบฟาร์มของคุณ!",
Duration = 5
})
return
end
print("✅ Found player farm: " .. MyFarm.Name)
local MyImportant = MyFarm:FindFirstChild("Important")
local PlantLocations = MyImportant:FindFirstChild("Plant_Locations")
local PlantsPhysical = MyImportant:FindFirstChild("Plants_Physical")
-- Helper Functions
local function GetArea(Base)
local Center = Base:GetPivot()
local Size = Base.Size
local X1 = math.ceil(Center.X - (Size.X/2))
local Z1 = math.ceil(Center.Z - (Size.Z/2))
local X2 = math.floor(Center.X + (Size.X/2))
local Z2 = math.floor(Center.Z + (Size.Z/2))
return X1, Z1, X2, Z2
end
local Dirt = PlantLocations:FindFirstChildOfClass("Part")
local X1, Z1, X2, Z2 = GetArea(Dirt)
local FarmCenter = Vector3.new((X1 + X2) / 2, 4, (Z1 + Z2) / 2)
-- Find Pet Events
local function FindPetEvents()
print("🔍 ค้นหา Pet RemoteEvents...")
for _, obj in pairs(ReplicatedStorage:GetDescendants()) do
if obj:IsA("RemoteEvent") or obj:IsA("RemoteFunction") then
local name = obj.Name:lower()
if name:find("pet") or name:find("egg") or name:find("hatch") or
name:find("feed") or name:find("animal") or name:find("equip") or
name:find("buy") or name:find("sell") or name:find("spawn") then
PetEvents[obj.Name] = obj
print("🐾 พบ Pet Event: " .. obj.Name)
end
end
end
if next(PetEvents) == nil then
print("⚠️ ไม่พบ Pet Events เฉพาะ จะใช้ GameEvents แทน")
local possibleEvents = {
"HatchEgg", "FeedPet", "BuyEgg", "EquipPet", "UnequipPet", "SellPet",
"Hatch", "Feed", "Buy", "Equip", "Unequip", "Sell"
}
for _, eventName in pairs(possibleEvents) do
local event = GameEvents:FindFirstChild(eventName)
if event then
PetEvents[eventName] = event
print("🐾 พบ GameEvent: " .. eventName)
end
end
end
end
FindPetEvents()
-- Walk Functions
local function GetRandomWalkPoint()
local Character = LocalPlayer.Character
if not Character then return nil end
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then return nil end
local currentPos = HumanoidRootPart.Position
local angle = math.random() * math.pi * 2
local distance = math.random(5, FarmSettings.WalkRadius)
local newX = FarmCenter.X + math.cos(angle) * distance
local newZ = FarmCenter.Z + math.sin(angle) * distance
newX = math.max(X1, math.min(X2, newX))
newZ = math.max(Z1, math.min(Z2, newZ))
return Vector3.new(newX, 4, newZ)
end
local function AutoWalkLoop()
if not FarmSettings.AutoWalk or IsWalking then return end
local currentTime = tick()
if (currentTime - LastWalkTime) < FarmSettings.WalkInterval then return end
local Character = LocalPlayer.Character
if not Character then return end
local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if not Humanoid or not HumanoidRootPart then return end
IsWalking = true
local targetPos = GetRandomWalkPoint()
if targetPos then
print("🚶 เดินไปที่: " .. string.format("%.1f, %.1f, %.1f", targetPos.X, targetPos.Y, targetPos.Z))
pcall(function()
Humanoid:MoveTo(targetPos)
end)
spawn(function()
local timeout = 0
while timeout < 30 and _G.CompleteFarmSystemLoaded and FarmSettings.AutoWalk do
if not HumanoidRootPart.Parent then break end
local currentPos = HumanoidRootPart.Position
local distance = (currentPos - targetPos).Magnitude
if distance < 8 then
print("✅ เดินถึงจุดหมาย")
break
end
timeout = timeout + 1
wait(0.3)
end
end)
end
LastWalkTime = currentTime
IsWalking = false
end
-- Harvest Functions
local function GetHarvestablePlants()
local Plants = {}
local function CollectHarvestable(Parent)
for _, Plant in pairs(Parent:GetChildren()) do
local Fruits = Plant:FindFirstChild("Fruits")
if Fruits then
CollectHarvestable(Fruits)
end
local Prompt = Plant:FindFirstChild("ProximityPrompt", true)
if Prompt and Prompt.Enabled then
table.insert(Plants, Plant)
end
end
end
CollectHarvestable(PlantsPhysical)
if FarmSettings.HarvestAll then
for _, Farm in pairs(Farms:GetChildren()) do
if Farm ~= MyFarm then
local OtherPlantsPhysical = Farm:FindFirstChild("Important")
if OtherPlantsPhysical then
OtherPlantsPhysical = OtherPlantsPhysical:FindFirstChild("Plants_Physical")
if OtherPlantsPhysical then
CollectHarvestable(OtherPlantsPhysical)
end
end
end
end
end
return Plants
end
local function HarvestPlant(Plant)
local Prompt = Plant:FindFirstChild("ProximityPrompt", true)
if Prompt and Prompt.Enabled then
fireproximityprompt(Prompt)
return true
end
return false
end
local function GetTotalInventoryCount()
local totalCount = 0
local Character = LocalPlayer.Character
local function CountFromParent(Parent)
for _, Tool in pairs(Parent:GetChildren()) do
if Tool:IsA("Tool") then
totalCount = totalCount + 1
end
end
end
CountFromParent(Backpack)
if Character then
CountFromParent(Character)
end
return totalCount
end
local function AutoHarvestLoop()
if not FarmSettings.AutoHarvest or IsHarvesting then return end
local currentTime = tick()
if (currentTime - LastHarvestTime) < FarmSettings.HarvestDelay then return end
local currentCount = GetTotalInventoryCount()
if currentCount >= FarmSettings.MaxInventorySlots then
print("🎒 กระเป๋าเต็มแล้ว! (" .. currentCount .. "/" .. FarmSettings.MaxInventorySlots .. ")")
return
end
local Plants = GetHarvestablePlants()
if #Plants == 0 then return end
print("🚜 เริ่มเก็บ " .. #Plants .. " ต้น")
IsHarvesting = true
local harvested = 0
for _, Plant in pairs(Plants) do
if not FarmSettings.AutoHarvest then break end
local newCount = GetTotalInventoryCount()
if newCount >= FarmSettings.MaxInventorySlots then
print("🎒 กระเป๋าเต็มแล้ว! หยุดเก็บ")
break
end
if HarvestPlant(Plant) then
harvested = harvested + 1
end
wait(0.1) -- ดีเลย์เล็กน้อย
end
if harvested > 0 then
print("✅ เก็บสำเร็จ " .. harvested .. " ต้น")
end
LastHarvestTime = currentTime
IsHarvesting = false
end
-- Plant Functions
local function GetOwnedSeeds()
local Seeds = {}
local Character = LocalPlayer.Character
local function CollectFromParent(Parent)
for _, Tool in pairs(Parent:GetChildren()) do
if Tool:IsA("Tool") then
local PlantName = Tool:FindFirstChild("Plant_Name")
local Count = Tool:FindFirstChild("Numbers")
if PlantName and Count then
Seeds[PlantName.Value] = {
Count = Count.Value,
Tool = Tool
}
end
end
end
end
CollectFromParent(Backpack)
if Character then
CollectFromParent(Character)
end
return Seeds
end
local function Plant(Position, Seed)
local PlantEvent = GameEvents:FindFirstChild("Plant_RE")
if PlantEvent then
PlantEvent:FireServer(Position, Seed)
wait(0.3)
return true
end
return false
end
local function AutoPlantLoop()
if not FarmSettings.AutoPlant or IsPlanting then return end
local currentTime = tick()
if (currentTime - LastPlantTime) < FarmSettings.PlantInterval then return end
local OwnedSeeds = GetOwnedSeeds()
local SeedData = OwnedSeeds[FarmSettings.SelectedSeed]
if not SeedData or SeedData.Count <= 0 then
print("⚠️ ไม่มีเมล็ด " .. FarmSettings.SelectedSeed .. " ให้ปลูก")
return
end
local Count = SeedData.Count
local Tool = SeedData.Tool
local Character = LocalPlayer.Character
if Character and Tool.Parent == Backpack then
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:EquipTool(Tool)
wait(0.5)
end
end
IsPlanting = true
local Planted = 0
if FarmSettings.PlantRandom then
local FarmLands = PlantLocations:GetChildren()
for i = 1, math.min(Count, FarmSettings.MaxPlantsPerLoop) do
if not FarmSettings.AutoPlant then break end
local FarmLand = FarmLands[math.random(1, #FarmLands)]
local LX1, LZ1, LX2, LZ2 = GetArea(FarmLand)
local X = math.random(LX1, LX2)
local Z = math.random(LZ1, LZ2)
local Point = Vector3.new(X, 4, Z)
if Plant(Point, FarmSettings.SelectedSeed) then
Planted = Planted + 1
end
end
else
for X = X1, X2, 2 do
for Z = Z1, Z2, 2 do
if Planted >= math.min(Count, FarmSettings.MaxPlantsPerLoop) or not FarmSettings.AutoPlant then break end
local Point = Vector3.new(X, 0.13, Z)
if Plant(Point, FarmSettings.SelectedSeed) then
Planted = Planted + 1
wait(0.1)
end
end
if Planted >= math.min(Count, FarmSettings.MaxPlantsPerLoop) or not FarmSettings.AutoPlant then break end
end
end
if Planted > 0 then
print("🌱 ปลูก " .. Planted .. " เมล็ด " .. FarmSettings.SelectedSeed)
end
LastPlantTime = currentTime
IsPlanting = false
end
-- Sell Functions
local function SellInventory()
if IsSelling then return false end
IsSelling = true
local Character = LocalPlayer.Character
if not Character then
IsSelling = false
return false
end
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then
IsSelling = false
return false
end
local Previous = HumanoidRootPart.CFrame
local ShecklesCount = Leaderstats:FindFirstChild("Sheckles")
print("💰 เริ่มขายของ...")
HumanoidRootPart.CFrame = CFrame.new(62, 4, -26)
wait(FarmSettings.SellDelay)
local soldAmount = 0
local previousSheckles = ShecklesCount and ShecklesCount.Value or 0
if ShecklesCount then
local SellEvent = GameEvents:FindFirstChild("Sell_Inventory")
if SellEvent then
SellEvent:FireServer()
wait(FarmSettings.SellDelay)
if ShecklesCount.Value ~= previousSheckles then
soldAmount = ShecklesCount.Value - previousSheckles
print("💰 ขายสำเร็จ! ได้เงิน " .. soldAmount .. " sheckles")
else
print("⚠️ ขายไม่สำเร็จ")
end
else
print("❌ ไม่พบ Sell Event")
end
end
HumanoidRootPart.CFrame = Previous
wait(0.2)
IsSelling = false
return soldAmount > 0
end
local function AutoSellLoop()
if not FarmSettings.AutoSell or IsSelling then return end
local currentTime = tick()
if (currentTime - LastSellTime) < 5 then return end
local totalItems = GetTotalInventoryCount()
if FarmSettings.SellWhenFull and totalItems >= FarmSettings.MaxInventorySlots then
print("💰 กระเป๋าเต็ม! เริ่มขาย (" .. totalItems .. "/" .. FarmSettings.MaxInventorySlots .. ")")
SellInventory()
LastSellTime = currentTime
elseif totalItems >= (FarmSettings.MaxInventorySlots * FarmSettings.SellThreshold / 100) then
print("💰 ถึงเกณฑ์ขาย! เริ่มขาย (" .. totalItems .. "/" .. FarmSettings.MaxInventorySlots .. ")")
SellInventory()
LastSellTime = currentTime
end
end
-- Buy Seeds Functions
local function BuySeed(SeedName)
local BuyEvent = GameEvents:FindFirstChild("BuySeedStock")
if BuyEvent then
BuyEvent:FireServer(SeedName)
wait(0.5)
return true
end
return false
end
local function AutoBuySeedsLoop()
if not FarmSettings.AutoBuySeeds or IsBuying then return end
local currentTime = tick()
if (currentTime - LastBuyTime) < FarmSettings.BuyInterval then return end
if FarmSettings.BuyRareSeeds then
for _, seedName in pairs(FarmSettings.RareSeeds) do
print("🛒 กำลังซื้อเมล็ดหายาก: " .. seedName)
if BuySeed(seedName) then
print("✅ ซื้อเมล็ดสำเร็จ: " .. seedName)
else
print("❌ ซื้อเมล็ดไม่สำเร็จ: " .. seedName)
end
wait(1)
end
end
LastBuyTime = currentTime
IsBuying = false
end
-- Pet Functions
local function GetAllPets()
local pets = {}
local Character = LocalPlayer.Character
local function isPetTool(tool)
if not tool:IsA("Tool") then return false end
local indicators = {
"PetData", "Pet_Data", "PetInfo", "Pet_Info",
"AnimalData", "Animal_Data", "CreatureData",
"IsPet", "Pet", "Animal", "Creature"
}
for _, indicator in pairs(indicators) do
if tool:FindFirstChild(indicator) then
return true, indicator
end
end
local name = tool.Name:lower()
local petNames = {
"dog", "cat", "bunny", "rabbit", "chicken", "cow", "pig", "sheep",
"bee", "ant", "butterfly", "dragonfly", "mouse", "rat", "hamster"
}
for _, petName in pairs(petNames) do
if name:find(petName) then
return true, "NameMatch"
end
end
return false
end
for _, tool in pairs(Backpack:GetChildren()) do
local isPet, indicator = isPetTool(tool)
if isPet then
table.insert(pets, {
Tool = tool,
Name = tool.Name,
Location = "Backpack",
Indicator = indicator
})
end
end
if Character then
for _, tool in pairs(Character:GetChildren()) do
local isPet, indicator = isPetTool(tool)
if isPet then
table.insert(pets, {
Tool = tool,
Name = tool.Name,
Location = "Equipped",
Indicator = indicator
})
end
end
end
return pets
end
local function GetAvailableEggs()
local eggs = {}
local Character = LocalPlayer.Character
local function isEggTool(tool)
if not tool:IsA("Tool") then return false end
local indicators = {
"EggData", "Egg_Data", "EggInfo", "Egg_Info",
"HatchData", "Hatch_Data", "IsEgg", "Egg"
}
for _, indicator in pairs(indicators) do
if tool:FindFirstChild(indicator) then
return true, indicator
end
end
local name = tool.Name:lower()
if name:find("egg") then
return true, "NameMatch"
end
for eggType, _ in pairs(PetEggTypes) do
if tool.Name == eggType then
return true, "EggTypeMatch"
end
end
return false
end
local function CollectFromParent(Parent)
for _, tool in pairs(Parent:GetChildren()) do
local isEgg, indicator = isEggTool(tool)
if isEgg then
table.insert(eggs, {
Tool = tool,
Name = tool.Name,
Indicator = indicator
})
end
end
end
CollectFromParent(Backpack)
if Character then
CollectFromParent(Character)
end
return eggs
end
local function HatchEgg(eggData)
if not eggData or not eggData.Tool then return false end
local eggTool = eggData.Tool
print("🥚 กำลังฟักไข่: " .. eggTool.Name)
local methods = {
function()
if PetEvents.HatchEgg then
PetEvents.HatchEgg:FireServer(eggTool)
return "HatchEgg Event"
end
end,
function()
for eventName, event in pairs(PetEvents) do
if eventName:lower():find("hatch") then
event:FireServer(eggTool)
return eventName .. " Event"
end
end
end,
function()
local events = {"HatchEgg", "Hatch", "Pet_Hatch", "Egg_Hatch"}
for _, eventName in pairs(events) do
local event = GameEvents:FindFirstChild(eventName)
if event then
event:FireServer(eggTool)
return eventName .. " GameEvent"
end
end
end
}
for _, method in pairs(methods) do
local success, result = pcall(method)
if success and result then
print("✅ ฟักไข่สำเร็จ: " .. eggTool.Name .. " ด้วยวิธี " .. result)
return true
end
end
return false
end
local function FeedPet(petData)
if not petData or not petData.Tool then return false end
local petTool = petData.Tool
print("🍼 กำลังให้อาหาร: " .. petTool.Name)
local methods = {
function()
if PetEvents.FeedPet then
PetEvents.FeedPet:FireServer(petTool)
return "FeedPet Event"
end
end,
function()
for eventName, event in pairs(PetEvents) do
if eventName:lower():find("feed") then
event:FireServer(petTool)
return eventName .. " Event"
end
end
end,
function()
local events = {"FeedPet", "Feed", "Pet_Feed", "Animal_Feed"}
for _, eventName in pairs(events) do
local event = GameEvents:FindFirstChild(eventName)
if event then
event:FireServer(petTool)
return eventName .. " GameEvent"
end
end
end
}
for _, method in pairs(methods) do
local success, result = pcall(method)
if success and result then
print("✅ ให้อาหารสำเร็จ: " .. petTool.Name .. " ด้วยวิธี " .. result)
return true
end
end
return false
end
local function BuyEgg(eggType)
if not PetEggTypes[eggType] then return false end
print("🛒 กำลังซื้อไข่: " .. eggType)
local methods = {
function()
if PetEvents.BuyEgg then
PetEvents.BuyEgg:FireServer(eggType)
return "BuyEgg Event"
end
end,
function()
for eventName, event in pairs(PetEvents) do
if eventName:lower():find("buy") then
event:FireServer(eggType)
return eventName .. " Event"
end
end
end,
function()
local events = {"BuyEgg", "Buy", "Pet_Buy", "Egg_Buy"}
for _, eventName in pairs(events) do
local event = GameEvents:FindFirstChild(eventName)
if event then
event:FireServer(eggType)
return eventName .. " GameEvent"
end
end
end
}
for _, method in pairs(methods) do
local success, result = pcall(method)
if success and result then
print("✅ ซื้อไข่สำเร็จ: " .. eggType .. " ด้วยวิธี " .. result)
return true
end
end
return false
end
-- Pet Loops
local function AutoHatchEggLoop()
if not FarmSettings.AutoHatchEgg or IsProcessingPets then return end
local currentTime = tick()
if (currentTime - LastHatchTime) < FarmSettings.HatchInterval then return end
local eggs = GetAvailableEggs()
if #eggs == 0 then return end
print("🥚 พบไข่ทั้งหมด " .. #eggs .. " ฟอง")
IsProcessingPets = true
local hatchedCount = 0
for _, eggData in pairs(eggs) do
if hatchedCount >= FarmSettings.MaxPetsToHatch then break end
if not FarmSettings.AutoHatchEgg then break end
if HatchEgg(eggData) then
hatchedCount = hatchedCount + 1
wait(2)
end
wait(0.5)
end
if hatchedCount > 0 then
print("✅ ฟักไข่สำเร็จทั้งหมด " .. hatchedCount .. " ฟอง")
end
LastHatchTime = currentTime
IsProcessingPets = false
end
local function AutoFeedPetsLoop()
if not FarmSettings.AutoFeedPets or IsProcessingPets then return end
local currentTime = tick()
if (currentTime - LastFeedTime) < FarmSettings.FeedInterval then return end
local pets = GetAllPets()
if #pets == 0 then return end
print("🐾 พบสัตว์เลี้ยงทั้งหมด " .. #pets .. " ตัว")
IsProcessingPets = true
local fedCount = 0
for _, petData in pairs(pets) do
if not FarmSettings.AutoFeedPets then break end
if FeedPet(petData) then
fedCount = fedCount + 1
wait(1)
end
wait(0.3)
end
if fedCount > 0 then
print("✅ ให้อาหารสำเร็จทั้งหมด " .. fedCount .. " ตัว")
end
LastFeedTime = currentTime
IsProcessingPets = false
end
local function AutoBuyEggsLoop()
if not FarmSettings.AutoBuyEggs or IsProcessingPets then return end
local currentTime = tick()
if (currentTime - LastBuyEggTime) < FarmSettings.BuyEggInterval then return end
local eggs = GetAvailableEggs()
if #eggs >= FarmSettings.MaxPetsToHatch then return end
local eggType = FarmSettings.SelectedEggType
local eggInfo = PetEggTypes[eggType]
if eggInfo then
print("🔄 กำลังซื้อไข่: " .. eggType .. " (ราคา: " .. eggInfo.Price .. ")")
if BuyEgg(eggType) then
print("✅ ซื้อไข่สำเร็จ: " .. eggType)
else
print("❌ ซื้อไข่ไม่สำเร็จ: " .. eggType)
end
else
print("⚠️ ไม่พบข้อมูลไข่: " .. eggType)
end
LastBuyEggTime = currentTime
end
-- Main Loops
local function StartCompleteFarmLoops()
print("🌱 เริ่มระบบฟาร์มแบบเต็มรูปแบบ...")
-- Auto Walk Loop
spawn(function()
while _G.CompleteFarmSystemLoaded do
local success, err = pcall(AutoWalkLoop)
if not success then
print("⚠️ ข้อผิดพลาดการเดิน: " .. tostring(err))
end
wait(1)
end
end)
-- Auto Harvest Loop
spawn(function()
while _G.CompleteFarmSystemLoaded do
local success, err = pcall(AutoHarvestLoop)
if not success then
print("⚠️ ข้อผิดพลาดการเก็บ: " .. tostring(err))
end
wait(FarmSettings.HarvestDelay)
end
end)
-- Auto Plant Loop
spawn(function()
while _G.CompleteFarmSystemLoaded do
local success, err = pcall(AutoPlantLoop)
if not success then
print("⚠️ ข้อผิดพลาดการปลูก: " .. tostring(err))
end
wait(FarmSettings.PlantInterval)
end
end)
-- Auto Sell Loop
spawn(function()
while _G.CompleteFarmSystemLoaded do
local success, err = pcall(AutoSellLoop)
if not success then
print("⚠️ ข้อผิดพลาดการขาย: " .. tostring(err))
end
wait(1)
end
end)
-- Auto Buy Seeds Loop
spawn(function()
while _G.CompleteFarmSystemLoaded do
local success, err = pcall(AutoBuySeedsLoop)
if not success then
print("⚠️ ข้อผิดพลาดการซื้อเมล็ด: " .. tostring(err))
end
wait(FarmSettings.BuyInterval)
end
end)
-- Auto Hatch Egg Loop
spawn(function()
while _G.CompleteFarmSystemLoaded do
local success, err = pcall(AutoHatchEggLoop)
if not success then
print("⚠️ ข้อผิดพลาดการฟักไข่: " .. tostring(err))
end
wait(FarmSettings.HatchInterval)
end
end)
-- Auto Feed Pets Loop
spawn(function()
while _G.CompleteFarmSystemLoaded do
local success, err = pcall(AutoFeedPetsLoop)
if not success then
print("⚠️ ข้อผิดพลาดการให้อาหาร: " .. tostring(err))
end
wait(FarmSettings.FeedInterval)
end
end)
-- Auto Buy Eggs Loop
spawn(function()
while _G.CompleteFarmSystemLoaded do
local success, err = pcall(AutoBuyEggsLoop)
if not success then
print("⚠️ ข้อผิดพลาดการซื้อไข่: " .. tostring(err))
end
wait(FarmSettings.BuyEggInterval)
end
end)
print("✅ ระบบฟาร์มทั้งหมดเริ่มทำงานแล้ว")
end
-- Simple UI
local function CreateCompleteFarmUI()
print("🎨 สร้าง UI ระบบฟาร์มแบบเต็มรูปแบบ...")
local oldUI = PlayerGui:FindFirstChild("CompleteFarmSystemUI")
if oldUI then oldUI:Destroy() end
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "CompleteFarmSystemUI"
ScreenGui.Parent = PlayerGui
ScreenGui.ResetOnSpawn = false
_G.CompleteFarmSystemUI = ScreenGui
local MainFrame = Instance.new("Frame")
MainFrame.Name = "MainFrame"
MainFrame.Parent = ScreenGui
MainFrame.BackgroundColor3 = Color3.fromRGB(25, 25, 30)
MainFrame.BorderSizePixel = 0
MainFrame.Position = UDim2.new(0, 50, 0, 50)
MainFrame.Size = UDim2.new(0, 350, 0, 450)
MainFrame.Active = true
MainFrame.Draggable = true
local Corner = Instance.new("UICorner")
Corner.CornerRadius = UDim.new(0, 12)
Corner.Parent = MainFrame
local Stroke = Instance.new("UIStroke")
Stroke.Parent = MainFrame
Stroke.Color = Color3.fromRGB(100, 255, 100)
Stroke.Thickness = 2
-- Title
local Title = Instance.new("TextLabel")
Title.Parent = MainFrame
Title.BackgroundColor3 = Color3.fromRGB(100, 255, 100)
Title.BorderSizePixel = 0
Title.Size = UDim2.new(1, 0, 0, 40)
Title.Font = Enum.Font.SourceSansBold
Title.Text = "🌱 ระบบฟาร์มแบบเต็มรูปแบบ"
Title.TextColor3 = Color3.fromRGB(255, 255, 255)
Title.TextSize = 16
local TitleCorner = Instance.new("UICorner")
TitleCorner.CornerRadius = UDim.new(0, 12)
TitleCorner.Parent = Title
-- Content
local ContentFrame = Instance.new("ScrollingFrame")
ContentFrame.Parent = MainFrame
ContentFrame.BackgroundTransparency = 1
ContentFrame.Position = UDim2.new(0, 10, 0, 50)
ContentFrame.Size = UDim2.new(1, -20, 1, -60)
ContentFrame.CanvasSize = UDim2.new(0, 0, 0, 600)
ContentFrame.ScrollBarThickness = 8
-- Toggle Functions
local function CreateToggle(text, yPos, callback, defaultState)
local ToggleFrame = Instance.new("Frame")
ToggleFrame.Parent = ContentFrame
ToggleFrame.BackgroundColor3 = Color3.fromRGB(35, 35, 40)
ToggleFrame.BorderSizePixel = 0
ToggleFrame.Position = UDim2.new(0, 0, 0, yPos)
ToggleFrame.Size = UDim2.new(1, 0, 0, 30)
local FrameCorner = Instance.new("UICorner")
FrameCorner.CornerRadius = UDim.new(0, 6)
FrameCorner.Parent = ToggleFrame
local Label = Instance.new("TextLabel")
Label.Parent = ToggleFrame
Label.BackgroundTransparency = 1
Label.Position = UDim2.new(0, 10, 0, 0)
Label.Size = UDim2.new(1, -70, 1, 0)
Label.Font = Enum.Font.SourceSans
Label.Text = text
Label.TextColor3 = Color3.fromRGB(255, 255, 255)
Label.TextSize = 12
Label.TextXAlignment = Enum.TextXAlignment.Left
local Toggle = Instance.new("TextButton")
Toggle.Parent = ToggleFrame
Toggle.BackgroundColor3 = defaultState and Color3.fromRGB(50, 200, 100) or Color3.fromRGB(200, 100, 100)
Toggle.BorderSizePixel = 0
Toggle.Position = UDim2.new(1, -60, 0, 5)
Toggle.Size = UDim2.new(0, 55, 0, 20)
Toggle.Font = Enum.Font.SourceSansBold
Toggle.Text = defaultState and "เปิด" or "ปิด"
Toggle.TextColor3 = Color3.fromRGB(255, 255, 255)
Toggle.TextSize = 10
local ToggleCorner = Instance.new("UICorner")
ToggleCorner.CornerRadius = UDim.new(0, 4)
ToggleCorner.Parent = Toggle
local isOn = defaultState or false
Toggle.MouseButton1Click:Connect(function()
isOn = not isOn
Toggle.Text = isOn and "เปิด" or "ปิด"
local targetColor = isOn and Color3.fromRGB(50, 200, 100) or Color3.fromRGB(200, 100, 100)
TweenService:Create(Toggle, TweenInfo.new(0.3), {
BackgroundColor3 = targetColor
}):Play()
if callback then callback(isOn) end
end)
return Toggle
end
-- Create Toggles
CreateToggle("🚶 เดินอัตโนมัติ", 10, function(state) FarmSettings.AutoWalk = state end, FarmSettings.AutoWalk)
CreateToggle("🚜 เก็บอัตโนมัติ", 50, function(state) FarmSettings.AutoHarvest = state end, FarmSettings.AutoHarvest)
CreateToggle("🌱 ปลูกอัตโนมัติ", 90, function(state) FarmSettings.AutoPlant = state end, FarmSettings.AutoPlant)
CreateToggle("💰 ขายอัตโนมัติ", 130, function(state) FarmSettings.AutoSell = state end, FarmSettings.AutoSell)
CreateToggle("🛒 ซื้อเมล็ดอัตโนมัติ", 170, function(state) FarmSettings.AutoBuySeeds = state end, FarmSettings.AutoBuySeeds)
CreateToggle("🥚 ฟักไข่อัตโนมัติ", 210, function(state) FarmSettings.AutoHatchEgg = state end, FarmSettings.AutoHatchEgg)
CreateToggle("🍼 ให้อาหารอัตโนมัติ", 250, function(state) FarmSettings.AutoFeedPets = state end, FarmSettings.AutoFeedPets)
CreateToggle("🛒 ซื้อไข่อัตโนมัติ", 290, function(state) FarmSettings.AutoBuyEggs = state end, FarmSettings.AutoBuyEggs)
CreateToggle("🎭 แอนิเมชั่นเรียบ", 330, function(state) FarmSettings.UseSmoothAnimations = state end, FarmSettings.UseSmoothAnimations)
print("✅ สร้าง UI ระบบฟาร์มสำเร็จ")
end
-- Initialize
print("🌱 เริ่มต้นระบบฟาร์มแบบเต็มรูปแบบ...")
wait(1)
CreateCompleteFarmUI()
StartCompleteFarmLoops()
game:GetService("StarterGui"):SetCore("SendNotification", {
Title = "🌱 ระบบฟาร์มแบบเต็มรูปแบบ",
Text = "ระบบฟาร์มแบบเต็มรูปแบบพร้อมใช้งาน!",
Duration = 3
})
print("🌱 " .. string.rep("=", 50))
print("✅ ระบบฟาร์มแบบเต็มรูปแบบพร้อมใช้งาน!")
print("🚶 เดิน: ทุก " .. FarmSettings.WalkInterval .. " วินาที")
print("🚜 เก็บ: ทุก " .. FarmSettings.HarvestDelay .. " วินาที")
print("🌱 ปลูก: ทุก " .. FarmSettings.PlantInterval .. " วินาที")
print("💰 ขาย: เมื่อเต็มกระเป๋า")
print("🛒 ซื้อเมล็ด: ทุก " .. FarmSettings.BuyInterval .. " วินาที")
print("🥚 ฟักไข่: ทุก " .. FarmSettings.HatchInterval .. " วินาที")
print("🍼 ให้อาหาร: ทุก " .. FarmSettings.FeedInterval .. " วินาที")
print("🛒 ซื้อไข่: ทุก " .. FarmSettings.BuyEggInterval .. " วินาที")
print("🌱 " .. string.rep("=", 50))
return {
Settings = FarmSettings,
UI = _G.CompleteFarmSystemUI,
MyFarm = MyFarm
}