IniCfg не сохраняет Slider.Float

cloused2

Известный
Автор темы
396
130
Версия MoonLoader
Другое
Говно код(не бейте палками):
---=== Библиотеки ===---

local imgui = require 'mimgui'
local ffi = require 'ffi'
local inicfg = require 'inicfg'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

---=== IniCfg ===---

local IniFilename = 'CTime_v2.ini'
local settings = inicfg.load({
    position = {
        posX=150,
        posY=170,
    },
    main = {
        text='CTime',
        enabled=false,
        sizeTime=1,
        sizeText=1,
    }
}, IniFilename)

---=== Переменные Mimgui ===---

local new = imgui.new
local str = ffi.string
local renderWindow = new.bool(false)

---=== Переменные ===---

checkbox_work = new.bool(settings.main.enabled)
input_text = new.char[6](u8(settings.main.text))
SetTimePos = false
ttext = settings.main.text
SizeTime = new.float(settings.main.sizeTime)
SizeText = new.float(settings.main.sizeText)

---=== Mimgui Code ===---

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    imgui.DarkTheme()
end)

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 600, 300
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'Настройки CTime', renderWindow)
            imgui.Text(u8'Увидев, что на BlastHack множество человек ищет данный скрипт, я решил написать его копию.')
            imgui.Separator()
            if imgui.Checkbox(u8'Показывать на экране', checkbox_work) then
                settings.main.enabled = checkbox_work[0]
                inicfg.save(settings, IniFilename)
            end

            imgui.Separator()
            imgui.Text(u8'Настройки часов')

            if imgui.InputText(u8'Введите текст для отображения', input_text, 6) then
                settings.main.text = u8:decode(str(input_text))
                inicfg.save(settings, IniFilename)
            end
            if imgui.Button(u8'Очистить') then
                imgui.StrCopy(input_text, '')
                settings.main.text = ''
                inicfg.save(settings, IniFilename)
            end
            imgui.Text(u8'Изменения будут применены только после перезахода')
            imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3)
            if imgui.Button('save', imgui.ImVec2(50, 30)) then
                inicfg.save(settings, IniFilename)
            end

            imgui.Separator()
            imgui.Text(u8'Координаты часов')

            if imgui.Button(u8'Установить положение часов', imgui.ImVec2(75, 25)) then
                SetTimePos = true
                if SetTimePos then
                    showCursor(true)
                    sampAddChatMessage('Установи положение текстдрава', -1)
                else
                    sampAddChatMessage('Текстдрав установлен', -1)
                end
            end
        imgui.End()
    end)

---=== Main Code ===---

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('set.ctime', function()
        renderWindow[0] = not renderWindow[0]
    end)

    while true do
        wait(0)
            if checkbox_work[0] then

            sampTextdrawCreate(444, ttext, settings.position.posX, settings.position.posY-10)
            sampTextdrawSetLetterSizeAndColor(444, 0.3, settings.position.posX, 0xFFFFFFFF)
            sampTextdrawSetOutlineColor(444, 0.5, 0xFF000000)
            sampTextdrawSetAlign(444, 1)
            sampTextdrawSetStyle(444, 2)

            
            sampTextdrawCreate(333, os.date("%H:%M:%S"), settings.position.posX, settings.position.posY)
            sampTextdrawSetLetterSizeAndColor(333, 0.3, settings.main.sizeTime, 0xFFFFFFFF)
            sampTextdrawSetOutlineColor(333, 0.5, 0xFF000000)
            sampTextdrawSetAlign(333, 1)
            sampTextdrawSetStyle(333, 2)
        else
            sampTextdrawDelete(333)
            sampTextdrawDelete(444)

        end

        if SetTimePos then

            sampSetCursorMode(2)
            posX, posY = getCursorPos()
            settings.position.posX, settings.position.posY = convertWindowScreenCoordsToGameScreenCoords(posX, posY)
            inicfg.save(settings, IniFilename)
            sampTextdrawSetPos(222, settings.position.posX, settings.position.posY)
            sampTextdrawSetPos(333, settings.position.posX, settings.position.posY-10)
            if wasKeyPressed(1) then
                SetTimePos = not SetTimePos
                showCursor(false)
            end
        end
    end
end

---=== Темная Тема Mimgui ===---

