Отловить текст в текстдраве

Pixzel

Известный
Автор темы
55
21
Версия SA-MP
  1. Любая
Привет
Как мне изменить этот кусок, чтобы я опять мог ловить нужный мне текст?:
Как было:
function ev.onDisplayGameText(style, time, text)
    if check.act[0] then
        if text:find('buy') then
            check.buy = check.buy + 1
        end
        if text:find('sell') then
            check.sell = check.sell + 1
        end

Раньше на сервере это был ГеймТекст, а сейчас сделано через ТекстДрав, соответственно мой скрипт перестал работать, хочу поправить
Id текстдрава 2050.
 

Andrinall

Известный
680
532
Привет
Как мне изменить этот кусок, чтобы я опять мог ловить нужный мне текст?:
Как было:
function ev.onDisplayGameText(style, time, text)
    if check.act[0] then
        if text:find('buy') then
            check.buy = check.buy + 1
        end
        if text:find('sell') then
            check.sell = check.sell + 1
        end

Раньше на сервере это был ГеймТекст, а сейчас сделано через ТекстДрав, соответственно мой скрипт перестал работать, хочу поправить
Id текстдрава 2050.
Проверки по ID текстдрава не лучшая практика
Lua:
function ev.onShowTextdraw(tdid, data)
    local temp = data.text:gsub("(%~.%~)", "")
    if temp:find("^buy$") then
        check.buy = check.buy + 1
    end
    if temp:find("^sell$") then
        check.sell = check.sell + 1
    end
end
 
  • Нравится
Реакции: Pixzel

Pixzel

Известный
Автор темы
55
21
К сожалению нет реакции на появление текстдрава :(
Проверки по ID текстдрава не лучшая практика
Lua:
function ev.onShowTextdraw(tdid, data)
    local temp = data.text:gsub("(%~.%~)", "")
    if temp:find("^buy$") then
        check.buy = check.buy + 1
    end
    if temp:find("^sell$") then
        check.sell = check.sell + 1
    end
end

Вот полный пример как было, прекрасно работало пока текст появлялся в виде ГеймТекста:
Как было::
local ev = require("lib.samp.events")

check = false


function ev.onDisplayGameText(style, time, text)
    lua_thread.create(function()
        if text:find('locked') then
            check = not check
            sampAddChatMessage('МАШИНА ЗАКРЫТА', -1)
        elseif text:find('unlock') then
            check = not check
            sampAddChatMessage('МАШИНА ОТКРЫТА', -1)
            wait(30000)
            check = not check
        end
    end)
end
function main()
    repeat wait(0) until isSampAvailable()
    
    sampRegisterChatCommand('carcheck', function()
        check = not check
        sampAddChatMessage(check and 'Проверяем машину' or 'Не проверяем машину', -1)
    end)
    while true do
        wait(0)
        if check then
            sampSendClickTextdraw(2050)
            wait(12000)
        end
    end
end

Вот что я сделал:

Как я сделал:
local ev = require("lib.samp.events")

check = false


function ev.onShowTextdraw(tdid, data)
    local temp = data.text:gsub("(%~.%~)", "")
    lua_thread.create(function()
        if temp:find("^locked$") then
            check = not check
            sampAddChatMessage('МАШИНА ЗАКРЫТА', -1)
        elseif temp:find("^unlock$") then
            check = not check
            sampAddChatMessage('МАШИНА ОТКРЫТА', -1)
            wait(30000)
            check = not check
        end
    end)
end
function main()
    repeat wait(0) until isSampAvailable()
    
    sampRegisterChatCommand('carcheck', function()
        check = not check
        sampAddChatMessage(check and 'Проверяем машину' or 'Не проверяем машину', -1)
    end)
    while true do
        wait(0)
        if check then
            sampSendClickTextdraw(2050)
            wait(12000)
        end
    end
end

К сожалению реакции на появление текстдрава нет
Может я что-то не так сделал?
 

Andrinall

Известный
680
532
К сожалению нет реакции на появление текстдрава :(


Вот полный пример как было, прекрасно работало пока текст появлялся в виде ГеймТекста:
Как было::
local ev = require("lib.samp.events")

check = false


function ev.onDisplayGameText(style, time, text)
    lua_thread.create(function()
        if text:find('locked') then
            check = not check
            sampAddChatMessage('МАШИНА ЗАКРЫТА', -1)
        elseif text:find('unlock') then
            check = not check
            sampAddChatMessage('МАШИНА ОТКРЫТА', -1)
            wait(30000)
            check = not check
        end
    end)
end
function main()
    repeat wait(0) until isSampAvailable()
    
    sampRegisterChatCommand('carcheck', function()
        check = not check
        sampAddChatMessage(check and 'Проверяем машину' or 'Не проверяем машину', -1)
    end)
    while true do
        wait(0)
        if check then
            sampSendClickTextdraw(2050)
            wait(12000)
        end
    end
end

Вот что я сделал:

Как я сделал:
local ev = require("lib.samp.events")

check = false


function ev.onShowTextdraw(tdid, data)
    local temp = data.text:gsub("(%~.%~)", "")
    lua_thread.create(function()
        if temp:find("^locked$") then
            check = not check
            sampAddChatMessage('МАШИНА ЗАКРЫТА', -1)
        elseif temp:find("^unlock$") then
            check = not check
            sampAddChatMessage('МАШИНА ОТКРЫТА', -1)
            wait(30000)
            check = not check
        end
    end)
end
function main()
    repeat wait(0) until isSampAvailable()
    
    sampRegisterChatCommand('carcheck', function()
        check = not check
        sampAddChatMessage(check and 'Проверяем машину' or 'Не проверяем машину', -1)
    end)
    while true do
        wait(0)
        if check then
            sampSendClickTextdraw(2050)
            wait(12000)
        end
    end
end

К сожалению реакции на появление текстдрава нет
Может я что-то не так сделал?

ну, как минимум, можешь через print вывести текст текстдрава и глянуть что там да как.
Например, после вырезки возможных вставок цвета - print(temp)
И дальше уже корректировать.
 
  • Нравится
Реакции: YarikVL и Pixzel

Pixzel

Известный
Автор темы
55
21
ну, как минимум, можешь через print вывести текст текстдрава и глянуть что там да как.
Например, после вырезки возможных вставок цвета - print(temp)
И дальше уже корректировать.

То есть нужно делать так?

?:
if temp:find("^~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~CAR~g~ UNLOCK$")
 

Andrinall

Известный
680
532
То есть нужно делать так?

?:
if temp:find("^~w~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~CAR~g~ UNLOCK$")
Тогда уж так.
Lua:
local temp = data.text:gsub("(%~.%~)", ""):lower()
if temp:find("^car unlock$") then
    -- code
end

изображение_2023-04-07_184257935.png
 
  • Нравится
Реакции: Pixzel