Page 1 of 1

sendQueue function

Posted: Mon Sep 05, 2016 11:55 pm
by Jor'Mox
I had some people asking for a way to send a series of commands that may need to be spaced out time wise so they could do scripted behaviors. In case anyone else wants it, here it is.
Code: [show] | [select all] lua
local runQueue
function runQueue(tbl)
    local info = table.remove(tbl,1)
    if info then
        local run = function()
                send(info[2])
                runQueue(tbl)
            end
        if info[1] ~= 0 then
            tempTimer(info[1], run)
        else
            run()
        end
    end
end

function sendQueue(...)
    local tbl = {}
    local args = arg
    for k,v in ipairs(args) do
        if k % 2 == 1 and type(v) ~= "number" then
            table.insert(args,k,0)
        end
    end
    for k = 1,#args,2 do
        tbl[(k + 1) / 2] = {args[k],args[k+1]}
    end
    runQueue(tbl)
end
Just pass the function commands as if it were sendAll, but if you want to wait before the next command, then pass a number equal to the amount of time you want to wait, and then pass the command. Like this: sendQueue("command 1",2,"command 2") Which would send "command 1" first, then wait 2 seconds, and then send "command 2".

Re: sendQueue function

Posted: Tue Sep 06, 2016 9:30 am
by chrio
Thanks for sharing. It's nice that it handles fractions of seconds aswell.

Re: sendQueue function

Posted: Wed Sep 07, 2016 9:33 am
by Duugan
chrio wrote:Thanks for sharing. It's nice that it handles fractions of seconds aswell.
I agree. It sounds awesome, but I'm a self-taught (with forum help) novice that will never understand scripting enough to even attempt this table nonsense. :D

Re: sendQueue function

Posted: Wed Sep 07, 2016 2:54 pm
by Jor'Mox
Duugan wrote:
chrio wrote:Thanks for sharing. It's nice that it handles fractions of seconds aswell.
I agree. It sounds awesome, but I'm a self-taught (with forum help) novice that will never understand scripting enough to even attempt this table nonsense. :D
That is why I shared this. There is no need to understand tables in order to take advantage of this function, just pass it the commands and delays you want, and it takes care of the rest.

Re: sendQueue function

Posted: Mon Sep 19, 2016 2:02 am
by Belgarath
Nice. Not sure how many people still use CMUD these days, but this would be a nice and easy substitute for the #wait function they have.