function imgui.DarkTheme()
    imgui.SwitchContext()
    --==[ STYLE ]==--
    imgui.GetStyle().WindowPadding = imgui.ImVec2(10, 5)
    imgui.GetStyle().FramePadding = imgui.ImVec2(5, 5)
    imgui.GetStyle().ItemSpacing = imgui.ImVec2(5, 5)
    imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(2, 2)
    imgui.GetStyle().TouchExtraPadding = imgui.ImVec2(0, 0)
    imgui.GetStyle().IndentSpacing = 0
    imgui.GetStyle().ScrollbarSize = 0
    imgui.GetStyle().GrabMinSize = 10

    --==[ BORDER ]==--
    imgui.GetStyle().WindowBorderSize = 1
    imgui.GetStyle().ChildBorderSize = 1
    imgui.GetStyle().PopupBorderSize = 1
    imgui.GetStyle().FrameBorderSize = 1
    imgui.GetStyle().TabBorderSize = 1

    --==[ ROUNDING ]==--
    imgui.GetStyle().WindowRounding = 10
    imgui.GetStyle().ChildRounding = 5
    imgui.GetStyle().FrameRounding = 5
    imgui.GetStyle().PopupRounding = 5
    imgui.GetStyle().ScrollbarRounding = 5
    imgui.GetStyle().GrabRounding = 5
    imgui.GetStyle().TabRounding = 5

    --==[ ALIGN ]==--
    imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    imgui.GetStyle().ButtonTextAlign = imgui.ImVec2(0.5, 0.5)
    imgui.GetStyle().SelectableTextAlign = imgui.ImVec2(0.5, 0.5)
    
    --==[ COLORS ]==--
    imgui.GetStyle().Colors[imgui.Col.Text]                   = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TextDisabled]           = imgui.ImVec4(0.50, 0.50, 0.50, 1.00)
    imgui.GetStyle().Colors[imgui.Col.WindowBg]               = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ChildBg]                = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PopupBg]                = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Border]                 = imgui.ImVec4(0.25, 0.25, 0.26, 0.54)
    imgui.GetStyle().Colors[imgui.Col.BorderShadow]           = imgui.ImVec4(0.00, 0.00, 0.00, 0.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBg]                = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBgHovered]         = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBgActive]          = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBg]                = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBgActive]          = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed]       = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.MenuBarBg]              = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarBg]            = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab]          = imgui.ImVec4(0.00, 0.00, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered]   = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive]    = imgui.ImVec4(0.51, 0.51, 0.51, 1.00)
    imgui.GetStyle().Colors[imgui.Col.CheckMark]              = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SliderGrab]             = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SliderGrabActive]       = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Button]                 = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ButtonHovered]          = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ButtonActive]           = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Header]                 = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.HeaderHovered]          = imgui.ImVec4(0.20, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.HeaderActive]           = imgui.ImVec4(0.47, 0.47, 0.47, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Separator]              = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SeparatorHovered]       = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SeparatorActive]        = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ResizeGrip]             = imgui.ImVec4(1.00, 1.00, 1.00, 0.25)
    imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered]      = imgui.ImVec4(1.00, 1.00, 1.00, 0.67)
    imgui.GetStyle().Colors[imgui.Col.ResizeGripActive]       = imgui.ImVec4(1.00, 1.00, 1.00, 0.95)
    imgui.GetStyle().Colors[imgui.Col.Tab]                    = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabHovered]             = imgui.ImVec4(0.28, 0.28, 0.28, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabActive]              = imgui.ImVec4(0.30, 0.30, 0.30, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabUnfocused]           = imgui.ImVec4(0.07, 0.10, 0.15, 0.97)
    imgui.GetStyle().Colors[imgui.Col.TabUnfocusedActive]     = imgui.ImVec4(0.14, 0.26, 0.42, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotLines]              = imgui.ImVec4(0.61, 0.61, 0.61, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered]       = imgui.ImVec4(1.00, 0.43, 0.35, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotHistogram]          = imgui.ImVec4(0.90, 0.70, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered]   = imgui.ImVec4(1.00, 0.60, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TextSelectedBg]         = imgui.ImVec4(1.00, 0.00, 0.00, 0.35)
    imgui.GetStyle().Colors[imgui.Col.DragDropTarget]         = imgui.ImVec4(1.00, 1.00, 0.00, 0.90)
    imgui.GetStyle().Colors[imgui.Col.NavHighlight]           = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
    imgui.GetStyle().Colors[imgui.Col.NavWindowingHighlight]  = imgui.ImVec4(1.00, 1.00, 1.00, 0.70)
    imgui.GetStyle().Colors[imgui.Col.NavWindowingDimBg]      = imgui.ImVec4(0.80, 0.80, 0.80, 0.20)
    imgui.GetStyle().Colors[imgui.Col.ModalWindowDimBg]       = imgui.ImVec4(0.00, 0.00, 0.00, 0.70)
