Не работает imgui.Hotkey

Vespan

Чешский луашер
Автор темы
Проверенный
2,123
1,731
Версия MoonLoader
.026-beta
Не работает скрипт,если добавляю такие строки:
Lua:
-- верх main()
local rkeys = require 'rkeys'
local key = require 'vkeys'
imgui.HotKey = require('imgui_addons').HotKey

local ActiveMenu = {
    v = {key.VK_F5}
}
local bindID = 0

--

-- main()
    bindID = rkeys.registerHotKey(ActiveMenu.v, true, function ()
        WallHackSkeletal = not WallHackSkeletal
    end)
--

-- imgui
            if imgui.HotKey("##keyWH", ActiveMenu, tLastKeys, 100) then
                rkeys.changeHotKey(bindID, ActiveMenu.v)
                sampAddChatMessage("Успешно! Старое значение: " .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. " | Новое: " .. table.concat(rkeys.getKeysName(ActiveMenu.v), " + "), -1)
            end
Ошибка
moonloader.log || ERROR:
[20:20:58.252838] (error)    Admin Tools [Gold-Rp].lua: D:\GTA\moonloader\Admin Tools [Gold-Rp].lua:2778: function at line 2163 has more than 60 upvalues
[20:20:58.252838] (error)    Admin Tools [Gold-Rp].lua: Script died due to an error. (0A924BDC)
Если я не добавлю это всё то работает скрипт
У меня есть imgui_addons.lua в папке moonloader/lib/ | и есть rkeys / vkeys
 
Решение
Какие элементы?Я всё это проделал в тестовом .lua и всё работало
Lua:
-- // Библиотеки // --
local imgui = require 'imgui'
local key = require 'vkeys'
local encoding = require 'encoding'
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey

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

-- // Для кнопок | imgui // --
local main_window_state = imgui.ImBool(false)

-- // Прочее // --
local ActiveMenu = {
    v = {key.VK_N}
}
local bindID = 0

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4

    style.WindowRounding = 2.0
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)...

Vespan

Чешский луашер
Автор темы
Проверенный
2,123
1,731
У тебя слишком много элементов в одной функции, раздели всё на несколько функций и запусти их в основной.
Какие элементы?Я всё это проделал в тестовом .lua и всё работало
Lua:
-- // Библиотеки // --
local imgui = require 'imgui'
local key = require 'vkeys'
local encoding = require 'encoding'
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey

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

-- // Для кнопок | imgui // --
local main_window_state = imgui.ImBool(false)

-- // Прочее // --
local ActiveMenu = {
    v = {key.VK_N}
}
local bindID = 0

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4

    style.WindowRounding = 2.0
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)
    style.ChildWindowRounding = 2.0
    style.FrameRounding = 2.0
    style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.GrabMinSize = 8.0
    style.GrabRounding = 1.0
    -- style.Alpha =
    -- style.WindowPadding =
    -- style.WindowMinSize =
    -- style.FramePadding =
    -- style.ItemInnerSpacing =
    -- style.TouchExtraPadding =
    -- style.IndentSpacing =
    -- style.ColumnsMinSpacing = ?
    -- style.ButtonTextAlign =
    -- style.DisplayWindowPadding =
    -- style.DisplaySafeAreaPadding =
    -- style.AntiAliasedLines =
    -- style.AntiAliasedShapes =
    -- style.CurveTessellationTol =

    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.35)
end
apply_custom_style()

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

    sampRegisterChatCommand('/test', function() main_window_state.v = not main_window_state.v end)
    sampRegisterChatCommand('/test1', test_1)
    sampRegisterChatCommand('/test2', test_2)

    bindID = rkeys.registerHotKey(ActiveMenu.v, true, function ()
        main_window_state.v = not main_window_state.v
    end)

  while true do
    wait(0)   
    imgui.Process = main_window_state.v
    end
end

function test_1(arg)
        car_hundle = storeCarCharIsInNoSave(PLAYER_PED)
    result, id = sampGetVehicleIdByCarHandle(car_hundle)
    if result then
        sampAddChatMessage(id, -1)
    end
end

function test_2(arg)
    var = not var if var then
        setCharProofs(PLAYER_PED, true, true, true, true, true)
        sampAddChatMessage('GM ON', -1)
    else
        setCharProofs(PLAYER_PED, false, false, false, false, false)
        sampAddChatMessage('GM OFF', -1)
    end
end

