Вытащить текст из диалога.

Kun_Vays

Новичок
Автор темы
19
0
Версия MoonLoader
.027.0-preview
Здравствуйте, снова.
Ситуация следущея: нужно достать из строки в диалоге текст, но при этом не указывать нужный текст в коде.
То-бишь, просто прочитать текст из строки и вывести его, к примеру в чат.
Заранее спасибо. ☺️

Код, который уже есть:
Lua:
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("Truck Helper. by Kun_Vays", main_window_state, imgui.WindowFlags.NoResize)
        imgui.Text("абв|abc")
        imgui.InputText("id", id_rent_text)
        imgui.InputText("price", price_rent_text)
        imgui.InputText("time", time_rent_text)
        imgui.InputText("слот авто", slot_text)    -- тут пользователь пишет номер строки диалога, то-бишь номер слота, и с него надо достать текст.
        imgui.Text("text")

        local rent_text = id_rent_text.v .. "," .. price_rent_text.v .. "," .. time_rent_text.v
            if imgui.Button("Press me") then
                
                lua_thread.create(function()
                    printStringNow("Progress...", 1500)
                    sampSendChat("/cars")
                    wait(900)
                    sampSendDialogResponse(162, 1, slot_text.v - 1, nil)
                    wait(1100)
                    sampSendDialogResponse(163, 1, 12, nil)
                    wait(1100)
                    sampSetCurrentDialogEditboxText(rent_text)
                    wait(1100)
                    sampSendDialogResponse(25305, 1, 12, rent_text)--id_rent_text.v .. "," .. price_rent_text.v .. "," .. time_rent_text.v)
                    wait(1100)
                    printStringNow("Job done.", 1500)
                end)
            end
        imgui.End()

    end
end


function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 then
        if (wparam == key.VK_ESCAPE and main_window_state.v) and not isPauseMenuActive() then
            consumeWindowMessage(true, false)
            if msg == 0x101 then
                main_window_state.v = false
            end
        end
    end
end



 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,226
1. выбор строки в диалоге лучше заменить с ImBuffer на ImInt
2. писал с телефона, но принцип ты должен увидеть
Lua:
local selected_slot_text = "empty"

function sampev.onShowDialog(id, style, title, b1, b2)
    local lineIndex = -1
    for line in text:gmatch("[^\n]+") do
       lineIndex = lineIndex + 1
       if lineIndex == tonumber(slot_text.v) - 1 then
           selected_slot_text = line
       end
    end
end

--imgui
imgui.Text(selected_slot_text)
 
Последнее редактирование:
  • Нравится
Реакции: zTechnology

Kun_Vays

Новичок
Автор темы
19
0
1. выбор строки в диалоге лучше заменить с ImBuffer на ImInt
2. писал с телефона, но принцип ты должен увидеть
Lua:
local slot_text = "empty"

function sampev.onShowDialog(id, style, title, b1, b2)
    local lineIndex = -1
    for line in text:gmatch("[^\n]+") do
       lineIndex = lineIndex + 1
       if lineIndex == tonumber(slot_text.v) + 1 then
          slot_text = line
       end
    end
end

--imgui
imgui.Text(slot_text)
разве empty не должно быть без скобок?
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,226
разве empty не должно быть без скобок?
всм? я там если что немного накосячил, этот код лучше
Lua:
local selected_slot_text = "empty"

function sampev.onShowDialog(id, style, title, b1, b2)
    local lineIndex = -1
    for line in text:gmatch("[^\n]+") do
       lineIndex = lineIndex + 1
       if lineIndex == tonumber(slot_text.v) - 1 then
           selected_slot_text = line 
       end
    end
end

--imgui
imgui.Text(selected_slot_text)
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,226
"empty" не должно быть без " " ?
нет,
1. “пустое” значение это nil
2. я написал empty сто бы пользователь видел что там нихуя нет
3. если запихнуть нил в имгуи.текст, то скрипт крашнется, так как имгуи.текст принимает тип string, а нил это нил

кстати пофиксить третий пункт можно так:
kmgui.Text(selected_slot_text or ‘дебил, у тя nil’)
 
  • Влюблен
Реакции: Kun_Vays

Kun_Vays

