I use this snippet *all the time* now so I thought I'd share.
`mq.delay` doesn't take a condition like regular `/delay`. So you can't write things like `/delay 3 ${Target.ID} == ${MyMobID}`
So I've been using this Lua function instead:
You pass in a function that takes no arguments, which will be evaluated repeatedly until it's true. This is easy in Lua since you can define functions in-line. Examples:
Note that you can make the content of this function as complicated as you want (and you could give it a name, not just define it inline). This could be useful if you want something like "do a thing, retry until it succeeds"
One caveat about timeouts: it's not actually a *timer* so the amount of time that passes before a timeout might be a little unpredictable. It's not just delaying 1ms 5 times, it's 1ms 5 times + the overhead from 5 function calls + whatever's inside that function.
`mq.delay` doesn't take a condition like regular `/delay`. So you can't write things like `/delay 3 ${Target.ID} == ${MyMobID}`
So I've been using this Lua function instead:
Lua:
function delay_until(predicate, timeout)
local count = 0
while not predicate() do
mq.delay(1)
if timeout and count > timeout then
break
end
count = count + 1
end
end
Lua:
delay_until(function() return mq.TLO.Window('DynamicZoneWnd').Open() end, 5) -- wait for expedition window to be open with a short timeout
delay_until(function() return mq.TLO.Spawn(npc_name).Distance3D() < 15 end) -- wait until we're near a specific NPC
Lua:
my_complicated_function = function()
--do
--lots
--of
--stuff
return result
end
delay_until(my_complicated_function)
One caveat about timeouts: it's not actually a *timer* so the amount of time that passes before a timeout might be a little unpredictable. It's not just delaying 1ms 5 times, it's 1ms 5 times + the overhead from 5 function calls + whatever's inside that function.