function imgui.OnDrawFrame()

    local tLastKeys = {}

  if main_window_state.v then
    local sw, sh = getScreenResolution()
    imgui.SetNextWindowPos(imgui.ImVec2(650, 300), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(200, 200), imgui.Cond.FirstUseEver)
    imgui.Begin('My window', main_window_state)
    if imgui.Button('test1') then
        sampAddChatMessage('3131')
    end
    if imgui.HotKey("##active", ActiveMenu, tLastKeys, 100) then -- HOTKEY
        rkeys.changeHotKey(bindID, ActiveMenu.v)
        sampAddChatMessage("Успешно! Старое значение: " .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. " | Новое: " .. table.concat(rkeys.getKeysName(ActiveMenu.v), " + "), -1)
    end
    if imgui.Button('Message') then
        sampAddChatMessage('isCursorActive', -1)
    end
    imgui.End()
  end
end
 

Quasper

Известный
835
354
Какие элементы?Я всё это проделал в тестовом .lua и всё работало
Lua:
-- // Библиотеки // --
local imgui = require 'imgui'
local key = require 'vkeys'
local encoding = require 'encoding'
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey

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

-- // Для кнопок | imgui // --
local main_window_state = imgui.ImBool(false)

-- // Прочее // --
local ActiveMenu = {
    v = {key.VK_N}
}
local bindID = 0

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4

    style.WindowRounding = 2.0
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)
    style.ChildWindowRounding = 2.0
    style.FrameRounding = 2.0
    style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.GrabMinSize = 8.0
    style.GrabRounding = 1.0
    -- style.Alpha =
    -- style.WindowPadding =
    -- style.WindowMinSize =
    -- style.FramePadding =
    -- style.ItemInnerSpacing =
    -- style.TouchExtraPadding =
    -- style.IndentSpacing =
    -- style.ColumnsMinSpacing = ?
    -- style.ButtonTextAlign =
    -- style.DisplayWindowPadding =
    -- style.DisplaySafeAreaPadding =
    -- style.AntiAliasedLines =
    -- style.AntiAliasedShapes =
    -- style.CurveTessellationTol =

    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.35)
end
apply_custom_style()

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

    sampRegisterChatCommand('/test', function() main_window_state.v = not main_window_state.v end)
    sampRegisterChatCommand('/test1', test_1)
    sampRegisterChatCommand('/test2', test_2)

    bindID = rkeys.registerHotKey(ActiveMenu.v, true, function ()
        main_window_state.v = not main_window_state.v
    end)

  while true do
    wait(0)  
    imgui.Process = main_window_state.v
    end
end

function test_1(arg)
        car_hundle = storeCarCharIsInNoSave(PLAYER_PED)
    result, id = sampGetVehicleIdByCarHandle(car_hundle)
    if result then
        sampAddChatMessage(id, -1)
    end
end

function test_2(arg)
    var = not var if var then
        setCharProofs(PLAYER_PED, true, true, true, true, true)
        sampAddChatMessage('GM ON', -1)
    else
        setCharProofs(PLAYER_PED, false, false, false, false, false)
        sampAddChatMessage('GM OFF', -1)
    end
end

function imgui.OnDrawFrame()

    local tLastKeys = {}

  if main_window_state.v then
    local sw, sh = getScreenResolution()
    imgui.SetNextWindowPos(imgui.ImVec2(650, 300), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(200, 200), imgui.Cond.FirstUseEver)
    imgui.Begin('My window', main_window_state)
    if imgui.Button('test1') then
        sampAddChatMessage('3131')
    end
    if imgui.HotKey("##active", ActiveMenu, tLastKeys, 100) then -- HOTKEY
        rkeys.changeHotKey(bindID, ActiveMenu.v)
        sampAddChatMessage("Успешно! Старое значение: " .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. " | Новое: " .. table.concat(rkeys.getKeysName(ActiveMenu.v), " + "), -1)
    end
    if imgui.Button('Message') then
        sampAddChatMessage('isCursorActive', -1)
    end
    imgui.End()
  end
end
элементы имгуи, в бегине. Имгуи жалуется что превышен лимит(в 60 элементов на бегин). Разделяй их по функциям как тебе сказали выше
Пример:
Код:
function imgui.OnDrawFrame()
    if window.v then
        imgui.Begin()
            elements()
            elements1()
        imgui.End()
    end
end

function elements()
    imgui.Button("Test") -- и прочие элементы
end

function elements1()
    imgui.Text("Test") -- и прочие элементы
end
Главное соблюдай порядок расстановки элементов для правильного рендера, ну думаю разберёшься