Работа с чатом

Thomasya

Известный
Автор темы
68
2
Версия MoonLoader
.026-beta
Приветствую мне нужна помощь с кодом, У меня есть часть с кодом которая ищет в чате строку после чего используя ид отправителя желает приятной игры.
Мне нужна помощь с реализацией варнингов на флуд. Помогите пожалуйста.

Lua:
local answers = {}

function sampev.onServerMessage(color, text)
    if text:find('Жалоба от (%w+_?%w+)%[(%d+)%]: {FFCD00}04') then
        local nickRep, idRep = text:match('Жалоба от (%w+_?%w+)%[(%d+)%]: {FFCD00}04')
        answers[#answers + 1] = ('/pm ' .. idRep .. ' Желаю приятной игры, ' .. nickRep .. '!')
    end
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    local pm_timer = os.clock()
    while true do
        if #answers > 0 and os.clock() - pm_timer > 1.5 then -- вместо 1.5 ставишь задержку антифлуда (в секундах)
            pm_timer = os.clock()
            sampSendChat(answers[1])
            table.remove(answers, 1)
        end
        wait(0)
    end
Так-же есть несколько фрагментов из скрипта cosmo
Lua:
function checkFlood(player, text, time)
    for k, v in pairs(log) do
        if k == player then
            if v[1] == text then
                log[k] = { text, log[k][2] + 1, os.time() }
                return true, time - v[3], log[k][2]
            end
        end
    end
    log[player] = { text, 1, time }
    return false
end
Lua:
function writeLog(message)
    if todayPath ~= nil then
        local strLog = string.format('[%s] %s\n', os.date('%H:%M:%S', os.time()), message:gsub('{......}', ''))
         local log = io.open(todayPath, 'a')
        log:write(strLog)
        log:close()
    end
end
(%w+_?%w+)%[(%d+)%]: кричит: обменяю косу +8 на щит на спину/катану!!
 
Последнее редактирование: