Startforage & Stopforage
Simple and basic condition to be used with MQ2AutoForage which will forage until the required amount of water/ingredients/items are in your inventory:
Simple and basic condition to be used with MQ2AutoForage which will forage until the required amount of water/ingredients/items are in your inventory:
Code:
local mq = require('mq')
if not package.loaded['events'] then print('This script is intended to be imported to Lua Event Manager (LEM). Try "\a-t/lua run lem\a-x"') end
---@return boolean @Returns true if the action should fire, otherwise false.
local function condition()
-- Get item counts
local waterCount = mq.TLO.FindItemCount("=Pod of Water")()
local rootsCount = mq.TLO.FindItemCount("=Roots")()
local vegetablesCount = mq.TLO.FindItemCount("=Vegetables")()
local totalFood = rootsCount + vegetablesCount
local canForage = mq.TLO.Me.AbilityReady("Forage")()
-- Stop foraging if we have enough items and aren't already stopped
if waterCount >= 40 and totalFood >= 40 and not canForage then
return true
end
-- Start foraging if we're low on items and can forage
if (waterCount <= 20 or totalFood <= 20) and canForage then
return true
end
return false
end
local function action()
local waterCount = mq.TLO.FindItemCount("=Pod of Water")()
local rootsCount = mq.TLO.FindItemCount("=Roots")()
local vegetablesCount = mq.TLO.FindItemCount("=Vegetables")()
local totalFood = rootsCount + vegetablesCount
-- If we have enough items, stop foraging
if waterCount >= 40 and totalFood >= 40 then
mq.cmd('/stopforage')
-- If we're low on items, start foraging
else
mq.cmd('/startforage')
end
end
return {condfunc=condition, actionfunc=action}


