Как реализовать работу с диалогами?

TwixRoth

Новичок
Автор темы
10
0
Версия MoonLoader
.027.0-preview
Всем ку, ищу способ или пример кода, чтобы реализовать бота для работы с диалогами, весь интернет перерыл, пытался писать и брал чужие коды но они не видят диалог ни по айди (он там у всех одинаковый) не по стилю, ни по названию, ни по поиску текста) трудно очень, может я что-то не то делаю, решаюсь узнать у знающих людей,

Суть работы:
Нажимает альт если нету диалога,
Если открылся диалог с названием "пример1" то выбирает пункт 1,
Далее если открыт другой диалог, то выбирает пункт 2, итд

И еще:
Если найден нужный диалог, то
Искать текст "текст 1" из всего содержимого диалога, если найден , то выбирать 2 пункт, если "текст 2" то 3 пункт, и так по новой
Чтобы был цикл и если их нету (диалогов), там 2-3 секунды, то нажимать альт.

Заранее спасибо!
 

fokichevskiy

Известный
505
305
обрати внимание на то, что названия диалогов и текста внутри них могут обладать разным регистром(т.е. не "п", а "П"), так что используй сниппет string.nlower для кириллицы после кода.

Lua:
local sampev = require('lib.samp.events')
local active = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('act', function ()
        active = not active
        sampAddChatMessage('флудер ' .. (active and 'включен' or 'выключен'), -1)
    end)
    lua_thread.create(function ()
        while true do
            wait(500)
            if active then
                setGameKeyState(21, -256)
                wait(200)
                setGameKeyState(21, 0)
            end
        end
    end)
end


function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if active then
        if title == 'пример1' then
            active = false
            sampSendDialogResponse(dialogId, 1, 1, '')
            active = true
        else
            active = false
            sampSendDialogResponse(dialogId, 1, 2, '')
            active = true
        end

        -- реализация поиска текста в диалоге
        if title == 'нужный диалог' then
            if text:find('текст 1') then
                active = false
                sampSendDialogResponse(dialogId, 1, 2, '')
            elseif text:find('текст 2') then
                active = false
                sampSendDialogResponse(dialogId, 1, 3, '')
            end
        end
       return false
    end
end


string.nlower от iniring

Lua:
local lower, sub, char, upper = string.lower, string.sub, string.char, string.upper
local concat = table.concat

-- initialization table
local lu_rus, ul_rus = {}, {}
for i = 192, 223 do
    local A, a = char(i), char(i + 32)
    ul_rus[A] = a
    lu_rus[a] = A
end
local E, e = char(168), char(184)
ul_rus[E] = e
lu_rus[e] = E

function string.nlower(s)
    s = lower(s)
    local len, res = #s, {}
    for i = 1, len do
        local ch = sub(s, i, i)
        res[i] = ul_rus[ch] or ch
    end
    return concat(res)
end

function string.nupper(s)
    s = upper(s)
    local len, res = #s, {}
    for i = 1, len do
        local ch = sub(s, i, i)
        res[i] = lu_rus[ch] or ch
    end
    return concat(res)
end
 
Последнее редактирование:

TwixRoth

Новичок
Автор темы
10
0
обрати внимание на то, что названия диалогов и текста внутри них могут обладать разным регистром(т.е. не "п", а "П"), так что используй сниппет string.nlower для кириллицы после кода.

Lua:
local sampev = require('lib.samp.events')
local active = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('act', function ()
        active = not active
        sampAddChatMessage('флудер ' .. (active and 'включен' or 'выключен'), -1)
    end)
    lua_thread.create(function ()
        while true do
            wait(500)
            if active then
                setGameKeyState(21, -256)
                wait(200)
                setGameKeyState(21, 0)
            end
        end
    end)
end


function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if active then
        if title == 'пример1' then
            active = false
            sampSendDialogResponse(dialogId, 1, 1, '')
            active = true
            return false
        else
            active = false
            sampSendDialogResponse(dialogId, 1, 2, '')
            active = true
            return false
        end

        -- реализация поиска текста в диалоге
        if title == 'нужный диалог' then
            if text:find('текст 1') then
                active = false
                sampSendDialogResponse(dialogId, 1, 2, '')
                return false
            elseif text:find('текст 2') then
                active = false
                sampSendDialogResponse(dialogId, 1, 3, '')
                return false
            end
        end
    end
