• 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

Delay until condition

tweeb

Active member
Joined
May 24, 2019
RedCents
684¢
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:
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
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:

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
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"

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.
 
Delay until condition

Users who are viewing this thread

Back
Top
Cart