Получение данных в OnFrame - mimgui

Sergey_Turner

Участник
Автор темы
102
7
Версия MoonLoader
.026-beta
Использую mimgui, и при рисовке получаю данные:
Lua:
_, pID = sampGetPlayerIdByCharHandle(PLAYER_PED)
При запуске сампа в скрипте возникает данная ошибка:
opcode '0B2B' call caused an unhandled exception (sampGetPlayerIdByCharHandle)

Но если скрипт перезапустить, всё встаёт на своё место.
Место кода в init.lua на который жалуется (17 строка):
Lua:
addEventHandler('onD3DPresent', function()
        if active then
            if not renderer then
                InitializeRenderer()
            end
            if renderer and not renderer.lost then
                renderer:SwitchContext()
                for _, sub in ipairs(subscriptionsNewFrame) do
                    if sub._render and sub._before then
                        sub:_before()
                    end
                end
                renderer:NewFrame()
                local hideCursor = true
                for _, sub in ipairs(subscriptionsNewFrame) do
                    if sub._render then
                        sub:_draw()
                        hideCursor = hideCursor and sub.HideCursor
                    end
                end
                if hideCursor and not isCursorActive() then
                    imgui.SetMouseCursor(imgui.lib.ImGuiMouseCursor_None)
                end
                renderer:EndFrame()
            end
        end
    end)
 

Rice.

https://t.me/riceoff
Модератор
1,689
1,433
Использую mimgui, и при рисовке получаю данные:
Lua:
_, pID = sampGetPlayerIdByCharHandle(PLAYER_PED)
При запуске сампа в скрипте возникает данная ошибка:
opcode '0B2B' call caused an unhandled exception (sampGetPlayerIdByCharHandle)

Но если скрипт перезапустить, всё встаёт на своё место.
Место кода в init.lua на который жалуется (17 строка):
Lua:
addEventHandler('onD3DPresent', function()
        if active then
            if not renderer then
                InitializeRenderer()
            end
            if renderer and not renderer.lost then
                renderer:SwitchContext()
                for _, sub in ipairs(subscriptionsNewFrame) do
                    if sub._render and sub._before then
                        sub:_before()
                    end
                end
                renderer:NewFrame()
                local hideCursor = true
                for _, sub in ipairs(subscriptionsNewFrame) do
                    if sub._render then
                        sub:_draw()
                        hideCursor = hideCursor and sub.HideCursor
                    end
                end
                if hideCursor and not isCursorActive() then
                    imgui.SetMouseCursor(imgui.lib.ImGuiMouseCursor_None)
                end
                renderer:EndFrame()
            end
        end
    end)
Свой скрипт лучше покажи, а не вырезку из библиотеки
 

Sergey_Turner

Участник
Автор темы
102
7
Свой скрипт лучше покажи, а не вырезку из библиотеки

Lua:
local InfoWindow = imgui.OnFrame(
    function() return InfoWindow[0] end,
    function(player)

        imgui.SetNextWindowPos(imgui.ImVec2(infoWindowX, infoWindowY), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(200, SizeYInfo), imgui.Cond.FirstUseEver)

        imgui.PushStyleColor(imgui.Col.WindowBg, imgui.ImVec4(0.11, 0.15, 0.17, 0.6))
            imgui.Begin('InfoWindow', InfoWindow, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoMove + imgui.WindowFlags.NoScrollbar)

            _, pID = sampGetPlayerIdByCharHandle(PLAYER_PED)
            health = sampGetPlayerHealth(pID)
            
            if ToggleButton_HP[0] then
                if health >= 70 then
                    imgui.TextColoredRGB("{FFFFFF}HP: {00FF00}" .. health .. "%")
                elseif health >= 20 then
                    imgui.TextColoredRGB("{FFFFFF}HP: {ffa203}" .. health .. "%")
                elseif health < 20 then
                    imgui.TextColoredRGB("{FFFFFF}HP: {FF0000}" .. health .. "%")
                end
            end
            
            imgui.End()
        imgui.PopStyleColor()
    end)