Как сохранять аргумент который игрок ввел в команду

KenDDD

Участник
Автор темы
15
3
Версия MoonLoader
.026-beta
Привет, не знаю как сохранять аргументы, при вводе команды /sticket нужно сделать(подскажите как?) аргументы, и сохранить их, после прочитать их при нажатии на имгуи кнопку.
Помогите это сделать.
Код имгуи кнопки:
Код:
local main_window_state = imgui.ImBool(false)
function imgui.OnDrawFrame()
  if main_window_state.v then
    imgui.SetNextWindowSize(imgui.ImVec2(1047, 417), imgui.Cond.FirstUseEver)
    imgui.Begin('AvtoStraf', main_window_state)
    if imgui.Button('Press me', imgui.ImVec2(1067, 70)) then
    sampAddChatMessage('Привет', 0xFFFFFFFF)
    end
    imgui.End()
  end
end
Команда открытия имгуи окна(function main)
Код:
function main()
     while not isSampAvailable() do wait(200) end
    sampRegisterChatCommand('sticket', function()
    main_window_state.v = not main_window_state.v
    end)
    imgui.Process = false
    main_window_state.v = false  
    while true do
        wait(0)
        imgui.Process = main_window_state.v
  end
end
P.S если что то не понятно объяснил, пишите в тему, более подробно могу рассказать.
 
Решение
Lua:
local main_window_state = imgui.ImBool(false)
local enterArg = nil

function main()
    while not isSampAvailable() do wait(200) end
    sampRegisterChatCommand('sticket', function(arg)
        if arg then
            enterArg = arg
            main_window_state.v = not main_window_state.v
        else
            sampAddChatMessage('/sticket [arg]', -1)
        end
    end)
    imgui.Process = false
    main_window_state.v = false 
    while true do
        wait(0)
        imgui.Process = main_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(1047, 417), imgui.Cond.FirstUseEver)
        imgui.Begin('AvtoStraf', main_window_state)
            if...

meowprd

Тот самый Котовский
Проверенный
1,283
711
Lua:
local main_window_state = imgui.ImBool(false)
local enterArg = nil

function main()
    while not isSampAvailable() do wait(200) end
    sampRegisterChatCommand('sticket', function(arg)
        if arg then
            enterArg = arg
            main_window_state.v = not main_window_state.v
        else
            sampAddChatMessage('/sticket [arg]', -1)
        end
    end)
    imgui.Process = false
    main_window_state.v = false 
    while true do
        wait(0)
        imgui.Process = main_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(1047, 417), imgui.Cond.FirstUseEver)
        imgui.Begin('AvtoStraf', main_window_state)
            if imgui.Button('Press me', imgui.ImVec2(1067, 70)) then
                sampAddChatMessage(enterArg, 0xFFFFFFFF)
            end
        imgui.End()
    end
end
 

KenDDD

Участник
Автор темы
15
3
Lua:
local main_window_state = imgui.ImBool(false)
local enterArg = nil

function main()
    while not isSampAvailable() do wait(200) end
    sampRegisterChatCommand('sticket', function(arg)
        if arg then
            enterArg = arg
            main_window_state.v = not main_window_state.v
        else
            sampAddChatMessage('/sticket [arg]', -1)
        end
    end)
    imgui.Process = false
    main_window_state.v = false
    while true do
        wait(0)
        imgui.Process = main_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(1047, 417), imgui.Cond.FirstUseEver)
        imgui.Begin('AvtoStraf', main_window_state)
            if imgui.Button('Press me', imgui.ImVec2(1067, 70)) then
                sampAddChatMessage(enterArg, 0xFFFFFFFF)
            end
        imgui.End()
    end
end
Привет, спасибо решил мой вопрос, но у меня есть ещё один вопрос, можно ли как-то использовать переменную с функцией sampProcessChatInput
При нескольком кол-ве аргументов
Lua:
sampProcessChatInput("/ticket 40000 29.1 ЕФК", enterArg)
При таком использование скрипт не определяет куда ставить информацию с переменной, возможно ли это устранить?
 

meowprd

Тот самый Котовский
Проверенный
1,283
711
Привет, спасибо решил мой вопрос, но у меня есть ещё один вопрос, можно ли как-то использовать переменную с функцией sampProcessChatInput
При нескольком кол-ве аргументов
Lua:
sampProcessChatInput("/ticket 40000 29.1 ЕФК", enterArg)
При таком использование скрипт не определяет куда ставить информацию с переменной, возможно ли это устранить?
читай про string.format