• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

milk_cookie_manager.lua

Joined
Jun 19, 2007
RedCents
254¢
My first attempt at a Lua script so be gentle. So far it has behaved as expected for me. Maintains 5 cookies/milk in your inventory at all times unless you are invisible.

[CODE lang="Lua" title="milk_cookies_manager.Lua"]
-- cookie_milk_manager.Lua version 1.4 (uses FindItemCount)
-- Maintains 5 Fresh Cookies and 5 Warm Milk in inventory
-- Summons only when needed
-- Auto-inventories summoned items
-- Does not summon while invisible

local mq = require("mq")

local COOKIE_ITEM_NAME = "Fresh Cookie"
local MILK_ITEM_NAME = "Warm Milk"
local COOKIE_CLICKY = "Fresh Cookie Dispenser"
local MILK_CLICKY = "Warm Milk Dispenser"
local TARGET_COOKIE_COUNT = 5
local TARGET_MILK_COUNT = 5

---@return number
local function getItemCount(itemName)
local count = mq.TLO.FindItemCount(string.format("=%s", itemName))() or 0
-- mq.cmdf("/echo Counted %d of %s", count, itemName)
return count
end

---@param itemName string
local function useClicky(itemName)
local item = mq.TLO.FindItem(itemName)
if item() and item.Clicky.Spell() and item.TimerReady() then
mq.cmdf("/useitem \"%s\"", itemName)
mq.delay(1500)
moveItemFromCursor()
end
end

function moveItemFromCursor()
local cursorItem = mq.TLO.Cursor
if cursorItem() then
if cursorItem.Name() == COOKIE_ITEM_NAME or cursorItem.Name() == MILK_ITEM_NAME then
mq.cmd("/autoinventory")
mq.delay(300)
end
end
end

local function maintainFoodAndDrink()
while true do
-- Skip checks while invisible
if not mq.TLO.Me.Invis() then
local cookieCount = getItemCount(COOKIE_ITEM_NAME)
local milkCount = getItemCount(MILK_ITEM_NAME)

if cookieCount < TARGET_COOKIE_COUNT then
useClicky(COOKIE_CLICKY)
end

if milkCount < TARGET_MILK_COUNT then
useClicky(MILK_CLICKY)
end
end

mq.delay(2000) -- Check every 2 seconds
end
end

maintainFoodAndDrink()
[/CODE]
 
Last edited:
I have found a small caveat with this script. If there is an empty main inventory slot rather than all full with bags or something, it will autoinventory the milk/cookie into that slot and not be found/counted towards the required 5 in inventory. It only counts if they are inside a bag.

Updated the script to use FindItemCount which correctly identifies the item regardless if it is in a main inventory slot or inside of a bag. Tested to make sure it works in all situations now.
 
Last edited:
milk_cookie_manager.lua

Users who are viewing this thread

Back
Top
Cart