Вопрос по активации чекбокса

sauntren

Новичок
Автор темы
14
1
Версия MoonLoader
Другое
Добрый день.

Представлю код:

Код:
script_name('Sauntren Helper')
script_author('Seth Sauntren')
script_description('Helper for Arizona RP')

require "lib.moonloader"
local keys = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
local main_window_state = imgui.ImBool(false)
local secondary_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)
local checked_radio = imgui.ImInt(1)
local checked_test = imgui.ImBool(false)
local checked_test_2 = imgui.ImBool(false)
local sw, sh = getScreenResolution()
local themes = import "resource/imgui_themes.lua"
local combo_select = imgui.ImInt(0)
encoding.default = 'CP1251'
u8 = encoding.UTF8

function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end

sampAddChatMessage("[SN Helper] {D5DEDD}Version: 1.0. | Author: Seth Sauntren.", 0x01A0E9)
sampAddChatMessage("[SN Helper] {D5DEDD}Activation: /snh.", 0x01A0E9)

sampRegisterChatCommand("snh", cmd_imgui)
sampRegisterChatCommand("snh2", cmd_imgui2)

imgui.Process = false

imgui.SwitchContext()
themes.SwitchColorTheme(1)


while true do
wait(0)
end
end

function imgui.OnDrawFrame()
if main_window_state.v then
imgui.SetNextWindowSize(imgui.ImVec2(500, 600), imgui.Cond.FirstUseEver)
imgui.SetNextWindowPos(imgui.ImVec2((sw/2), sh/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

imgui.Begin("Sauntren Helper 1.0", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)


imgui.BeginChild("ChildWindow", imgui.ImVec2(484, 150), true)
imgui.Checkbox("Lock cars", checked_test)
imgui.SameLine()
imgui.Checkbox("SW ST", checked_test_2)
imgui.EndChild()

imgui.InputText(u8'Введите текст:', text_buffer)
if imgui.Button(u8'Вывести в чат') then
sampAddChatMessage(u8:decode(text_buffer.v), -1)
end


imgui.SetCursorPosY(575)
imgui.SetCursorPosX(455)
if imgui.Button(u8'Темы') then
secondary_window_state.v = true
end



x, y, z = getCharCoordinates(PLAYER_PED)
imgui.SetCursorPosY(580)
imgui.SetCursorPosX(10)
imgui.Text(u8("Позиция игрока: X:" .. math.floor(x) .. " | Y: " .. math.floor(y) .. " | Z: " .. math.floor(z)))
imgui.End()
end

if main_window_state.v == false then
imgui.Process = false
end

imgui.SetNextWindowSize(imgui.ImVec2(150, 205), imgui.Cond.FirstUseEver)
imgui.SetNextWindowPos(imgui.ImVec2((sw/2), sh/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
if secondary_window_state.v then
imgui.Begin(u8'Темы', secondary_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
imgui.BeginChild("ChildWindow2", imgui.ImVec2(140, 175), true)
for i, value in ipairs(themes.colorThemes) do
if imgui.RadioButton(value, checked_radio, i) then
themes.SwitchColorTheme(i)
end
end
imgui.EndChild()
imgui.End()
end
end




function cmd_imgui(arg)
main_window_state.v = not main_window_state.v
imgui.Process = main_window_state.v
end

function cmd_imgui2(arg)
secondary_window_state.v = not secondary_window_state.v
imgui.Process = secondary_window_state.v
end

function apply_custom_style()
imgui.SwitchContext()
local style = imgui.GetStyle()
style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
end
apply_custom_style()

Как в нём сделать бинд на активированный чекбокс?
Допустим, если чекбокс активирован, то при нажатии на кнопку P будет отправляться команда /phone в чат?

Moonloader версии 026.5-beta.

Спасибо за внимание.
 
Решение
В месте где "Код" я и затрудняюсь, если не сложно, допишите пожалуйста. На кнопку P при вкл. чекбоксе должна отправляться команда /phone
Lua:
            if CheckBox.v then
                if isKeyJustPressed(VK_P) and not sampIsCursorActive() then
                    sampSendChat('/phone')
                end
            end

Dmitriy Makarov

25.05.2021
Проверенный
2,500
1,131
Lua:
script_name("Sauntren Helper")
script_author("Seth Sauntren")
script_description("Helper for Arizona RP")

require "lib.moonloader"
local keys = require "vkeys"
local imgui = require "imgui"
local encoding = require "encoding"
local main_window_state = imgui.ImBool(false)
local secondary_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)
local checked_radio = imgui.ImInt(1)
local checked_test = imgui.ImBool(false)
local checked_test_2 = imgui.ImBool(false)
local sw, sh = getScreenResolution()
local themes = import "resource/imgui_themes.lua"
local combo_select = imgui.ImInt(0)
encoding.default = "CP1251"
u8 = encoding.UTF8

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage("[SN Helper] {D5DEDD}Version: 1.0. | Author: Seth Sauntren.", 0x01A0E9)
    sampAddChatMessage("[SN Helper] {D5DEDD}Activation: /snh.", 0x01A0E9)

    sampRegisterChatCommand("snh", function() main_window_state.v = not main_window_state.v end)
    sampRegisterChatCommand("snh2", function() secondary_window_state.v = not secondary_window_state.v end)
   
    imgui.SwitchContext()
    themes.SwitchColorTheme(1)
    while true do
        wait(0)
        imgui.Process = main_window_state.v or secondary_window_state.v
        if checked_test.v then
            if isKeyJustPressed(VK_J) and not sampIsCursorActive() then
                sampSendChat("help")
            end
        end
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(500, 600), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin("Sauntren Helper 1.0", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.BeginChild("ChildWindow", imgui.ImVec2(484, 150), true)
        imgui.Checkbox("Help", checked_test)
        imgui.Checkbox("SW ST", checked_test_2)
        imgui.EndChild()
        imgui.InputText(u8 "Введите текст:", text_buffer)
        if imgui.Button(u8 "Вывести в чат") then
            sampAddChatMessage(u8:decode(text_buffer.v), -1)
        end
        imgui.SetCursorPosY(575)
        imgui.SetCursorPosX(455)
        if imgui.Button(u8 "Темы") then
            secondary_window_state.v = true
        end
        x, y, z = getCharCoordinates(PLAYER_PED)
        imgui.SetCursorPosY(580)
        imgui.SetCursorPosX(10)
        imgui.Text(u8("Позиция игрока: X:" .. math.floor(x) .. " | Y: " .. math.floor(y) .. " | Z: " .. math.floor(z)))
        imgui.End()
    end
    if secondary_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(150, 205), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8 "Темы", secondary_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
        imgui.BeginChild("ChildWindow2", imgui.ImVec2(140, 175), true)
        for i, value in ipairs(themes.colorThemes) do
            if imgui.RadioButton(value, checked_radio, i) then
                themes.SwitchColorTheme(i)
            end
        end
        imgui.EndChild()
        imgui.End()
    end
end

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
end
apply_custom_style()