onServerMessage

Zverina

Участник
Автор темы
24
0
Версия MoonLoader
.026-beta
Lua:
string.find(text, '%[POLICE%] .+%[(%d+)%]: .+')
Строка игре выглядит так:
Код:
 [POLICE] Nikita_Pupov[14]: /su 13 6 У.К. 123
Правильно ли я сделал string.find? и как сделать так, чтобы я при вводе команды /yes - ввёл в чат этот же " /su 13 6 У.К. 123 "?
 
Решение
Lua:
local msg
function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('yes', function()
        sampSendChat(msg)
        sampAddChatMessage('наказание выдано', -1)
    end)
    wait(-1)
end
local tbl = {'su', 'lic'}
local function match(s)
    for i = 1, #tbl do
        local p = s:match('%[POLICE] .+%[%d+]: (/'..tbl[i]..' .+)')
        if p then return p end
    end
end

require('samp.events').onServerMessage = function(clr, text)
    if match(text)
        sampAddChatMessage('Поступила заявка. Чтобы оформить розыск введите /yes')
        msg = match(text)
    end
end

Zverina

Участник
Автор темы
24
0
Ничего не понятно. Вот смотри, есть функция ловли чата:
Lua:
function sampev.onServerMessage(color, text)
    if string.find(text, '%[POLICE%] .+%[(%d+)%]: .+') then
        sampAddChatMessage('Поступила заявка. Чтобы оформить розыск введите /yes')
    end
end
Вот команда:
Lua:
function cmd_yes(arg)
    sampAddChatMessage('Вы выдали наказание по последнему запросу!', -1)
end
 

sᴀxᴏɴ

Известный
Всефорумный модератор
788
855
Lua:
local msg
function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('yes', function()
        sampSendChat(msg)
        sampAddChatMessage('наказание выдано', -1)
    end)
    wait(-1)
end

require('samp.events').onServerMessage = function(clr, text)
    local p = text:match('%[POLICE] .+%[%d+]: (/su .+)')
    if p then
        sampAddChatMessage('Поступила заявка. Чтобы оформить розыск введите /yes')
        msg = p
    end
end
 

sᴀxᴏɴ

Известный
Всефорумный модератор
788
855
Lua:
local msg
function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('yes', function()
        sampSendChat(msg)
        sampAddChatMessage('наказание выдано', -1)
    end)
    wait(-1)
end

local function match(s)
    return s:match('%[POLICE] .+%[%d+]: (/su .+)') or s:match('%[POLICE] .+%[%d+]: (/lic .+)')
end

require('samp.events').onServerMessage = function(clr, text)
    if match(text)
        sampAddChatMessage('Поступила заявка. Чтобы оформить розыск введите /yes')
        msg = match(text)
    end
end
 

sᴀxᴏɴ

Известный
Всефорумный модератор
788
855
Lua:
local msg
function main()
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('yes', function()
        sampSendChat(msg)
        sampAddChatMessage('наказание выдано', -1)
    end)
    wait(-1)
end
local tbl = {'su', 'lic'}
local function match(s)
    for i = 1, #tbl do
        local p = s:match('%[POLICE] .+%[%d+]: (/'..tbl[i]..' .+)')
        if p then return p end
    end
end

require('samp.events').onServerMessage = function(clr, text)
    if match(text)
        sampAddChatMessage('Поступила заявка. Чтобы оформить розыск введите /yes')
        msg = match(text)
    end
end
 

sᴀxᴏɴ

Известный
Всефорумный модератор
788
855
Блин, помог, спасибо. А возможно ли сделать типо если pnumber = 1, то local tbl = {'su', 'lic'}, если pnumber = 2, то local tbl = {'su', 'lic', 'wiz'}
Если поможешь и с этим, буду признателен!
используй if pnumber == 2 then table.insert(tbl, 'wiz') end
чет такое