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

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



 

Kun_Vays

Новичок
Автор темы
19
0
local lineIndex = 0
перед хуком объяви
: attempt to perform arithmetic on a nil value
stack traceback:
E:\ARIZONA GAMES\bin\Arizona\moonloader\trucker.lua:144: in function 'callback'
Lua:
function sampev.onShowDialog(id, style, title, b1, b2, text)
    local lineIndex = -1
    for line in text:gmatch("[^\n]+") do
       lineIndex = lineIndex + 1
       local lineIndex = 0   -- если я верно обьявил
       if lineIndex == tonumber(slot_text.v) - 1 then     --строка 144
           selected_slot_text = line
       end
    end
end
 

moreveal

Известный
Проверенный
859
539
Lua:
local lineIndex = 0
function sampev.onShowDialog(id, style, title, b1, b2, text)
    local lineIndex = -1
    for line in text:gmatch("[^\n]+") do
       lineIndex = lineIndex + 1
       if lineIndex == tonumber(slot_text.v) - 1 then     --строка 144
           selected_slot_text = line
       end
    end
end
зачем два раза лайниндекс объявлять, очевидно ругается на slot_text.v