end

Нет сохранения в иникфг, хотя ини сейв есть
 
Решение
Сохранение есть, перезаписи нет.

Замени это:
Lua:
imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3)
if imgui.Button('save', imgui.ImVec2(50, 30)) then
    inicfg.save(settings, IniFilename)
end
На это:
Lua:
if imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3) then
    settings.main.sizeTime = SizeTime.v
    inicfg.save(settings, IniFilename)
end

Dmitriy Makarov

25.05.2021
Проверенный
2,500
1,131
Сохранение есть, перезаписи нет.

Замени это:
Lua:
imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3)
if imgui.Button('save', imgui.ImVec2(50, 30)) then
    inicfg.save(settings, IniFilename)
end
На это:
Lua:
if imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3) then
    settings.main.sizeTime = SizeTime.v
    inicfg.save(settings, IniFilename)
end
 
  • Нравится
Реакции: cloused2

cloused2

Известный
Автор темы
396
130
Сохранение есть, перезаписи нет.

Замени это:
Lua:
imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3)
if imgui.Button('save', imgui.ImVec2(50, 30)) then
    inicfg.save(settings, IniFilename)
end
На это:
Lua:
if imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3) then
    settings.main.sizeTime = SizeTime.v
    inicfg.save(settings, IniFilename)
end
а что делает .v после SizeTime?
 

cloused2

Известный
Автор темы
396
130
Lua:
---=== Библиотеки ===---

local imgui = require 'mimgui'
local ffi = require 'ffi'
local inicfg = require 'inicfg'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

---=== IniCfg ===---

local IniFilename = 'CTime_v2.ini'
local settings = inicfg.load({
    position = {
        posX=150,
        posY=170,
    },
    main = {
        text='CTime',
        enabled=false,
        sizeTime=1,
        sizeText=1,
    }
}, IniFilename)

---=== Переменные Mimgui ===---

local new = imgui.new
local str = ffi.string
local renderWindow = new.bool(false)

---=== Переменные ===---

checkbox_work = new.bool(settings.main.enabled)
input_text = new.char[6](u8(settings.main.text))
SetTimePos = false
ttext = settings.main.text
SizeTime = new.float(settings.main.sizeTime)
SizeText = new.float(settings.main.sizeText)

---=== Mimgui Code ===---

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    imgui.DarkTheme()
end)

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 600, 300
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'Настройки CTime', renderWindow)
            imgui.Text(u8'Увидев, что на BlastHack множество человек ищет данный скрипт, я решил написать его копию.')
            imgui.Separator()
            if imgui.Checkbox(u8'Показывать на экране', checkbox_work) then
                settings.main.enabled = checkbox_work[0]
                inicfg.save(settings, IniFilename)
            end

            imgui.Separator()
            imgui.Text(u8'Настройки часов')

            if imgui.InputText(u8'Введите текст для отображения', input_text, 6) then
                settings.main.text = u8:decode(str(input_text))
                inicfg.save(settings, IniFilename)
            end
            if imgui.Button(u8'Очистить') then
                imgui.StrCopy(input_text, '')
                settings.main.text = ''
                inicfg.save(settings, IniFilename)
            end
            imgui.Text(u8'Изменения будут применены только после перезахода')
            if imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3) then
                settings.main.sizeTime = SizeTime
                inicfg.save(settings, IniFilename)
            end

            imgui.Separator()
            imgui.Text(u8'Координаты часов')

            if imgui.Button(u8'Установить положение часов', imgui.ImVec2(75, 25)) then
                SetTimePos = true
                if SetTimePos then
                    showCursor(true)
                    sampAddChatMessage('Установи положение текстдрава', -1)
                else
                    sampAddChatMessage('Текстдрав установлен', -1)
                end
            end
        imgui.End()
    end)

