Помощь по scoreboard

W1ll04eison

Участник
Автор темы
328
19
Версия MoonLoader
.026-beta
Lua:
local imgui = require 'imgui'
local vkeys = require 'vkeys'
local bitex = require 'bitex'
local memory = require 'memory'
local encoding = require 'encoding'
encoding.default = 'CP1251'

-- DISABLE DEFAULT SA:MP SCOREBOARD (MINIFIED)
(function()
    patches={['SAMP_PATCH_SCOREBOARDTOGGLEON']=
    {
        old_value=nil,
        offset=0x6AA10,
        value=0xC3,
        size=1
    },
    ['SAMP_PATCH_SCOREBOARDTOGGLEONKEYLOCK']=
    {
        old_value=nil,
        offset=0x6AD30,
        value=0xC3,
        size=1
    }
        }setmetatable(patches,{__call=function(a,b,c)
        if type(b)~='string'then
            return
            end
            local d=a[b]if d~=nil then
            if type(c)~='boolean'then c=false
            end
            local e=false
            if c==false and d.old_value==nil then
                d.old_value=memory.getint8(sampGetBase()+d.offset,true)memory.write(sampGetBase()+d.offset,d.value,d.size,true)e=true
            elseif
            d.old_value~=nil then
                memory.write(sampGetBase()+d.offset,d.old_value,d.size,true)d.old_value=nil end
                return e
            end
        end})
end)()


local show_main_window = imgui.ImBool(false)
imgui.GetIO().MouseDoubleClickTime = 0.8

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

    patches('SAMP_PATCH_SCOREBOARDTOGGLEON')
    patches('SAMP_PATCH_SCOREBOARDTOGGLEONKEYLOCK')

    while true do
        wait(0)
        if wasKeyPressed(vkeys.VK_TAB) then
            if not show_main_window.v then
                if not sampIsChatInputActive() then
                    toggleScoreboard(true)
                end
            else
                toggleScoreboard(false)
            end
        end

        imgui.Process = show_main_window.v
    end
end

function toggleScoreboard(flag)
    if type(flag) == 'boolean' then
        show_main_window.v = flag
    else
        show_main_window.v = not show_main_window.v
    end
end

function getLocalPlayerId()
    local _, id = sampGetPlayerIdByCharHandle(playerPed)
    return id
end

function imgui.OnDrawFrame()
    if show_main_window.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(400, 480), imgui.Cond.FirstUseEver)
        imgui.Begin(encoding.UTF8(sampGetCurrentServerName()), show_main_window, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoResize)

        imgui.Text('Players: ' .. sampGetPlayerCount(false))

        imgui.Columns(4)
        imgui.Separator()
        imgui.SetColumnWidth(-1, 55); imgui.Text('ID'); imgui.NextColumn()
        imgui.SetColumnWidth(-1, 175); imgui.Text('Nickname'); imgui.NextColumn()
        imgui.SetColumnWidth(-1, 100); imgui.Text('Score'); imgui.NextColumn()
        imgui.SetColumnWidth(-1, 55); imgui.Text('Ping'); imgui.NextColumn()
        imgui.Separator()

        local local_player_id = getLocalPlayerId()
        drawScoreboardPlayer(local_player_id)
        for i = 0, sampGetMaxPlayerId(false) do
            if local_player_id ~= i and sampIsPlayerConnected(i) then
                drawScoreboardPlayer(i)
            end
        end

        imgui.Columns(1)
        imgui.Separator()

        imgui.End()
    end
end

function drawScoreboardPlayer(id)
    -- send scores&ping update?

    local nickname = encoding.UTF8(sampGetPlayerNickname(id))
    local score = sampGetPlayerScore(id)
    local ping = sampGetPlayerPing(id)
    local color = sampGetPlayerColor(id)
    local r, g, b = bitex.bextract(color, 16, 8), bitex.bextract(color, 8, 8), bitex.bextract(color, 0, 8)
    local imgui_RGBA = imgui.ImVec4(r / 255.0, g / 255.0, b / 255.0, 1)

    if imgui.Selectable(id, false, imgui.SelectableFlags.SpanAllColumns + imgui.SelectableFlags.AllowDoubleClick) then
        if imgui.IsMouseDoubleClicked(0) then
            sampSendClickPlayer(id, 0)
            toggleScoreboard(false)
        end
    end

    if imgui.BeginPopupContextItem() then
        imgui.TextColored(imgui_RGBA, nickname)

        if imgui.Button('Send \'Click Player\'') then
            sampSendClickPlayer(id, 0)
            imgui.CloseCurrentPopup()
            toggleScoreboard(false)
        end

        if imgui.Button('Copy nickname') then
            setClipboardText(nickname)
            imgui.CloseCurrentPopup()
        end

        if nickname:find('_') then
            if imgui.Button('Copy nickname (replace \'_\' to space)') then
                setClipboardText(nickname:gsub('_', ' ', 1))
                imgui.CloseCurrentPopup()
            end
        end

        imgui.EndPopup()
    end

    imgui.NextColumn()

    imgui.TextColored(imgui_RGBA, nickname); imgui.NextColumn()
    imgui.Text(score); imgui.NextColumn()
    imgui.Text(ping); imgui.NextColumn()
end

function onScriptTerminate(script, quitGame)
    if script == thisScript() then
        patches('SAMP_PATCH_SCOREBOARDTOGGLEON', true)
        patches('SAMP_PATCH_SCOREBOARDTOGGLEONKEYLOCK', true)
    end
end



У меня есть код(кинул выше, код scoreboard'a) и есть кнопка:
Lua:
imgui.ToggleButton(u8'  ', qwe)
Как сделать так что бы, если значение кнопки = true, то scoreboard будет работать, а если значение кнопки = false, то будет отображаться стандартный, самповский scoreboard