Imgui.Checkbox

r3wZzzz

Участник
Автор темы
73
5
Как сделать, что бы когда я сохраняю скрипт, сохранялись и галочки в имгуи?


1:
require "lib.moonloader"

local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8

font = renderCreateFont('Arial', 13, 5)

local sampev = require 'lib.samp.events'
local imgui = require "imgui"

local renderwindow = false

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)

local checkedbox_klad = imgui.ImBool(false)
local checkedbox_hueta = imgui.ImBool(false)

local inicfg = require("inicfg")
local directIni = ("config.ini")
local ini = inicfg.load(inicfg.load({
    settings = {
        rklad=false,
        rhueta=false,
        state=false
    },
}, directIni))
inicfg.save(ini, directIni)


function imgui.OnDrawFrame()
  imgui.Begin(u8'123', main_window_state)
  imgui.Text(u8'123')
  if imgui.Checkbox(u8"Клады", checkedbox_klad, imgui.ImVec2(100, 50), 1) then rklad = not rklad saveklad()
  end
  if imgui.Checkbox(u8"Х1йня какая-то", checkedbox_hueta, imgui.ImVec2(100, 50),  2) then rhueta = not rhueta save2()
end
  imgui.End()
end

function main()

    while not isSampLoaded() do wait(0) end wait(1)

    wait(300)

    sampAddChatMessage("Render Loaded", -1)

    sampRegisterChatCommand("nwr", renderwindow)
    sampRegisterChatCommand("coordinates", coordinates)
    sampRegisterChatCommand("getc", test_get)
    sampRegisterChatCommand("setc", test_set)
        
         imgui.Process = false

    while true do
        wait(0)
        rklad = ini.settings.rklad
        rhueta = ini.settings.rhueta
        state = ini.settings.state

        if main_window_state.v == false then
            imgui.Process = false
        end
        if rklad then
            for _, v in pairs(getAllObjects()) do
                local asd
                if sampGetObjectSampIdByHandle(v) == 2680 then
                    asd = sampGetObjectSampIdByHandle(v)
                end
                if isObjectOnScreen(v) then
                    local result, oX, oY, oZ = getObjectCoordinates(v)
                    local x1, y1 = convert3DCoordsToScreen(oX,oY,oZ)
                    local objmodel = getObjectModel(v)
                    local x2,y2,z2 = getCharCoordinates(PLAYER_PED)
                    local x10, y10 = convert3DCoordsToScreen(x2,y2,z2)
                    distance = string.format("%.0f", getDistanceBetweenCoords3d(oX,oY,oZ, x2, y2, z2))
                    if objmodel == 2680 then renderDrawLine(x10, y10, x1, y1, 5, -1) renderFontDrawText(font,"{FFFFFF}Клад - {696969}"..distance, x1, y1, -1) end
            end
        end
    end
              -- 123
        if rhueta then
            for _, v in pairs(getAllObjects()) do
                local qwe
                if sampGetObjectSampIdByHandle(v) == 11744 then
                    qwe = sampGetObjectSampIdByHandle(v)
                end
                if isObjectOnScreen(v) then
                    local result, oX, oY, oZ = getObjectCoordinates(v)
                    local x1, y1 = convert3DCoordsToScreen(oX,oY,oZ)
                    local objmodel = getObjectModel(v)
                    local x2,y2,z2 = getCharCoordinates(PLAYER_PED)
                    local x10, y10 = convert3DCoordsToScreen(x2,y2,z2)
                    distance = string.format("%.0f", getDistanceBetweenCoords3d(oX,oY,oZ, x2, y2, z2))
                    if objmodel == 11744 then renderDrawLine(x10, y10, x1, y1, 5, -1) renderFontDrawText(font,"{FFFFFF}Х1йня какая-то - {696969}"..distance, x1, y1, -1) end
                end   
            end
        end
    end
end


function renderwindow()
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function coordinates()
    x, y, z = getCharCoordinates(PLAYER_PED)
    sampAddChatMessage("Твои Координаты: " .. math.floor(x) .. " | " .. math.floor(y) .. " | " .. math.floor(z), 0xDC143C)
end

function loadcfgg()
    rklad=ini.settings.rklad
    rhueta=ini.settings.rhueta
end

function saveklad()
    ini.settings.rklad = rklad
    inicfg.save(ini, directIni)
    sampAddChatMessage('Сохранено.', -1)
end

function save2()
    ini.settings.rhueta = rhueta
    inicfg.save(ini, directIni)
    sampAddChatMessage('Сохранено.', -1)
end
 
Решение
Lua:
local key = require 'vkeys'
local imgui = require 'imgui'
local inicfg = require 'inicfg'

local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local ds = inicfg.load(nil, "test")
if ds == nil then
    local ds = inicfg.load(
    {
        st = {
            stat = false
        }
    })
    if inicfg.save(ds,'test') then 
        print('new file')
    end   
end

local main_window_state = imgui.ImBool(false)
local cb = imgui.ImBool(ds.st.stat) 
function main()

    while true do wait(0)
        if wasKeyPressed(key.VK_X) then main_window_state.v = not main_window_state.v end
        imgui.Process = main_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then...

qdIbp

Автор темы
Проверенный
1,387
1,146
Lua:
local key = require 'vkeys'
local imgui = require 'imgui'
local inicfg = require 'inicfg'

local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local ds = inicfg.load(nil, "test")
if ds == nil then
    local ds = inicfg.load(
    {
        st = {
            stat = false
        }
    })
    if inicfg.save(ds,'test') then 
        print('new file')
    end   
end

local main_window_state = imgui.ImBool(false)
local cb = imgui.ImBool(ds.st.stat) 
function main()

    while true do wait(0)
        if wasKeyPressed(key.VK_X) then main_window_state.v = not main_window_state.v end
        imgui.Process = main_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(150, 200), imgui.Cond.FirstUseEver) -- меняем размер
        imgui.Begin('My window', main_window_state)
            imgui.Text('hp  '..getCharHealth(playerPed)..'\nArmor '..getCharArmour(playerPed))
            imgui.Checkbox("Check", cb)
            ds.st.stat = cb.v
            inicfg.save(ds,'test')   
        imgui.End()
    end
end
 
  • Нравится
Реакции: r3wZzzz