Что не так с этим кодом?

andrey456626

Известный
Автор темы
64
3
Помогите разобраться почему не работает автоответ для арп

Lua:
require 'lib.moonloader'
require 'lib.sampfuncs'
local samp = require 'lib.samp.events'

local answers = {'da', 'tut', 'aga', 'тут', 'Что?', 'а что?'}

function main()
    if not isSampLoaded() and not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    wait(-1)
end

function samp.onServerMessage(clr, text)
    local pattern = text:match('Администратор%s.+%sдля:%s(.+)')
    if pattern ~= nil and pattern:find("тут?") then
        lua_thread.create(function()
            wait(5000)
            sampSendChat('/n ' .. answers[math.random(1, #answers)])
        end)
    end
end
 
Последнее редактирование:

CatKnight

Известный
148
54
Помогите разобраться почему не работает автоответ для арп

Код:
require 'lib.moonloader'
require 'lib.sampfuncs'
local samp = require 'lib.samp.events'

local answers = {'да', 'тут', 'я', 'тут', 'Что?', 'что', 'а, а что?'}

function main()
    if not isSampLoaded() and not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    wait(-1)
end

function samp.onServerMessage(clr, text)
    local pattern = text:match('Администратор%s.+%sдля:%s(.+)')
    if pattern ~= nil and pattern:find("тут?") then
        lua_thread.create(function()
            wait(5000)
            sampSendChat('/n ' .. answers[math.random(1, #answers)])
        end)
    end
end
Бросается в глаза знак вопроса здесь: pattern:find("тут?"). Либо экранируй его через \, либо сделай игнор рег.выражений, отправив вторым аргументом true.
И мимоходом, у тебя функция math.random будет выдавать всегда одно и то же значение. Используй где-нибудь в начале скрипта: math.randomseed(os.clock()^5) или math.randomseed(os.time()).