Command queue with delays

Share your scripts and packages with other Mudlet users.
Post Reply
chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

Command queue with delays

Post by chrio »

Inspired by Jor'Mox sendQueue, I decided to make my own commandqueue system, together with an alias "q" to make it easy to run from the command line.
Code: [show] | [select all] lua
function commandQueue(...)
	if(type(arg[1]) == "table" and #arg[1] > 0) then
		local v = table.remove(arg[1], 1)
		local next = function() commandQueue(arg[1]) end
		if(type(v) == "number") then	
			tempTimer(v, next)
		else
			expandAlias(v)
			commandQueue(arg[1])
		end
	else
		commandQueue(arg)
	end
end


-- commandQueue Alias:
local reg,al = [[^q (.*)]],
[[local tc = {}
local args = matches[2]

for c in args:gmatch('([^,]+)') do
	if(tonumber(c)) then
		table.insert(tc, tonumber(c))
	else
		c = string.trim(c)
		table.insert(tc, c)
	end
end
local c1,c2 = "<slate_blue>","<white>"
cecho(c1.."Command queue: ".. c2 .. table.concat(tc, c1..", "..c2) .. "\n")
commandQueue(unpack(tc))
]]

aliastable = aliastable or {}
if( aliastable.q ~= nil and exists(aliastable.q,"alias") > 0 ) then
	killAlias(aliastable.q)
	aliastable.q = nil
end
aliastable.q = tempAlias(reg, al)
Place it in a new script and save it and it will create the alias for you. If you want to change the alias pattern you do it in the script and save the script again. The current alias pattern is ^q (.*)

Function usage example: commandQueue(1,"look",2,"e","e",0.5,"kill kobold")
Same using the alias: q 1, look, 2, e, e, 0.5, kill kobold

You can have several pauses in a row if needed: q who,1,2,3,look will send "who", wait 6 seconds, and then send "look".

Post Reply