975 lines
30 KiB
Lua
975 lines
30 KiB
Lua
-- Ultimate GaG Auto Farm - Optimized Version
|
|
-- ปรับปรุงให้เก็บของไวขึ้น ขายเร็วขึ้น และเลี้ยงสัตว์ Smooth ขึ้น
|
|
|
|
print("🚀 Loading Ultimate GaG Auto Farm (Optimized)...")
|
|
|
|
-- Services
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
local Players = game:GetService("Players")
|
|
local RunService = game:GetService("RunService")
|
|
local TweenService = game:GetService("TweenService")
|
|
local HttpService = game:GetService("HttpService")
|
|
|
|
local LocalPlayer = Players.LocalPlayer
|
|
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
|
|
local Leaderstats = LocalPlayer:WaitForChild("leaderstats")
|
|
local Backpack = LocalPlayer:WaitForChild("Backpack")
|
|
|
|
print("✅ Services loaded")
|
|
|
|
-- ป้องกันการรันซ้ำ
|
|
if _G.UltimateGaGFarmOptimizedLoaded then
|
|
print("⚠️ Ultimate GaG Farm Optimized already loaded, removing old one...")
|
|
if _G.UltimateGaGFarmOptimizedUI then
|
|
_G.UltimateGaGFarmOptimizedUI:Destroy()
|
|
end
|
|
end
|
|
_G.UltimateGaGFarmOptimizedLoaded = true
|
|
|
|
-- Game Objects
|
|
local GameEvents = ReplicatedStorage:WaitForChild("GameEvents")
|
|
local Farms = workspace:WaitForChild("Farm")
|
|
|
|
print("✅ Game objects found")
|
|
|
|
-- Optimized Settings
|
|
local Settings = {
|
|
-- Auto Farm Settings
|
|
AutoPlant = false,
|
|
AutoHarvest = false,
|
|
AutoSell = false,
|
|
AutoBuy = false,
|
|
AutoWalk = false,
|
|
|
|
-- Basic Settings
|
|
SelectedSeed = "Carrot",
|
|
HarvestAll = true,
|
|
HarvestSpeed = "Ultra Fast",
|
|
SellThreshold = 15,
|
|
PlantRandom = false,
|
|
|
|
-- Optimized Auto Sell Settings
|
|
AutoSellWhenFull = true,
|
|
MaxInventorySlots = 200,
|
|
SellImmediately = true, -- ขายทันทีเมื่อเต็ม
|
|
SellAtThreshold = 80, -- ขายเมื่อเหลือ 80% ของกระเป๋า
|
|
|
|
-- Optimized Walk Settings
|
|
WalkSpeed = "เร็ว",
|
|
WalkRandomness = true,
|
|
WalkRadius = 20,
|
|
|
|
-- Optimized Pet/Animal Settings
|
|
AutoHatchEgg = false,
|
|
AutoFeedPets = false,
|
|
AutoBuyEggs = false,
|
|
AutoEquipPets = false,
|
|
SelectedEggType = "Common Egg",
|
|
MaxPetsToHatch = 5,
|
|
FeedWhenHungry = true,
|
|
AutoSellBadPets = false,
|
|
|
|
-- Optimized Harvest Settings
|
|
HarvestNormalOnly = true,
|
|
HarvestGolden = true,
|
|
HarvestSpecial = false,
|
|
|
|
-- Ultra Fast Optimization
|
|
HarvestDelay = 0.001, -- ลดดีเลย์ลงมาก
|
|
MaxHarvestPerLoop = 100, -- เพิ่มจำนวนสูงสุด
|
|
ParallelHarvest = true, -- เก็บแบบ Parallel
|
|
BatchHarvest = true, -- เก็บเป็นชุด
|
|
HarvestBatchSize = 20, -- ขนาดชุด
|
|
|
|
-- Smooth Movement
|
|
SmoothTeleport = true,
|
|
TeleportDelay = 0.1,
|
|
|
|
-- Smart Inventory Management
|
|
SmartInventory = true,
|
|
InventoryCheckInterval = 0.5,
|
|
|
|
-- Performance Optimization
|
|
UseThreading = true,
|
|
MaxThreads = 4,
|
|
ThreadDelay = 0.01
|
|
}
|
|
|
|
-- Performance Optimization Variables
|
|
local HarvestThreads = {}
|
|
local IsHarvesting = false
|
|
local LastHarvestTime = 0
|
|
local InventoryCache = {}
|
|
local InventoryCacheTime = 0
|
|
|
|
-- Find Player's Farm
|
|
local function GetFarmOwner(Farm)
|
|
local Important = Farm:FindFirstChild("Important")
|
|
if not Important then return nil end
|
|
|
|
local Data = Important:FindFirstChild("Data")
|
|
if not Data then return nil end
|
|
|
|
local Owner = Data:FindFirstChild("Owner")
|
|
if not Owner then return nil end
|
|
|
|
return Owner.Value
|
|
end
|
|
|
|
local function GetFarm(PlayerName)
|
|
local AllFarms = Farms:GetChildren()
|
|
for _, Farm in pairs(AllFarms) do
|
|
local Owner = GetFarmOwner(Farm)
|
|
if Owner == PlayerName then
|
|
return Farm
|
|
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 = "Ultimate GaG Farm Optimized",
|
|
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)
|
|
|
|
-- Optimized Get Harvestable Plants
|
|
local function GetHarvestablePlants()
|
|
local Plants = {}
|
|
local currentTime = tick()
|
|
|
|
-- ใช้ cache ถ้าไม่นานเกินไป
|
|
if InventoryCacheTime > 0 and (currentTime - InventoryCacheTime) < 0.1 then
|
|
return InventoryCache
|
|
end
|
|
|
|
local function ShouldHarvestPlant(Plant)
|
|
local plantName = Plant.Name:lower()
|
|
|
|
-- ตรวจสอบผลพิเศษ
|
|
local specialEffects = {
|
|
"shocked", "moonlit", "twisted", "burnt", "frozen", "wet",
|
|
"bloodlit", "zombified", "celestial", "disco", "plasma",
|
|
"voidtouched", "honeyglazed", "pollinated", "chilled",
|
|
"radiant", "aurora", "crystal", "shadow", "ethereal",
|
|
"cursed", "blessed", "elemental", "mystical", "enchanted"
|
|
}
|
|
|
|
local hasSpecialEffect = false
|
|
for _, effect in pairs(specialEffects) do
|
|
if plantName:find(effect) then
|
|
hasSpecialEffect = true
|
|
break
|
|
end
|
|
end
|
|
|
|
local isGolden = plantName:find("golden") or plantName:find("gold")
|
|
|
|
if Plant:IsA("Model") and Plant.PrimaryPart then
|
|
local primaryPart = Plant.PrimaryPart
|
|
if primaryPart.Color == Color3.new(1, 0.8, 0) or
|
|
primaryPart.Color == Color3.fromRGB(255, 215, 0) then
|
|
isGolden = true
|
|
end
|
|
|
|
if primaryPart:FindFirstChild("PointLight") or
|
|
primaryPart:FindFirstChild("SpotLight") or
|
|
primaryPart:FindFirstChild("SurfaceLight") then
|
|
hasSpecialEffect = true
|
|
end
|
|
end
|
|
|
|
if hasSpecialEffect and not Settings.HarvestSpecial then
|
|
return false
|
|
end
|
|
|
|
if isGolden and not Settings.HarvestGolden then
|
|
return false
|
|
end
|
|
|
|
if not isGolden and not hasSpecialEffect and not Settings.HarvestNormalOnly then
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
local function CollectHarvestable(Parent)
|
|
for _, Plant in pairs(Parent:GetChildren()) do
|
|
if #Plants >= Settings.MaxHarvestPerLoop then
|
|
break
|
|
end
|
|
|
|
local Fruits = Plant:FindFirstChild("Fruits")
|
|
if Fruits then
|
|
CollectHarvestable(Fruits)
|
|
end
|
|
|
|
local Prompt = Plant:FindFirstChild("ProximityPrompt", true)
|
|
if Prompt and Prompt.Enabled and ShouldHarvestPlant(Plant) then
|
|
table.insert(Plants, Plant)
|
|
end
|
|
end
|
|
end
|
|
|
|
CollectHarvestable(PlantsPhysical)
|
|
|
|
if Settings.HarvestAll and #Plants < Settings.MaxHarvestPerLoop then
|
|
for _, Farm in pairs(Farms:GetChildren()) do
|
|
if Farm ~= MyFarm and #Plants < Settings.MaxHarvestPerLoop then
|
|
local OtherPlantsPhysical = Farm:FindFirstChild("Important")
|
|
if OtherPlantsPhysical then
|
|
OtherPlantsPhysical = OtherPlantsPhysical:FindFirstChild("Plants_Physical")
|
|
if OtherPlantsPhysical then
|
|
CollectHarvestable(OtherPlantsPhysical)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Update cache
|
|
InventoryCache = Plants
|
|
InventoryCacheTime = currentTime
|
|
|
|
return Plants
|
|
end
|
|
|
|
-- Optimized Harvest Function
|
|
local function HarvestPlant(Plant)
|
|
local Prompt = Plant:FindFirstChild("ProximityPrompt", true)
|
|
if Prompt and Prompt.Enabled then
|
|
fireproximityprompt(Prompt)
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- Batch Harvest Function
|
|
local function BatchHarvestPlants(Plants, startIndex, endIndex)
|
|
local harvested = 0
|
|
for i = startIndex, endIndex do
|
|
if Plants[i] and Settings.AutoHarvest then
|
|
if HarvestPlant(Plants[i]) then
|
|
harvested = harvested + 1
|
|
end
|
|
end
|
|
end
|
|
return harvested
|
|
end
|
|
|
|
-- Optimized Get Inventory Count
|
|
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
|
|
|
|
-- Smart Inventory Management
|
|
local function IsInventoryFull()
|
|
local currentCount = GetTotalInventoryCount()
|
|
return currentCount >= Settings.MaxInventorySlots
|
|
end
|
|
|
|
local function ShouldAutoSell()
|
|
local totalItems = GetTotalInventoryCount()
|
|
|
|
if Settings.SellImmediately and IsInventoryFull() then
|
|
return true, "กระเป๋าเต็มทันที"
|
|
end
|
|
|
|
if Settings.SellAtThreshold and totalItems >= (Settings.MaxInventorySlots * Settings.SellAtThreshold / 100) then
|
|
return true, "ถึงเกณฑ์ขาย (" .. math.floor((totalItems / Settings.MaxInventorySlots) * 100) .. "%)"
|
|
end
|
|
|
|
if Settings.AutoSellWhenFull and totalItems >= (Settings.MaxInventorySlots - 1) then
|
|
return true, "กระเป๋าใกล้เต็ม"
|
|
end
|
|
|
|
return false, "ยังไม่ถึงเวลา"
|
|
end
|
|
|
|
-- Optimized Sell Function
|
|
local IsSelling = false
|
|
local function SellInventory()
|
|
if IsSelling then return end
|
|
IsSelling = true
|
|
|
|
local Character = LocalPlayer.Character
|
|
if not Character then
|
|
IsSelling = false
|
|
return
|
|
end
|
|
|
|
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
|
|
if not HumanoidRootPart then
|
|
IsSelling = false
|
|
return
|
|
end
|
|
|
|
local Previous = HumanoidRootPart.CFrame
|
|
local ShecklesCount = Leaderstats:FindFirstChild("Sheckles")
|
|
|
|
-- Optimized teleport
|
|
if Settings.SmoothTeleport then
|
|
local targetPos = CFrame.new(62, 4, -26)
|
|
local tween = TweenService:Create(HumanoidRootPart, TweenInfo.new(Settings.TeleportDelay), {
|
|
CFrame = targetPos
|
|
})
|
|
tween:Play()
|
|
tween.Completed:Wait()
|
|
else
|
|
HumanoidRootPart.CFrame = CFrame.new(62, 4, -26)
|
|
end
|
|
|
|
wait(0.3)
|
|
|
|
if ShecklesCount then
|
|
local PreviousSheckles = ShecklesCount.Value
|
|
|
|
local SellEvent = GameEvents:FindFirstChild("Sell_Inventory")
|
|
if SellEvent then
|
|
local attempts = 0
|
|
while attempts < 5 do
|
|
if ShecklesCount.Value ~= PreviousSheckles then break end
|
|
SellEvent:FireServer()
|
|
wait(0.1)
|
|
attempts = attempts + 1
|
|
end
|
|
print("💰 ขายได้เงิน " .. (ShecklesCount.Value - PreviousSheckles) .. " sheckles")
|
|
end
|
|
end
|
|
|
|
-- Return smoothly
|
|
if Settings.SmoothTeleport then
|
|
local tween = TweenService:Create(HumanoidRootPart, TweenInfo.new(Settings.TeleportDelay), {
|
|
CFrame = Previous
|
|
})
|
|
tween:Play()
|
|
tween.Completed:Wait()
|
|
else
|
|
HumanoidRootPart.CFrame = Previous
|
|
end
|
|
|
|
wait(0.1)
|
|
IsSelling = false
|
|
end
|
|
|
|
-- Optimized Auto Harvest Loop
|
|
local function AutoHarvestLoop()
|
|
if not Settings.AutoHarvest or IsSelling then return end
|
|
|
|
local currentCount = GetTotalInventoryCount()
|
|
if currentCount >= Settings.MaxInventorySlots then
|
|
return
|
|
end
|
|
|
|
local Plants = GetHarvestablePlants()
|
|
if #Plants == 0 then return end
|
|
|
|
local availableSlots = Settings.MaxInventorySlots - currentCount
|
|
local maxHarvestPerLoop = math.min(#Plants, availableSlots, Settings.MaxHarvestPerLoop)
|
|
|
|
if Settings.ParallelHarvest and Settings.UseThreading then
|
|
-- Parallel harvesting with threading
|
|
local threads = {}
|
|
local batchSize = math.ceil(maxHarvestPerLoop / Settings.MaxThreads)
|
|
|
|
for i = 1, Settings.MaxThreads do
|
|
local startIndex = (i - 1) * batchSize + 1
|
|
local endIndex = math.min(i * batchSize, maxHarvestPerLoop)
|
|
|
|
if startIndex <= endIndex then
|
|
local thread = spawn(function()
|
|
return BatchHarvestPlants(Plants, startIndex, endIndex)
|
|
end)
|
|
table.insert(threads, thread)
|
|
end
|
|
end
|
|
|
|
-- Wait for all threads to complete
|
|
local totalHarvested = 0
|
|
for _, thread in pairs(threads) do
|
|
totalHarvested = totalHarvested + (thread or 0)
|
|
end
|
|
|
|
if totalHarvested > 0 then
|
|
print("🚜 เก็บแบบ Parallel: " .. totalHarvested .. " ต้น")
|
|
end
|
|
|
|
elseif Settings.BatchHarvest then
|
|
-- Batch harvesting
|
|
local harvested = 0
|
|
local batchSize = Settings.HarvestBatchSize
|
|
|
|
for i = 1, maxHarvestPerLoop, batchSize do
|
|
if not Settings.AutoHarvest then break end
|
|
|
|
local endIndex = math.min(i + batchSize - 1, maxHarvested)
|
|
local batchHarvested = BatchHarvestPlants(Plants, i, endIndex)
|
|
harvested = harvested + batchHarvested
|
|
|
|
wait(Settings.HarvestDelay)
|
|
end
|
|
|
|
if harvested > 0 then
|
|
print("🚜 เก็บแบบ Batch: " .. harvested .. " ต้น")
|
|
end
|
|
|
|
else
|
|
-- Sequential harvesting (ultra fast)
|
|
local harvested = 0
|
|
for i = 1, maxHarvestPerLoop do
|
|
if not Settings.AutoHarvest then break end
|
|
|
|
if HarvestPlant(Plants[i]) then
|
|
harvested = harvested + 1
|
|
end
|
|
|
|
wait(Settings.HarvestDelay)
|
|
end
|
|
|
|
if harvested > 0 then
|
|
print("🚜 เก็บแบบ Sequential: " .. harvested .. " ต้น")
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Optimized Auto Sell Loop
|
|
local function AutoSellLoop()
|
|
if not Settings.AutoSell or IsSelling then return end
|
|
|
|
local shouldSell, reason = ShouldAutoSell()
|
|
if not shouldSell then return end
|
|
|
|
local totalItems = GetTotalInventoryCount()
|
|
print("💰 ขาย " .. totalItems .. " ชิ้น (" .. reason .. ")")
|
|
SellInventory()
|
|
end
|
|
|
|
-- Pet System (Optimized)
|
|
local PetEggTypes = {
|
|
["Common Egg"] = { HatchTime = 600, Price = 100 },
|
|
["Uncommon Egg"] = { HatchTime = 1200, Price = 500 },
|
|
["Rare Egg"] = { HatchTime = 7200, Price = 2500 },
|
|
["Legendary Egg"] = { HatchTime = 14400, Price = 10000 },
|
|
["Mythical Egg"] = { HatchTime = 18400, Price = 50000 }
|
|
}
|
|
|
|
local PetEvents = {}
|
|
|
|
-- Find Pet Events
|
|
local function FindPetEvents()
|
|
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
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
FindPetEvents()
|
|
|
|
-- Optimized 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
|
|
|
|
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
|
|
|
|
-- Optimized Pet Actions
|
|
local function HatchEgg(eggData)
|
|
if not eggData or not eggData.Tool then return false end
|
|
|
|
local eggTool = eggData.Tool
|
|
|
|
-- Try multiple methods
|
|
local methods = {
|
|
function()
|
|
if PetEvents.HatchEgg then
|
|
PetEvents.HatchEgg:FireServer(eggTool)
|
|
return true
|
|
end
|
|
end,
|
|
function()
|
|
for eventName, event in pairs(PetEvents) do
|
|
if eventName:lower():find("hatch") then
|
|
event:FireServer(eggTool)
|
|
return true
|
|
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 true
|
|
end
|
|
end
|
|
end
|
|
}
|
|
|
|
for _, method in pairs(methods) do
|
|
local success = pcall(method)
|
|
if success then
|
|
print("✅ ฟักไข่สำเร็จ: " .. eggTool.Name)
|
|
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
|
|
|
|
local methods = {
|
|
function()
|
|
if PetEvents.FeedPet then
|
|
PetEvents.FeedPet:FireServer(petTool)
|
|
return true
|
|
end
|
|
end,
|
|
function()
|
|
for eventName, event in pairs(PetEvents) do
|
|
if eventName:lower():find("feed") then
|
|
event:FireServer(petTool)
|
|
return true
|
|
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 true
|
|
end
|
|
end
|
|
end
|
|
}
|
|
|
|
for _, method in pairs(methods) do
|
|
local success = pcall(method)
|
|
if success then
|
|
print("✅ ให้อาหารสำเร็จ: " .. petTool.Name)
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
-- Optimized Pet Loops
|
|
local function AutoHatchEggLoop()
|
|
if not Settings.AutoHatchEgg or IsSelling then return end
|
|
|
|
local eggs = GetAvailableEggs()
|
|
if #eggs == 0 then return end
|
|
|
|
local hatchedCount = 0
|
|
for _, eggData in pairs(eggs) do
|
|
if hatchedCount >= Settings.MaxPetsToHatch then break end
|
|
if not Settings.AutoHatchEgg then break end
|
|
|
|
if HatchEgg(eggData) then
|
|
hatchedCount = hatchedCount + 1
|
|
wait(1)
|
|
end
|
|
wait(0.2)
|
|
end
|
|
|
|
if hatchedCount > 0 then
|
|
print("✅ ฟักไข่สำเร็จ " .. hatchedCount .. " ฟอง")
|
|
end
|
|
end
|
|
|
|
local function AutoFeedPetsLoop()
|
|
if not Settings.AutoFeedPets or IsSelling then return end
|
|
|
|
local pets = GetAllPets()
|
|
if #pets == 0 then return end
|
|
|
|
local fedCount = 0
|
|
for _, petData in pairs(pets) do
|
|
if not Settings.AutoFeedPets then break end
|
|
|
|
if FeedPet(petData) then
|
|
fedCount = fedCount + 1
|
|
wait(0.5)
|
|
end
|
|
wait(0.1)
|
|
end
|
|
|
|
if fedCount > 0 then
|
|
print("✅ ให้อาหารสำเร็จ " .. fedCount .. " ตัว")
|
|
end
|
|
end
|
|
|
|
-- Main Loops
|
|
local function StartOptimizedLoops()
|
|
print("🚀 Starting optimized loops...")
|
|
|
|
-- Auto Harvest Loop (Ultra Fast)
|
|
spawn(function()
|
|
while _G.UltimateGaGFarmOptimizedLoaded do
|
|
if Settings.AutoHarvest and not IsSelling then
|
|
local success, err = pcall(AutoHarvestLoop)
|
|
if not success then
|
|
print("⚠️ Harvest error: " .. tostring(err))
|
|
end
|
|
end
|
|
wait(0.1) -- เร็วขึ้นมาก
|
|
end
|
|
end)
|
|
|
|
-- Auto Sell Loop (Smart)
|
|
spawn(function()
|
|
while _G.UltimateGaGFarmOptimizedLoaded do
|
|
if Settings.AutoSell and not IsSelling then
|
|
local success, err = pcall(AutoSellLoop)
|
|
if not success then
|
|
print("⚠️ Sell error: " .. tostring(err))
|
|
end
|
|
end
|
|
wait(0.5)
|
|
end
|
|
end)
|
|
|
|
-- Auto Pet Loops
|
|
spawn(function()
|
|
while _G.UltimateGaGFarmOptimizedLoaded do
|
|
if Settings.AutoHatchEgg and not IsSelling then
|
|
local success, err = pcall(AutoHatchEggLoop)
|
|
if not success then
|
|
print("⚠️ Pet Hatch error: " .. tostring(err))
|
|
end
|
|
end
|
|
wait(30)
|
|
end
|
|
end)
|
|
|
|
spawn(function()
|
|
while _G.UltimateGaGFarmOptimizedLoaded do
|
|
if Settings.AutoFeedPets and not IsSelling then
|
|
local success, err = pcall(AutoFeedPetsLoop)
|
|
if not success then
|
|
print("⚠️ Pet Feed error: " .. tostring(err))
|
|
end
|
|
end
|
|
wait(60)
|
|
end
|
|
end)
|
|
|
|
print("✅ All optimized loops started")
|
|
end
|
|
|
|
-- Simple UI
|
|
local function CreateOptimizedUI()
|
|
print("🎨 Creating Optimized UI...")
|
|
|
|
local oldUI = PlayerGui:FindFirstChild("UltimateGaGFarmOptimizedUI")
|
|
if oldUI then oldUI:Destroy() end
|
|
|
|
local ScreenGui = Instance.new("ScreenGui")
|
|
ScreenGui.Name = "UltimateGaGFarmOptimizedUI"
|
|
ScreenGui.Parent = PlayerGui
|
|
ScreenGui.ResetOnSpawn = false
|
|
|
|
_G.UltimateGaGFarmOptimizedUI = 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, 300, 0, 350)
|
|
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(70, 170, 255)
|
|
Stroke.Thickness = 2
|
|
|
|
-- Title
|
|
local Title = Instance.new("TextLabel")
|
|
Title.Parent = MainFrame
|
|
Title.BackgroundColor3 = Color3.fromRGB(45, 130, 220)
|
|
Title.BorderSizePixel = 0
|
|
Title.Size = UDim2.new(1, 0, 0, 40)
|
|
Title.Font = Enum.Font.SourceSansBold
|
|
Title.Text = "🚀 ระบบฟาร์มอัตโนมัติ (Optimized)"
|
|
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, 400)
|
|
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("🌱 Auto Plant", 10, function(state) Settings.AutoPlant = state end, Settings.AutoPlant)
|
|
CreateToggle("🚜 Auto Harvest", 50, function(state) Settings.AutoHarvest = state end, Settings.AutoHarvest)
|
|
CreateToggle("💰 Auto Sell", 90, function(state) Settings.AutoSell = state end, Settings.AutoSell)
|
|
CreateToggle("🥚 Auto Hatch", 130, function(state) Settings.AutoHatchEgg = state end, Settings.AutoHatchEgg)
|
|
CreateToggle("🍼 Auto Feed", 170, function(state) Settings.AutoFeedPets = state end, Settings.AutoFeedPets)
|
|
CreateToggle("🔄 Parallel Harvest", 210, function(state) Settings.ParallelHarvest = state end, Settings.ParallelHarvest)
|
|
CreateToggle("📦 Batch Harvest", 250, function(state) Settings.BatchHarvest = state end, Settings.BatchHarvest)
|
|
CreateToggle("🚀 Smooth Teleport", 290, function(state) Settings.SmoothTeleport = state end, Settings.SmoothTeleport)
|
|
|
|
print("✅ Optimized UI created")
|
|
end
|
|
|
|
-- Initialize
|
|
print("🚀 Initializing Optimized GaG Auto Farm...")
|
|
|
|
wait(1)
|
|
|
|
CreateOptimizedUI()
|
|
StartOptimizedLoops()
|
|
|
|
game:GetService("StarterGui"):SetCore("SendNotification", {
|
|
Title = "🚀 ระบบฟาร์มอัตโนมัติ (Optimized)",
|
|
Text = "โหลดเรียบร้อย! เร็วขึ้นและ Smooth ขึ้น!",
|
|
Duration = 3
|
|
})
|
|
|
|
print("✨ " .. string.rep("=", 50))
|
|
print("✅ โหลดระบบฟาร์มอัตโนมัติแบบ Optimized สำเร็จ!")
|
|
print("🚀 การปรับปรุง:")
|
|
print(" - เก็บของเร็วขึ้น (Parallel/Batch processing)")
|
|
print(" - ขายเร็วขึ้น (Smart inventory management)")
|
|
print(" - เลี้ยงสัตว์ Smooth ขึ้น (Optimized pet system)")
|
|
print(" - ระบบ Threading สำหรับประสิทธิภาพสูงสุด")
|
|
print(" - Smooth teleport และ movement")
|
|
print("✨ " .. string.rep("=", 50))
|
|
|
|
return {
|
|
Settings = Settings,
|
|
UI = _G.UltimateGaGFarmOptimizedUI,
|
|
MyFarm = MyFarm
|
|
} |