---=== Main Code ===---

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('set.ctime', function()
        renderWindow[0] = not renderWindow[0]
    end)

    while true do
        wait(0)
            if checkbox_work[0] then

            sampTextdrawCreate(444, ttext, settings.position.posX, settings.position.posY-10)
            sampTextdrawSetLetterSizeAndColor(444, 0.3, settings.position.posX, 0xFFFFFFFF)
            sampTextdrawSetOutlineColor(444, 0.5, 0xFF000000)
            sampTextdrawSetAlign(444, 1)
            sampTextdrawSetStyle(444, 2)

            
            sampTextdrawCreate(333, os.date("%H:%M:%S"), settings.position.posX, settings.position.posY)
            sampTextdrawSetLetterSizeAndColor(333, 0.3, settings.main.sizeTime, 0xFFFFFFFF)
            sampTextdrawSetOutlineColor(333, 0.5, 0xFF000000)
            sampTextdrawSetAlign(333, 1)
            sampTextdrawSetStyle(333, 2)
        else
            sampTextdrawDelete(333)
            sampTextdrawDelete(444)

        end

        if SetTimePos then

            sampSetCursorMode(2)
            posX, posY = getCursorPos()
            settings.position.posX, settings.position.posY = convertWindowScreenCoordsToGameScreenCoords(posX, posY)
            inicfg.save(settings, IniFilename)
            sampTextdrawSetPos(222, settings.position.posX, settings.position.posY)
            sampTextdrawSetPos(333, settings.position.posX, settings.position.posY-10)
            if wasKeyPressed(1) then
                SetTimePos = not SetTimePos
                showCursor(false)
            end
        end
    end
end

---=== Темная Тема Mimgui ===---

function imgui.DarkTheme()
    imgui.SwitchContext()
    --==[ STYLE ]==--
    imgui.GetStyle().WindowPadding = imgui.ImVec2(10, 5)
    imgui.GetStyle().FramePadding = imgui.ImVec2(5, 5)
    imgui.GetStyle().ItemSpacing = imgui.ImVec2(5, 5)
    imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(2, 2)
    imgui.GetStyle().TouchExtraPadding = imgui.ImVec2(0, 0)
    imgui.GetStyle().IndentSpacing = 0
    imgui.GetStyle().ScrollbarSize = 0
    imgui.GetStyle().GrabMinSize = 10

    --==[ BORDER ]==--
    imgui.GetStyle().WindowBorderSize = 1
    imgui.GetStyle().ChildBorderSize = 1
    imgui.GetStyle().PopupBorderSize = 1
    imgui.GetStyle().FrameBorderSize = 1
    imgui.GetStyle().TabBorderSize = 1

    --==[ ROUNDING ]==--
    imgui.GetStyle().WindowRounding = 10
    imgui.GetStyle().ChildRounding = 5
    imgui.GetStyle().FrameRounding = 5
    imgui.GetStyle().PopupRounding = 5
    imgui.GetStyle().ScrollbarRounding = 5
    imgui.GetStyle().GrabRounding = 5
    imgui.GetStyle().TabRounding = 5

    --==[ ALIGN ]==--
    imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    imgui.GetStyle().ButtonTextAlign = imgui.ImVec2(0.5, 0.5)
    imgui.GetStyle().SelectableTextAlign = imgui.ImVec2(0.5, 0.5)
    
    --==[ COLORS ]==--
    imgui.GetStyle().Colors[imgui.Col.Text]                   = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TextDisabled]           = imgui.ImVec4(0.50, 0.50, 0.50, 1.00)
    imgui.GetStyle().Colors[imgui.Col.WindowBg]               = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ChildBg]                = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PopupBg]                = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Border]                 = imgui.ImVec4(0.25, 0.25, 0.26, 0.54)
    imgui.GetStyle().Colors[imgui.Col.BorderShadow]           = imgui.ImVec4(0.00, 0.00, 0.00, 0.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBg]                = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBgHovered]         = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBgActive]          = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBg]                = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBgActive]          = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed]       = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.MenuBarBg]              = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarBg]            = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab]          = imgui.ImVec4(0.00, 0.00, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered]   = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive]    = imgui.ImVec4(0.51, 0.51, 0.51, 1.00)
    imgui.GetStyle().Colors[imgui.Col.CheckMark]              = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SliderGrab]             = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SliderGrabActive]       = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Button]                 = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ButtonHovered]          = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ButtonActive]           = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Header]                 = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.HeaderHovered]          = imgui.ImVec4(0.20, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.HeaderActive]           = imgui.ImVec4(0.47, 0.47, 0.47, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Separator]              = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SeparatorHovered]       = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SeparatorActive]        = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ResizeGrip]             = imgui.ImVec4(1.00, 1.00, 1.00, 0.25)
    imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered]      = imgui.ImVec4(1.00, 1.00, 1.00, 0.67)
    imgui.GetStyle().Colors[imgui.Col.ResizeGripActive]       = imgui.ImVec4(1.00, 1.00, 1.00, 0.95)
    imgui.GetStyle().Colors[imgui.Col.Tab]                    = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabHovered]             = imgui.ImVec4(0.28, 0.28, 0.28, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabActive]              = imgui.ImVec4(0.30, 0.30, 0.30, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabUnfocused]           = imgui.ImVec4(0.07, 0.10, 0.15, 0.97)
    imgui.GetStyle().Colors[imgui.Col.TabUnfocusedActive]     = imgui.ImVec4(0.14, 0.26, 0.42, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotLines]              = imgui.ImVec4(0.61, 0.61, 0.61, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered]       = imgui.ImVec4(1.00, 0.43, 0.35, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotHistogram]          = imgui.ImVec4(0.90, 0.70, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered]   = imgui.ImVec4(1.00, 0.60, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TextSelectedBg]         = imgui.ImVec4(1.00, 0.00, 0.00, 0.35)
    imgui.GetStyle().Colors[imgui.Col.DragDropTarget]         = imgui.ImVec4(1.00, 1.00, 0.00, 0.90)
    imgui.GetStyle().Colors[imgui.Col.NavHighlight]           = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
    imgui.GetStyle().Colors[imgui.Col.NavWindowingHighlight]  = imgui.ImVec4(1.00, 1.00, 1.00, 0.70)
    imgui.GetStyle().Colors[imgui.Col.NavWindowingDimBg]      = imgui.ImVec4(0.80, 0.80, 0.80, 0.20)
    imgui.GetStyle().Colors[imgui.Col.ModalWindowDimBg]       = imgui.ImVec4(0.00, 0.00, 0.00, 0.70)
