Выбор пункта в диалоге по его названию lua

Betskiy

Новичок
Автор темы
10
2
Добрый день, у меня вопрос такой, можно ли как то сделать что бы при открытии диалога, он начинал искать нужный самолет (например перед этим выбрать в менюшке какой самолет искать), и флудил диалогом до тех пор, пока не нашел нужный самолет, потом останавливался? Желательно на луа и чтобы работал в лаунчере аризоны
Вот диалог
XCxDgb9.jpeg

Есть 4 самолета:
Shamal
Nevada
Andromeda
AT400
 

Betskiy

Новичок
Автор темы
10
2
Можешь пожалуйста тут пример написать с моим диалогом? А то не очень понимаю, id диалога 1421
 
  • Эм
Реакции: qdIbp

qdIbp

Автор темы
Проверенный
1,386
1,141
Lua:
local on = require('lib.samp.events')

function sampUseListboxItemByText(did,text, plain)
    if not sampIsDialogActive() then return -1 end
    plain = not (plain == false)
    for i = 0, sampGetListboxItemsCount() - 1 do
        if sampGetListboxItemText(i):find(text, 1, plain) then
            sampSendDialogResponse(did,1, i,nil)
            return i
        end
    end
    return -1
end

function on.onShowDialog(dId, style, title, b1, b2, text)
    if dId == 1421 then
        local index = sampUseListboxItemByText(dId,'AT400')
        local index = sampUseListboxItemByText(dId,'%AT400.-%a+', false)
    end
end

Немного подкорректировал код было времени
 
Последнее редактирование:

Betskiy

Новичок
Автор темы
10
2
Lua:
local on = require('lib.samp.events')

function sampUseListboxItemByText(did,text, plain)
    if not sampIsDialogActive() then return -1 end
    plain = not (plain == false)
    for i = 0, sampGetListboxItemsCount() - 1 do
        if sampGetListboxItemText(i):find(text, 1, plain) then
            sampSendDialogResponse(did,1, i,nil)
            return i
        end
    end
    return -1
end

function on.onShowDialog(dId, style, title, b1, b2, text)
    if dId == 1421 then
        --local index = sampUseListboxItemByText(dId,'AT400') --На выбор 1
        local index = sampUseListboxItemByText(dId,'%AT400.-%a+', false) -- на выбор 2
    end
end

Немного подкорректировал код было времени

Ничего не происходит почему то
 

qdIbp

Автор темы
Проверенный
1,386
1,141
Lua:
local on = require('lib.samp.events')

function sampUseListboxItemByText(did,text, plain)
    if not sampIsDialogActive() then return -1 end
    plain = not (plain == false)
    for i = 0, sampGetListboxItemsCount() - 1 do
        if sampGetListboxItemText(i):find(text, 1, plain) then
            sampSendDialogResponse(did,1, i,nil)
            return i
        end
    end
    return -1
end

function on.onShowDialog(dId, style, title, b1, b2, text)
    if dId == 1421 then
        local index = sampUseListboxItemByText(dId,'AT400')
        local index = sampUseListboxItemByText(dId,'%AT400.-%a+', false)
    end
end

Немного подкорректировал код было времени
Попробуй сейчас
 

qdIbp

Автор темы
Проверенный
1,386
1,141
Lua:
local on = require('lib.samp.events')
function on.onShowDialog(dId, style, title, b1, b2, text)
    local findu = 'Настройки'
    if string.find(text,findu) then
        local index = sampUseListboxItemByText(dId,findu)
    end
end
function sampUseListboxItemByText(id,text, plain)
    --if not sampIsDialogActive() then return -1 end
        plain = not (plain == false)
    for i = 0, sampGetListboxItemsCount() - 1 do
        if sampGetListboxItemText(i):find(text, 1, plain) then
            sampSendDialogResponse(id, 1, i,nil)
            return i
        end
    end
    return -2
end
 

Betskiy

Новичок
Автор темы
10
2
Lua:
local on = require('lib.samp.events')
function on.onShowDialog(dId, style, title, b1, b2, text)
    local findu = 'Настройки'
    if string.find(text,findu) then
        local index = sampUseListboxItemByText(dId,findu)
    end
end
function sampUseListboxItemByText(id,text, plain)
    --if not sampIsDialogActive() then return -1 end
        plain = not (plain == false)
    for i = 0, sampGetListboxItemsCount() - 1 do
        if sampGetListboxItemText(i):find(text, 1, plain) then
            sampSendDialogResponse(id, 1, i,nil)
            return i
        end
    end
    return -2
