Как правильно включить в код потоки?

Flame Castle

Новичок
Автор темы
3
0
Версия MoonLoader
.026-beta
Имею следующий код:

Lua:
local function getArgs(func)
    local args = {}
    for i = 1, debug.getinfo(func).nparams, 1 do
        table.insert(args, debug.getlocal(func, i));
    end
    return args;
end

local function searchArgs(input, count)
    local args = {}
    local text = ""
    local i = 1
    for word in input:gmatch("%S+") do
        if i == 1 then
            -- none
        else
            if i <= count then
                table.insert(args, word)
            else
                text = text  .. " " .. word
            end
        end
        i = i + 1
    end
  
    table.insert( args, text )
    return args
end

local function searchName(input)
    local name

    for word in input:gmatch("%S+") do
        name = word
        break
    end

    return name
end

local commands = {}

local function registerCommand(name, func)
    local command = {}
    command.name = name
    command.func = func
    command.args = getArgs(func)
    commands[name] = command
end

function onSendRpc(id, bitStream, priority, reliability, orderingChannel, shiftTs)
    if id == 50 then
        local length = raknetBitStreamReadInt32(bitStream)
        local text = raknetBitStreamReadString(bitStream, length)
        text = string.sub(text, 2, #text)
        local name = searchName(text)
        local command = commands[name]
        if not command then return end
        local args = searchArgs(text, #command.args)
  
        if #args ~= #command.args then
            local line = ""
            -- Выводит список именований аргументов функций
            for k, v in ipairs(command.args) do
                line = line .. " " .. v
            end

            sampAddChatMessage("[Биндер] Аргументы: " .. line, -1)
            return false
        end

        local handled_text = command.func(table.unpack(args))
  
        if handled_text then
            handled_text = "/" .. name .. " " .. handled_text
            raknetBitStreamResetWritePointer(bitStream)
            raknetBitStreamWriteInt32(bitStream, #handled_text)
            raknetBitStreamWriteString(bitStream, handled_text)
            return {id, bitStream, priority, reliability, orderingChannel, shiftTs}
        end
    end
end

registerCommand("d", function(where, to, text)
    local message
    message = "[" .. where .. "] - [" .. to .. "] " .. text
    return message
end)
Мне нужно, чтобы при отправке RPC пакета подменялась строка, что уже реализовано, однако, при этом нужно проиграть несколько команд, сопровождаемые ожиданием через wait(number), какие есть варианты включить потоки в выполнение функции, не создая поток во втором аргументе функции registerCommand каждый раз?