end

[ML] (error) ctime_td.lua: ...izona Games Launcher\bin\arizona\moonloader\ctime_td.lua:77: 'float [1]' has no member named 'v'
stack traceback:
...izona Games Launcher\bin\arizona\moonloader\ctime_td.lua:77: in function '_draw'
...ames Launcher\bin\arizona\moonloader\lib\mimgui\init.lua:107: in function <...ames Launcher\bin\arizona\moonloader\lib\mimgui\init.lua:91>
[ML] (error) ctime_td.lua: Script died due to an error. (4146CB44)

при добавлении .v

и малейшем движении ползунка
 

chromiusj

R&B-baby-queen
Модератор
5,570
3,881
Lua:
---=== Библиотеки ===---

local imgui = require 'mimgui'
local ffi = require 'ffi'
local inicfg = require 'inicfg'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

---=== IniCfg ===---

local IniFilename = 'CTime_v2.ini'
local settings = inicfg.load({
    position = {
        posX=150,
        posY=170,
    },
    main = {
        text='CTime',
        enabled=false,
        sizeTime=1,
        sizeText=1,
    }
}, IniFilename)

---=== Переменные Mimgui ===---

local new = imgui.new
local str = ffi.string
local renderWindow = new.bool(false)

---=== Переменные ===---

checkbox_work = new.bool(settings.main.enabled)
input_text = new.char[6](u8(settings.main.text))
SetTimePos = false
ttext = settings.main.text
SizeTime = new.float(settings.main.sizeTime)
SizeText = new.float(settings.main.sizeText)

---=== Mimgui Code ===---

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
    imgui.DarkTheme()