end


string.nlower от iniring

Lua:
local lower, sub, char, upper = string.lower, string.sub, string.char, string.upper
local concat = table.concat

-- initialization table
local lu_rus, ul_rus = {}, {}
for i = 192, 223 do
    local A, a = char(i), char(i + 32)
    ul_rus[A] = a
    lu_rus[a] = A
end
local E, e = char(168), char(184)
ul_rus[E] = e
lu_rus[e] = E

function string.nlower(s)
    s = lower(s)
    local len, res = #s, {}
    for i = 1, len do
        local ch = sub(s, i, i)
        res[i] = ul_rus[ch] or ch
    end
    return concat(res)
end

function string.nupper(s)
    s = upper(s)
    local len, res = #s, {}
    for i = 1, len do
        local ch = sub(s, i, i)
        res[i] = lu_rus[ch] or ch
    end
    return concat(res)
end
А если, текст в диалоге окрашенный?
Там желтый белый итд
 

TwixRoth

Новичок
Автор темы
10
0

fokichevskiy

Известный
505
305
вот так?

Lua:
local sampev = require('lib.samp.events')
local active = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('act', function ()
        active = not active
        sampAddChatMessage('флудер ' .. (active and 'включен' or 'выключен'), -1)
    end)
    lua_thread.create(function ()
        while true do
            wait(500)
            if active then
                setGameKeyState(21, -256)
                wait(200)
                setGameKeyState(21, 0)
            end
        end
    end)
end


function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if active then
        if title:find('Подвал') then
            active = false
            sampSendDialogResponse(dialogId, 1, 0, '')
        elseif title:find('семена') then
            sampSendDialogResponse(dialogId, 1, 0, '1')
        elseif title:find('ферма') then
            if text:find("семян:%s*0гр") then
                sampSendDialogResponse(dialogId, 1, 1, '')
            else
                sampSendDialogResponse(dialogId, 1, 2)
            end
        end
        return false
    end 
end
 

TwixRoth

Новичок
Автор темы
10
0
вот так?

Lua:
local sampev = require('lib.samp.events')
local active = false

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('act', function ()
        active = not active
        sampAddChatMessage('флудер ' .. (active and 'включен' or 'выключен'), -1)
    end)
    lua_thread.create(function ()
        while true do
            wait(500)
            if active then
                setGameKeyState(21, -256)
                wait(200)
                setGameKeyState(21, 0)
            end
        end
    end)
end


function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if active then
        if title:find('Подвал') then
            active = false
            sampSendDialogResponse(dialogId, 1, 0, '')
        elseif title:find('семена') then
            sampSendDialogResponse(dialogId, 1, 0, '1')
        elseif title:find('ферма') then
            if text:find("семян:%s*0гр") then
                sampSendDialogResponse(dialogId, 1, 1, '')
            else
                sampSendDialogResponse(dialogId, 1, 2)
            end
        end
        return false
    end
end
А чтоб включить отображение диалогов надо,
Return false на true поставить?
 

OttoMorteus

Участник
11
4
Переменной active присвоить false. (Команда /act в коде выше)
Вот пример кода который скрывает все диалоги.
Lua:
local sampev = require('lib.samp.events')

function cmd_disableDialogs(arg)
    state = not state
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("dstate", cmd_disableDialogs)
    while true do wait(0)
    end
end

function sampev.onShowDialog(id, style, title, button1, button2, text)
    if state then
        return false
    end
end
По команде /dstate включает и отключает показ диалогов.
 
  • Эм
Реакции: fokichevskiy

TwixRoth

Новичок
Автор темы
10
0
Диалоги показывает альт нажимает а дальше просто стоит на первом диалоге где "Подвал", вот ошибка повторяется я хз толи он не видит толи я дурак. Если надо могу видео показать
Может дело в сборке? Раньше диалоги открывались в таком же стиле как и на телефонах, но сейчас в таком как на видео, хотя другие текстуры остались


Вот так у меня раньше выглядели диалоги, вид с телефона:
Хз почему они пропали на пк, уже неск дней такая херь
 

Вложения

  • Screenshot_20250726-163902.jpg
    Screenshot_20250726-163902.jpg
    757.9 KB · Просмотры: 6
Последнее редактирование: