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

Я кавказец

Известный
Автор темы
440
106
Короче скрипт должен открыть /settings И если найдет Damage informer: [Выключено], то должен выбрать этот пункт и включить его. Подскажите как это реализовать в плане кода

Moonloader 0.26
 
Решение
Код не работает, в отдельный файл его запихнул, зашел и просто открывает /settings и ничего
Lua:
local sampev = require 'lib.samp.events'

function main()
    repeat wait(0) until isSampAvailable()
    repeat wait(100) until sampIsLocalPlayerSpawned()
    sampSendChat('/settings')
end

function sampev.onShowDialog(id, style, title, button1, button2, tekst)
      if tekst:find('Damage informer:.+%[Выключено%]') then
            lua_thread.create(function()
            wait(0) --увеличь здесь задержку, если диалог долго не появляется и скрипт не успевает нажать
            listbox = sampGetListboxItemByText('Damage informer')
            sampSendDialogResponse(id, 1, listbox, nil)
            thisScript():unload() --сотри эту...

Adrian G.

Известный
Проверенный
521
453
Lua:
local sampev = require 'lib.samp.events'
function main()
    repeat wait(0) until isSampAvailable()
    repeat wait(100) until sampIsLocalPlayerSpawned()
    sampSendChat('/settings')
end

function sampev.onShowDialog(id, style, title, button1, button2, tekst)
    if tekst:find('Damage informer: %[Выключено%]') then
        listbox = sampGetListboxItemByText('Damage informer')
        sampSendDialogResponse(id, 0, listbox, nil)
    end
end

function sampGetListboxItemByText(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
            return i
        end
    end
    return -1
end
 
  • Нравится
Реакции: HickRus

Я кавказец

Известный
Автор темы
440
106
Lua:
local sampev = require 'lib.samp.events'
function main()
    repeat wait(0) until isSampAvailable()
    repeat wait(100) until sampIsLocalPlayerSpawned()
    sampSendChat('/settings')
end

function sampev.onShowDialog(id, style, title, button1, button2, tekst)
    if tekst:find('Damage informer: %[Выключено%]') then
        listbox = sampGetListboxItemByText('Damage informer')
        sampSendDialogResponse(id, 0, listbox, nil)
    end
end

function sampGetListboxItemByText(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
            return i
        end
    end
    return -1
end
Распеши пжпж что за что отвечает, нихуа не понимаю ))
upd попробовал код, не робит. Библиотеку импортировал и скрипт запустился, но включение damage informer не происходит.
 
Последнее редактирование:

VRush

https://t.me/vrushscript
Проверенный
2,344
1,091
Распеши пжпж что за что отвечает, нихуа не понимаю ))
upd попробовал код, не робит. Библиотеку импортировал и скрипт запустился, но включение damage informer не происходит.
Код:
local sampev = require 'lib.samp.events'
function main()
    repeat wait(0) until isSampAvailable()
    repeat wait(100) until sampIsLocalPlayerSpawned()
    sampSendChat('/settings')
end

function sampev.onShowDialog(id, style, title, button1, button2, tekst)
    if tekst:find('Damage informer: %[Выключено%]') then -- если в диалоге будет текст тогда
        listbox = sampGetListboxItemByText('Damage informer') -- получаем номен строки с текстом
        sampSendDialogResponse(id, 0, listbox, nil) -- скрипт нажимает на ту строку
    end
end

function sampGetListboxItemByText(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
            return i
        end
    end
    return -1
end
 

Я кавказец

Известный
Автор темы
440
106
Код:
local sampev = require 'lib.samp.events'
function main()
    repeat wait(0) until isSampAvailable()
    repeat wait(100) until sampIsLocalPlayerSpawned()
    sampSendChat('/settings')
end

function sampev.onShowDialog(id, style, title, button1, button2, tekst)
    if tekst:find('Damage informer: %[Выключено%]') then -- если в диалоге будет текст тогда
        listbox = sampGetListboxItemByText('Damage informer') -- получаем номен строки с текстом
        sampSendDialogResponse(id, 0, listbox, nil) -- скрипт нажимает на ту строку
    end
end

function sampGetListboxItemByText(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
            return i
        end
    end
    return -1
end
Код не работает, в отдельный файл его запихнул, зашел и просто открывает /settings и ничего
 

Я кавказец

Известный
Автор темы
440
106
Безымянный.png
 

Adrian G.

Известный
Проверенный
521
453
Код не работает, в отдельный файл его запихнул, зашел и просто открывает /settings и ничего
Lua:
local sampev = require 'lib.samp.events'

function main()
    repeat wait(0) until isSampAvailable()
    repeat wait(100) until sampIsLocalPlayerSpawned()
    sampSendChat('/settings')
end

function sampev.onShowDialog(id, style, title, button1, button2, tekst)
      if tekst:find('Damage informer:.+%[Выключено%]') then
            lua_thread.create(function()
            wait(0) --увеличь здесь задержку, если диалог долго не появляется и скрипт не успевает нажать
            listbox = sampGetListboxItemByText('Damage informer')
            sampSendDialogResponse(id, 1, listbox, nil)
            thisScript():unload() --сотри эту строку, если не хочешь, чтобы скрипт выгружался после нажатия
            end)
      end
end

function sampGetListboxItemByText(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
            return i
        end
    end
    return -1
end