end)

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 600, 300
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'Настройки CTime', renderWindow)
            imgui.Text(u8'Увидев, что на BlastHack множество человек ищет данный скрипт, я решил написать его копию.')
            imgui.Separator()
            if imgui.Checkbox(u8'Показывать на экране', checkbox_work) then
                settings.main.enabled = checkbox_work[0]
                inicfg.save(settings, IniFilename)
            end

            imgui.Separator()
            imgui.Text(u8'Настройки часов')

            if imgui.InputText(u8'Введите текст для отображения', input_text, 6) then
                settings.main.text = u8:decode(str(input_text))
                inicfg.save(settings, IniFilename)
            end
            if imgui.Button(u8'Очистить') then
                imgui.StrCopy(input_text, '')
                settings.main.text = ''
                inicfg.save(settings, IniFilename)
            end
            imgui.Text(u8'Изменения будут применены только после перезахода')
            if imgui.SliderFloat(u8'Размер шрифта часов', SizeTime, 0, 3) then
                settings.main.sizeTime = SizeTime
                inicfg.save(settings, IniFilename)
            end

            imgui.Separator()
            imgui.Text(u8'Координаты часов')

            if imgui.Button(u8'Установить положение часов', imgui.ImVec2(75, 25)) then
                SetTimePos = true
                if SetTimePos then
                    showCursor(true)
                    sampAddChatMessage('Установи положение текстдрава', -1)
                else
                    sampAddChatMessage('Текстдрав установлен', -1)
                end
            end
        imgui.End()
    end)

---=== Main Code ===---

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('set.ctime', function()
        renderWindow[0] = not renderWindow[0]
    end)

    while true do
        wait(0)
            if checkbox_work[0] then

            sampTextdrawCreate(444, ttext, settings.position.posX, settings.position.posY-10)
            sampTextdrawSetLetterSizeAndColor(444, 0.3, settings.position.posX, 0xFFFFFFFF)
            sampTextdrawSetOutlineColor(444, 0.5, 0xFF000000)
            sampTextdrawSetAlign(444, 1)
            sampTextdrawSetStyle(444, 2)

           
            sampTextdrawCreate(333, os.date("%H:%M:%S"), settings.position.posX, settings.position.posY)
            sampTextdrawSetLetterSizeAndColor(333, 0.3, settings.main.sizeTime, 0xFFFFFFFF)
            sampTextdrawSetOutlineColor(333, 0.5, 0xFF000000)
            sampTextdrawSetAlign(333, 1)
            sampTextdrawSetStyle(333, 2)
        else
            sampTextdrawDelete(333)
            sampTextdrawDelete(444)

        end

        if SetTimePos then

            sampSetCursorMode(2)
            posX, posY = getCursorPos()
            settings.position.posX, settings.position.posY = convertWindowScreenCoordsToGameScreenCoords(posX, posY)
            inicfg.save(settings, IniFilename)
            sampTextdrawSetPos(222, settings.position.posX, settings.position.posY)
            sampTextdrawSetPos(333, settings.position.posX, settings.position.posY-10)
            if wasKeyPressed(1) then
                SetTimePos = not SetTimePos
                showCursor(false)
            end
        end
    end
end

---=== Темная Тема Mimgui ===---

