вопрос имгуи lua

kwzInside

Участник
Автор темы
65
7
Версия MoonLoader
.027.0-preview
хочу сделать так, чтобы когда ставишь галочку на "Наркотики на Z" на определенную клавишу (я поставил клавишу Z) должна вводиться в чат команда "/usedrugs 3"
но это происходит даже без галочки, и только когда imgui окно открыто, помогите пожалуйста, буду благодарен
Код:
local ffi = require 'ffi'
local imgui = require 'mimgui'
local encoding = require 'encoding'
require "lib.moonloader"
encoding.default = "CP1251"
local u8 = encoding.UTF8
local new = imgui.new
local currentItem = new.int(1)
local items = new['const char*'][3]{ u8"Пункт 1", u8"Пункт 2", u8"Пункт 3" }
local state = new.bool()
local input_text = new.char[256]("")
local isChecked = new.bool(true)
imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    image = imgui.CreateTextureFromFileInMemory(new('const char*', image_data), #image_data)
end)
imgui.OnFrame(function() return state[0] end, function()
    if imgui.Begin(u8"Ghetto Helper", state, imgui.WindowFlags.NoCollapse) then
        if imgui.Button(u8"Нажми на меня") then sampAddChatMessage("Кнопка нажата!", -1) end
        
        imgui.Text(u8"Текст")
        imgui.SameLine()
        imgui.InputText("##text", input_text, 256)
        imgui.Combo(u8"Выберите пункт:", currentItem, items, ffi.sizeof(items) / 4)
        imgui.Checkbox(u8"Наркотики на Z", isChecked)
            if isKeyJustPressed(VK_Z) and isChecked then
                sampSendChat("/usedrugs 3")
            end
        if imgui.BeginChild(u8"Изображение", imgui.ImVec2(200, 200), true) then
            imgui.Text("Image")
            imgui.Image(image, imgui.ImVec2(150, 150))
            imgui.EndChild()
        end
        imgui.End()
    end
end)
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    repeat wait(100) until isSampAvailable()
    sampRegisterChatCommand("imgui", function() state[0] = not state[0] end)
    wait(-1)
end
image_data = "" -- сюда картинку в base85
if isKeyJustPressed(VK_Z) and isChecked.v then
    sampSendChat("/usedrugs 3")
end
 

MLycoris

Режим чтения
Проверенный
1,823
1,865
в беск цикле проверяешь состояние чекбокса, нажатие клавиши и отсутствие самп курсора, чтоб избежать срабатывания, когда открыт чат
Lua:
local ffi = require 'ffi'
local imgui = require 'mimgui'
local encoding = require 'encoding'
require "lib.moonloader"
encoding.default = "CP1251"
local u8 = encoding.UTF8
local new = imgui.new
local currentItem = new.int(1)
local items = new['const char*'][3]{ u8"Пункт 1", u8"Пункт 2", u8"Пункт 3" }
local state = new.bool()
local input_text = new.char[256]("")
local isChecked = new.bool()
imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    image = imgui.CreateTextureFromFileInMemory(new('const char*', image_data), #image_data)
end)
imgui.OnFrame(function() return state[0] end, function()
    if imgui.Begin(u8"Ghetto Helper", state, imgui.WindowFlags.NoCollapse) then
        if imgui.Button(u8"Нажми на меня") then sampAddChatMessage("Кнопка нажата!", -1) end
       
        imgui.Text(u8"Текст")
        imgui.SameLine()
        imgui.InputText("##text", input_text, 256)
        imgui.Combo(u8"Выберите пункт:", currentItem, items, ffi.sizeof(items) / 4)
        imgui.Checkbox(u8"Наркотики на Z", isChecked)
        if imgui.BeginChild(u8"Изображение", imgui.ImVec2(200, 200), true) then
            imgui.Text("Image")
            imgui.Image(image, imgui.ImVec2(150, 150))
            imgui.EndChild()
        end
        imgui.End()
    end
end)
function main()
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("imgui", function() state[0] = not state[0] end)
    while true do wait(0)
        if isChecked[0] and wasKeyPressed(VK_Z) and not sampIsCursorActive() then
            sampSendChat("/usedrugs 3")
        end
    end
end
image_data = "" -- сюда картинку в base85
 
  • Нравится
Реакции: joumey