end
Теперь работает, можно как то теперь сделать что бы когда я нажал Alt на чекпоинте, он искал этот пункт, и если его нет, то закрывал диалог, открывал заново и опять искал, и так до того момента пока не найдет, потом когда найдет, останавливался?
 

qdIbp

Автор темы
Проверенный
1,386
1,141
Lua:
local on = require('lib.samp.events')
function on.onShowDialog(dId, style, title, b1, b2, text)
    local findu = 'Настройки'
    if string.find(text,findu) then
        local index = sampUseListboxItemByText(dId,findu)
        if index == -1 or index == -2 then
            sampSendDialogResponse(dId, 0, nil,nil)
        end
    end
end
function sampUseListboxItemByText(id,text, plain)
    --if not sampIsDialogActive() then return -1 end
        plain = not (plain == false)
    for i = 0, sampGetListboxItemsCount() - 1 do
        if sampGetListboxItemText(i):find(text, 1, plain) then
            sampSendDialogResponse(id, 1, i,nil)
            return i
        end
    end
    return -2
end
 

Betskiy

Новичок
Автор темы
10
2
Lua:
local on = require('lib.samp.events')
function on.onShowDialog(dId, style, title, b1, b2, text)
    local findu = 'Настройки'
    if string.find(text,findu) then
        local index = sampUseListboxItemByText(dId,findu)
        if index == -1 or index == -2 then
            sampSendDialogResponse(dId, 0, nil,nil)
        end
    end
end
function sampUseListboxItemByText(id,text, plain)
    --if not sampIsDialogActive() then return -1 end
        plain = not (plain == false)
    for i = 0, sampGetListboxItemsCount() - 1 do
        if sampGetListboxItemText(i):find(text, 1, plain) then
            sampSendDialogResponse(id, 1, i,nil)
            return i
        end
    end
    return -2
end
Смотри, он чекает диалог, если в нем нет названия самолета, то нечего не происходит, а надо чтобы если нет названия самолета, то он закрывал диалог, открывал его по новой на Alt и опять проверял, и это до тех пор, пока не найдет самолет

И еще такой момент, он получается ищет по конкретному названию, а можно сделать что бы просто слово присутствовало в этом пункте?
Например там есть [AIRLV-9] Nevada, дак вот чтобы то что в скобках не учитывалось, а только Nevada
 
Последнее редактирование:

qdIbp

Автор темы
Проверенный
1,386
1,141
Смотри, он чекает диалог, если в нем нет названия самолета, то нечего не происходит, а надо чтобы если нет названия самолета, то он закрывал диалог, открывал его по новой на Alt и опять проверял, и это до тех пор, пока не найдет самолет

И еще такой момент, он получается ищет по конкретному названию, а можно сделать что бы просто слово присутствовало в этом пункте?
Например там есть [AIRLV-9] Nevada, дак вот чтобы то что в скобках не учитывалось, а только Nevada
Составляй массив самолетов и через for доставай знач массива и потом проверяй

Lua:
local on = require('lib.samp.events')
local stdial = 0
local timer = -1
local air = {
    [417] = 'Leviathon',
    [425] = 'Hunter',
    [487] = 'Maverick',
    [511] = 'Beagle',
    [512] = 'Cropduster',
    [548] = 'Cargobob',
    [553] = 'Nevada',
    [577] = 'AT-400',
    [592] = 'Andromada',
    [593] = 'Dodo'
}
function on.onShowDialog(dId, style, title, b1, b2, text)
    for i, k in pairs(air) do
        if string.find(text,k) then
            local index = sampUseListboxItemByText(dId,k)
            if index == -1 then
                sampSendDialogResponse(dId, 0, nil,nil)
                stdial = 2
            else
                stdial = 1
                timer = os.time() + 3
            end
        end
    end
end
function sampUseListboxItemByText(id,text, plain)
    --if not sampIsDialogActive() then return -1 end
        plain = not (plain == false)
    for i = 0, sampGetListboxItemsCount() -1 do
        if sampGetListboxItemText(i):find(text, 1, plain) then
            sampSendDialogResponse(id, 1, i,nil)
            return i
        end
    end
    return -1
end

function main()
    repeat wait(0) until isSampAvailable()
        --Дрочим в присядку :D
    while true do wait(0)
        if timer < os.time() then
            if stdial == 1 then
                stdial = 0
            elseif stdial == 2 then
                setVirtualKeyDown(18, true) -- 18 id key (alt)
                wait(10)
                setVirtualKeyDown(18, false)
                stdial = 0
            end
        end
    end
end
на так уж и быть, не то там нахерачишь
 
Последнее редактирование: