После поиска в OnServerMessage не выводит сообщение в чат

Yaroslav001

Новичок
Автор темы
10
1
Версия MoonLoader
.026-beta
Не выводится сообщение после поиска его в чате


Lua:
script_author('Clinya')
script_name('Счетчик баллов')

local inicfg = require 'inicfg'
local sampev = require 'samp.events'
local vkeys = require 'vkeys'

_, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)

local defsets = {
    main = {
        score = 0,
        nick = sampGetPlayerNickname(myid)
    },
}
if not doesDirectoryExist('moonloader/config') then
    createDirectory('moonloader/config')
end
if not doesFileExist('moonloader/config/score.ini') then
    inicfg.save(defsets,'score.ini')
end
local sets = inicfg.load(defsets,'score.ini')
local settings = sets.main
local score = settings.score
local nick = settings.nick

function main ()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    wait(1000)
    sampAddChatMessage(string.format('[Счетчик Баллов]: Приветствую, %s. Основные команды для работы - /ss, /gs',sampGetPlayerNickname(myid):gsub("_"," ")),-1)
    sampAddChatMessage('Помощь по скрипту - /shelp',-1)
    if nick == 'Ketrin_Murrr' then
        sampAddChatMessage('Люблю тебя, зайчонок',-1)
    end
    load()
    sampRegisterChatCommand('gs',function()
        sampAddChatMessage("У вас "..score.." баллов",-1)
    end)
    sampRegisterChatCommand('shelp',function()
        sampAddChatMessage("/ss - изменить кол-во баллов",-1)
        sampAddChatMessage("/gs - посмотреть баллы",-1)
    end)
    sampRegisterChatCommand('ss',function(arg)
        score = arg
        sampAddChatMessage("Вы успешно изменили значение на "..score,-1)
        save()
    end)
    sampRegisterChatCommand('sn',function(arg)
        nick = arg
        sampAddChatMessage("Вы успешно изменили значение на "..nick,-1)
        save()
    end)
    while true do
        wait (0)
    end
end

function save()
    settings.score = score
    settings.nick = nick
    inicfg.save(sets,"score.ini")
end

function load()
    score = settings.score
    nick = settings.nick
end

function sampev.onServerMessage(color,text)
    if text:find('Вы выдали %w+_%w "Мед. Карта [Полностью здоровый(ая)]" сроком на (%d+) дня(ей).') then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("Вы отправили предложение о лечении.") then
        sampAddChatMessage('{96bd8a}[Информация] {FFFFFF}Вы отправили предложение о лечении.',-1)
        score = score + 1
        sampAddChatMessage('+1 балл, уже '..score,-1)
    end
    if text:find("Вы вылечили (%w+_%w+) за $(%d+).") then 
        score = score + 1
        sampAddChatMessage('+1 балл, уже '..score,-1)
        time()
        save()
    end
    if text:find("Игрок полностью вакцинирован.") then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("Вы начали лечение %w+_%w+ от наркозависимости за $(%d+).") then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("(%w+_%w+)%[(%d+)%] доставил 100 медикаментов на склад больницы!") then
        local name, id = text:match("(%w+_%w+)%[(%d+)%] доставил 100 медикаментов на склад больницы!")
        if name == nick then
            score = score + 2
            sampAddChatMessage('+2 балла, уже '..score,-1)
            time()
            save()
        end
    end
end

function time()
    lua_thread.create(function()
        sampSendChat("/time")
        wait(1500)
        setVirtualKeyDown(vkeys.VK_F8, true)
        wait(20)
        setVirtualKeyDown(vkeys.VK_F8, false)
    end)
end
Почему не возвращается строчка? Помогите, пожалуйста

Много чего пробовал, поэтому некоторые регулярные выражения взяты в скобки. Также код полусырой, так что не бейте)
 
  • Нравится
Реакции: Катя 228

Dmitriy Makarov

25.05.2021
Проверенный
2,478
1,113
Lua:
function sampev.onServerMessage(color,text)
    if text:find('Вы выдали %w+_%w "Мед%. Карта %[Полностью здоровый%(ая%)%]" сроком на (%d+) дня%(ей%)%.') then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("Вы отправили предложение о лечении.") then
        sampAddChatMessage('{96bd8a}%[Информация%] {FFFFFF}Вы отправили предложение о лечении%.',-1)
        score = score + 1
        sampAddChatMessage('+1 балл, уже '..score,-1)
    end
    if text:find("Вы вылечили (%w+_%w+) за %$(%d+).") then
        score = score + 1
        sampAddChatMessage('+1 балл, уже '..score,-1)
        time()
        save()
    end
    if text:find("Игрок полностью вакцинирован.") then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("Вы начали лечение %w+_%w+ от наркозависимости за %$%(%d+%)%.") then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("(%w+_%w+)%[(%d+)%] доставил 100 медикаментов на склад больницы%!") then
        local name, id = text:match("(%w+_%w+)%[(%d+)%] доставил 100 медикаментов на склад больницы!")
        if name == nick then
            score = score + 2
            sampAddChatMessage('+2 балла, уже '..score,-1)
            time()
            save()
        end
    end
end
 

Yaroslav001

Новичок
Автор темы
10
1
Lua:
function sampev.onServerMessage(color,text)
    if text:find('Вы выдали %w+_%w "Мед%. Карта %[Полностью здоровый%(ая%)%]" сроком на (%d+) дня%(ей%)%.') then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("Вы отправили предложение о лечении.") then
        sampAddChatMessage('{96bd8a}%[Информация%] {FFFFFF}Вы отправили предложение о лечении%.',-1)
        score = score + 1
        sampAddChatMessage('+1 балл, уже '..score,-1)
    end
    if text:find("Вы вылечили (%w+_%w+) за %$(%d+).") then
        score = score + 1
        sampAddChatMessage('+1 балл, уже '..score,-1)
        time()
        save()
    end
    if text:find("Игрок полностью вакцинирован.") then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("Вы начали лечение %w+_%w+ от наркозависимости за %$%(%d+%)%.") then
        score = score + 2
        sampAddChatMessage('+2 балла, уже '..score,-1)
        time()
        save()
    end
    if text:find("(%w+_%w+)%[(%d+)%] доставил 100 медикаментов на склад больницы%!") then
        local name, id = text:match("(%w+_%w+)%[(%d+)%] доставил 100 медикаментов на склад больницы!")
        if name == nick then
            score = score + 2
            sampAddChatMessage('+2 балла, уже '..score,-1)
            time()
            save()
        end
    end
end
Не помогло, все точно также