Вопрос с imgui. Radiobutton, Checkbox

Wer_tyn

Участник
Автор темы
46
0
Версия MoonLoader
.027.0-preview
У меня случилась проблема с Checkbox/RadioButton есть код:

Код:
imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(445, 270), imgui.Cond.Always)
    
    imgui.Begin('Helper', WinState, imgui.WindowFlags.NoResize)
    imgui.Checkbox(u8'box', checkboxone)
    imgui.End()
end)

 
function main()
    while true do wait(0)
        if wasKeyPressed(VK_R) and not sampIsCursorActive() then
            WinState[0] = not WinState[0]
        end
        if checkboxone[0] then
            sampAddChatMessage('soft',-1)
        else
            sampAddChatMessage('ansoft',-1)
        end
    end
end

В чат происходит жесткий спам, пробывал через wait но окно imgui не открывается
 

chapo

чопа сребдс // TG/IG: @moujeek
Модератор
9,021
11,853
так а ты чего хотел, у тебя же проверка в бесконечном цикле. Если тебе нужно воспроизвести какое-то действие после клика на чекбокс, то в самом фрейме оберни чекбокс в if (...) then и там прописывай действия
 
  • Нравится
  • Влюблен
Реакции: kyrtion и santov

kyrtion

Известный
1,096
395
Lua:
imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(445, 270), imgui.Cond.Always)
   
    if imgui.Begin('Helper', WinState, imgui.WindowFlags.NoResize) then
        -- с условиями то триггерится один раз (после нажатий)
        if imgui.Checkbox(u8'box', checkboxone) then
            local enabled = checkboxone[0]
            sampAddChatMessage(enabled and 'soft' or 'unsoft', -1)
        end

        imgui.End()
    end
end)

 
function main()
    while true do wait(0)
        if wasKeyPressed(VK_R) and not sampIsCursorActive() then
            WinState[0] = not WinState[0]
        end
        -- if checkboxone[0] then
        --     sampAddChatMessage('soft',-1)
        -- else
        --     sampAddChatMessage('ansoft',-1)
        -- end
    end
end
 

Wer_tyn

Участник
Автор темы
46
0
Lua:
imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(445, 270), imgui.Cond.Always)
 
    if imgui.Begin('Helper', WinState, imgui.WindowFlags.NoResize) then
        -- с условиями то триггерится один раз (после нажатий)
        if imgui.Checkbox(u8'box', checkboxone) then
            local enabled = checkboxone[0]
            sampAddChatMessage(enabled and 'soft' or 'unsoft', -1)
        end

        imgui.End()
    end
end)

 
function main()
    while true do wait(0)
        if wasKeyPressed(VK_R) and not sampIsCursorActive() then
            WinState[0] = not WinState[0]
        end
        -- if checkboxone[0] then
        --     sampAddChatMessage('soft',-1)
        -- else
        --     sampAddChatMessage('ansoft',-1)
        -- end
    end
end
Спасибо

Помогите пожалуйста еще с радиокнопками, окно опять не открывается, без wait спамит, только не sampAddChatMessage(enabled and 'soft' or 'unsoft', -1), если там будет большой скрипт то не получится

Код:
local radiosoft = imgui.new.int(1)

imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(445, 270), imgui.Cond.Always)
  
  
    imgui.Begin('Helper', WinState, imgui.WindowFlags.NoResize)

    if imgui.RadioButtonIntPtr('soft', radiosoft, 1) then
        sampAddChatMessage('soft on',-1)
        wait(5000)
    else
        sampAddChatMessage('soft off', -1)
        wait(5000)
    end
    if imgui.RadioButtonIntPtr('ansoft', radiosoft, 2) then
        sampAddChatMessage('ansoft',-1)
    end
function main()
    while true do wait(0)
        if wasKeyPressed(VK_R) and not sampIsCursorActive() then
            WinState[0] = not WinState[0]
        end
    end
end