function imgui.DarkTheme()
    imgui.SwitchContext()
    --==[ STYLE ]==--
    imgui.GetStyle().WindowPadding = imgui.ImVec2(10, 5)
    imgui.GetStyle().FramePadding = imgui.ImVec2(5, 5)
    imgui.GetStyle().ItemSpacing = imgui.ImVec2(5, 5)
    imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(2, 2)
    imgui.GetStyle().TouchExtraPadding = imgui.ImVec2(0, 0)
    imgui.GetStyle().IndentSpacing = 0
    imgui.GetStyle().ScrollbarSize = 0
    imgui.GetStyle().GrabMinSize = 10

    --==[ BORDER ]==--
    imgui.GetStyle().WindowBorderSize = 1
    imgui.GetStyle().ChildBorderSize = 1
    imgui.GetStyle().PopupBorderSize = 1
    imgui.GetStyle().FrameBorderSize = 1
    imgui.GetStyle().TabBorderSize = 1

    --==[ ROUNDING ]==--
    imgui.GetStyle().WindowRounding = 10
    imgui.GetStyle().ChildRounding = 5
    imgui.GetStyle().FrameRounding = 5
    imgui.GetStyle().PopupRounding = 5
    imgui.GetStyle().ScrollbarRounding = 5
    imgui.GetStyle().GrabRounding = 5
    imgui.GetStyle().TabRounding = 5

    --==[ ALIGN ]==--
    imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    imgui.GetStyle().ButtonTextAlign = imgui.ImVec2(0.5, 0.5)
    imgui.GetStyle().SelectableTextAlign = imgui.ImVec2(0.5, 0.5)
   
    --==[ COLORS ]==--
    imgui.GetStyle().Colors[imgui.Col.Text]                   = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TextDisabled]           = imgui.ImVec4(0.50, 0.50, 0.50, 1.00)
    imgui.GetStyle().Colors[imgui.Col.WindowBg]               = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ChildBg]                = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PopupBg]                = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Border]                 = imgui.ImVec4(0.25, 0.25, 0.26, 0.54)
    imgui.GetStyle().Colors[imgui.Col.BorderShadow]           = imgui.ImVec4(0.00, 0.00, 0.00, 0.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBg]                = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBgHovered]         = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
    imgui.GetStyle().Colors[imgui.Col.FrameBgActive]          = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBg]                = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBgActive]          = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed]       = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.MenuBarBg]              = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarBg]            = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab]          = imgui.ImVec4(0.00, 0.00, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered]   = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive]    = imgui.ImVec4(0.51, 0.51, 0.51, 1.00)
    imgui.GetStyle().Colors[imgui.Col.CheckMark]              = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SliderGrab]             = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SliderGrabActive]       = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Button]                 = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ButtonHovered]          = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ButtonActive]           = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Header]                 = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.HeaderHovered]          = imgui.ImVec4(0.20, 0.20, 0.20, 1.00)
    imgui.GetStyle().Colors[imgui.Col.HeaderActive]           = imgui.ImVec4(0.47, 0.47, 0.47, 1.00)
    imgui.GetStyle().Colors[imgui.Col.Separator]              = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SeparatorHovered]       = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.SeparatorActive]        = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.ResizeGrip]             = imgui.ImVec4(1.00, 1.00, 1.00, 0.25)
    imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered]      = imgui.ImVec4(1.00, 1.00, 1.00, 0.67)
    imgui.GetStyle().Colors[imgui.Col.ResizeGripActive]       = imgui.ImVec4(1.00, 1.00, 1.00, 0.95)
    imgui.GetStyle().Colors[imgui.Col.Tab]                    = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabHovered]             = imgui.ImVec4(0.28, 0.28, 0.28, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabActive]              = imgui.ImVec4(0.30, 0.30, 0.30, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TabUnfocused]           = imgui.ImVec4(0.07, 0.10, 0.15, 0.97)
    imgui.GetStyle().Colors[imgui.Col.TabUnfocusedActive]     = imgui.ImVec4(0.14, 0.26, 0.42, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotLines]              = imgui.ImVec4(0.61, 0.61, 0.61, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered]       = imgui.ImVec4(1.00, 0.43, 0.35, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotHistogram]          = imgui.ImVec4(0.90, 0.70, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered]   = imgui.ImVec4(1.00, 0.60, 0.00, 1.00)
    imgui.GetStyle().Colors[imgui.Col.TextSelectedBg]         = imgui.ImVec4(1.00, 0.00, 0.00, 0.35)
    imgui.GetStyle().Colors[imgui.Col.DragDropTarget]         = imgui.ImVec4(1.00, 1.00, 0.00, 0.90)
    imgui.GetStyle().Colors[imgui.Col.NavHighlight]           = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
    imgui.GetStyle().Colors[imgui.Col.NavWindowingHighlight]  = imgui.ImVec4(1.00, 1.00, 1.00, 0.70)
    imgui.GetStyle().Colors[imgui.Col.NavWindowingDimBg]      = imgui.ImVec4(0.80, 0.80, 0.80, 0.20)
    imgui.GetStyle().Colors[imgui.Col.ModalWindowDimBg]       = imgui.ImVec4(0.00, 0.00, 0.00, 0.70)
end

[ML] (error) ctime_td.lua: ...izona Games Launcher\bin\arizona\moonloader\ctime_td.lua:77: 'float [1]' has no member named 'v'
stack traceback:
...izona Games Launcher\bin\arizona\moonloader\ctime_td.lua:77: in function '_draw'
...ames Launcher\bin\arizona\moonloader\lib\mimgui\init.lua:107: in function <...ames Launcher\bin\arizona\moonloader\lib\mimgui\init.lua:91>
[ML] (error) ctime_td.lua: Script died due to an error. (4146CB44)

при добавлении .v

и малейшем движении ползунка
Дмитрий видимо подумал что у тебя imgui. Для mimgui значение переменной обозначают [0]
т.е так: variable[0]
 
  • Нравится
Реакции: Dmitriy Makarov и cloused2