Новичок
Автор темы
19
0
Lua:
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("Truck Helper. by Kun_Vays", main_window_state, imgui.WindowFlags.NoResize)
        imgui.Text("абв|abc")
        imgui.InputText("id", id_rent_text)
        imgui.InputText("price", price_rent_text)
        imgui.InputText("time", time_rent_text)
        imgui.InputText("слот авто", slot_text)    -- тут пользователь пишет номер строки диалога, то-бишь номер слота, и с него надо достать текст.
        imgui.Text("text")

        function sampev.onShowDialog(id, style, title, b1, b2)
            local lineIndex = -1
            for line in text:gmatch("[^\n]+") do
               lineIndex = lineIndex + 1
               if lineIndex == tonumber(slot_text.v) - 1 then
                   selected_slot_text = line
               end
            end
        end
     
        imgui.Text(selected_slot_text)
я куда то не туда его впхнул. забыл еще сказать в самом начале, нужно при нажатии на кнопку выводить текст из строки.


_____________________________________________________________________
Lua:
if imgui.Button("Press me") then
              
                lua_thread.create(function()
                    printStringNow("Progress...", 1500)
                    sampSendChat("/cars")
                    wait(1100)
                    function sampev.onShowDialog(id, style, title, b1, b2)
                        local lineIndex = -1
                        for line in text:gmatch("[^\n]+") do
                           lineIndex = lineIndex + 1
                           if lineIndex == tonumber(slot_text.v) - 1 then
                               selected_slot_text = line
                           end
                        end
                    end
                  
                    sampAddChatMessage(selected_slot_text)
                    wait(1100)
                    sampSendDialogResponse(162, 1, slot_text.v - 1, nil)
                    wait(1100)
                    sampSendDialogResponse(163, 1, 12, nil)
                    wait(1100)
                    sampSetCurrentDialogEditboxText(rent_text)
                    wait(1100)
                    sampSendDialogResponse(25305, 1, 12, rent_text)--id_rent_text.v .. "," .. price_rent_text.v .. "," .. time_rent_text.v)
                    wait(1100)
                    printStringNow("Job done.", 1500)
                end)
            endv

решил засунуть его в кнопку, вот что получилось.

14.32.56.031.jpg
 
Последнее редактирование:
  • Bug
Реакции: zTechnology

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,226
  • Нравится
Реакции: ARMOR

Kun_Vays

Новичок
Автор темы
19
0
Lua:
local sampev = require "samp.events"
local selected_slot_text = imgui.ImBuffer("", 256)
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("Truck Helper. by Kun_Vays", main_window_state, imgui.WindowFlags.NoResize)
        imgui.Text("абв|abc")
        imgui.InputText("id", id_rent_text)
        imgui.InputText("price", price_rent_text)
        imgui.InputText("time", time_rent_text)
        imgui.InputText("слот авто", slot_text)    -- тут пользователь пишет номер строки диалога, то-бишь номер слота, и с него надо достать текст.
        imgui.Text("text")
        imgui.Text(selected_slot_text.v)

        local rent_text = id_rent_text.v .. "," .. price_rent_text.v .. "," .. time_rent_text.v
            if imgui.Button("Press me") then
              
                lua_thread.create(function()
                    printStringNow("Progress...", 1500)
                    sampSendChat("/cars")
                    wait(900)
                    sampSendDialogResponse(162, 1, slot_text.v - 1, nil)
                    wait(1100)
                    sampSendDialogResponse(163, 1, 12, nil)
                    wait(1100)
                    sampSetCurrentDialogEditboxText(rent_text)
                    wait(1100)
                    sampSendDialogResponse(25305, 1, 12, rent_text)--id_rent_text.v .. "," .. price_rent_text.v .. "," .. time_rent_text.v)
                    wait(1100)
                    printStringNow("Job done.", 1500)
                end)
            end
        imgui.End()

    end
end


function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 then
        if (wparam == key.VK_ESCAPE and main_window_state.v) and not isPauseMenuActive() then
            consumeWindowMessage(true, false)
            if msg == 0x101 then
                main_window_state.v = false
            end
        end
    end
end
function sampev.onShowDialog(id, style, title, b1, b2)
    local lineIndex = -1
    for line in text:gmatch("[^\n]+") do
       lineIndex = lineIndex + 1
       if lineIndex == tonumber(slot_text.v) - 1 then
           selected_slot_text.v = line
       end
    end
end
attempt to index global 'text' (a nil value)
stack traceback:
E:\ARIZONA GAMES\bin\Arizona\moonloader\trucker.lua:139: in function 'callback'

Lua:
    for line in text:gmatch("[^\n]+") do   -- ругает эту строку