Вывод ников в меню

ReoGenT

Участник
Автор темы
90
6
Версия MoonLoader
.026-beta
возможно ли вывести все ники /admins в imgui меню? Причем не вводя /admins
 

VRush

https://t.me/vrushscript
2,417
1,207
просто искать текст в диалоге, и добавлять его в таблицу, потом из таблицы все выводить в имгуи
Код:
      for line in string.gmatch(text, "[^\r\n]+") do
         sampAddChatMessage(line, 0xF0A531)
         admins[#admins+ 1] = line
      end

а если в чате, то искать в чате
(.+)[(%d+)] Основатель
Потом выводить в таблицу, и опять таки таблицу кидать в имгуи

Если диалогом то на:
require 'lib.moonloader'
local ev =  require 'samp.events'

local admins = { }
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local window = imgui.ImBool(false)

function theme()

    imgui.SwitchContext()
    local style  = imgui.GetStyle()
    local colors = style.Colors
    local clr    = imgui.Col
    local ImVec4 = imgui.ImVec4
    local ImVec2 = imgui.ImVec2
 
    style.WindowRounding         = 4.0
    style.WindowTitleAlign       = ImVec2(0.5, 0.5)
    style.ChildWindowRounding    = 2.0
    style.FrameRounding          = 4.0
    style.ItemSpacing            = ImVec2(10, 5)
    style.ScrollbarSize          = 15
    style.ScrollbarRounding      = 0
    style.GrabMinSize            = 9.6
    style.GrabRounding           = 1.0
    style.WindowPadding          = ImVec2(10, 10)
    style.AntiAliasedLines       = true
    style.AntiAliasedShapes      = true
    style.FramePadding           = ImVec2(5, 4)
    style.DisplayWindowPadding   = ImVec2(27, 27)
    style.DisplaySafeAreaPadding = ImVec2(5, 5)
    style.ButtonTextAlign        = ImVec2(0.5, 0.5)
    style.IndentSpacing          = 12.0
    style.Alpha                  = 1.0
 
    colors[clr.Text]                 = ImVec4(0.75, 0.75, 0.75, 1.00)
    colors[clr.TextDisabled]         = ImVec4(0.35, 0.35, 0.35, 1.00)
    colors[clr.WindowBg]             = ImVec4(0.00, 0.00, 0.00, 0.94)
    colors[clr.ChildWindowBg]        = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.PopupBg]              = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.Border]               = ImVec4(0.00, 0.00, 0.00, 0.50)
    colors[clr.BorderShadow]         = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg]              = ImVec4(0.00, 0.00, 0.00, 0.54)
    colors[clr.FrameBgHovered]       = ImVec4(0.37, 0.14, 0.14, 0.67)
    colors[clr.FrameBgActive]        = ImVec4(0.39, 0.20, 0.20, 0.67)
    colors[clr.TitleBg]              = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]        = ImVec4(0.48, 0.16, 0.16, 1.00)
    colors[clr.TitleBgCollapsed]     = ImVec4(0.48, 0.16, 0.16, 1.00)
    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.56, 0.10, 0.10, 1.00)
    colors[clr.SliderGrab]           = ImVec4(1.00, 0.19, 0.19, 0.40)
    colors[clr.SliderGrabActive]     = ImVec4(0.89, 0.00, 0.19, 1.00)
    colors[clr.Button]               = ImVec4(1.00, 0.19, 0.19, 0.40)
    colors[clr.ButtonHovered]        = ImVec4(0.80, 0.17, 0.00, 1.00)
    colors[clr.ButtonActive]         = ImVec4(0.89, 0.00, 0.19, 1.00)
    colors[clr.Header]               = ImVec4(0.33, 0.35, 0.36, 0.53)
    colors[clr.HeaderHovered]        = ImVec4(0.76, 0.28, 0.44, 0.67)
    colors[clr.HeaderActive]         = ImVec4(0.47, 0.47, 0.47, 0.67)
    colors[clr.Separator]            = ImVec4(0.32, 0.32, 0.32, 1.00)
    colors[clr.SeparatorHovered]     = ImVec4(0.32, 0.32, 0.32, 1.00)
    colors[clr.SeparatorActive]      = ImVec4(0.32, 0.32, 0.32, 1.00)
    colors[clr.ResizeGrip]           = ImVec4(1.00, 1.00, 1.00, 0.85)
    colors[clr.ResizeGripHovered]    = ImVec4(1.00, 1.00, 1.00, 0.60)
    colors[clr.ResizeGripActive]     = ImVec4(1.00, 1.00, 1.00, 0.90)
    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

function imgui.OnDrawFrame()
    if window.v then
        imgui.SetNextWindowPos(imgui.ImVec2(1563.0, 250.0), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(350.0, 200.0), imgui.Cond.FirstUseEver)
        imgui.Begin('Заголовок', window)
    for i = 1, #admins do
        imgui.TextColoredRGB(admins[i])
    end
    if imgui.Button(u8'update', imgui.ImVec2(70, 30)) then
        sampSendChat("/admins")
    end
    if imgui.Button('cursor', imgui.ImVec2(50, 30)) then
        imgui.ShowCursor = false
    end
        imgui.End()
    end
end

theme()
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('madmins', function ()
        window.v = not window.v
    end)
        sampRegisterChatCommand('fishcheck', function ()
            admins = { }
            sampSendChat("/invent")
        end)
        imgui.Process = false
        window.v = true
        while true do
             wait(0)
             imgui.Process = window.v
    end
end

function ev.onShowDialog(id, style, title, but_1, but_2, text)
    if id == 0 and title:find('Администрация') then
        for line in string.gmatch(text, "[^\r\n]+") do
            sampAddChatMessage(line, 0xF0A531)
            admins[#admins + 1] = line
        end
        sampSendDialogResponse(id, 0, nil, nil)
        return false
    end
end

function imgui.TextColoredRGB(string)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col

    local function color_imvec4(color)
         if color:upper() == 'SSSSSS' then return colors[clr.Text] end
         local color = type(color) == 'number' and ('%X'):format(color):upper() or color:upper()
         local rgb = {}
         for i = 1, #color/2 do rgb[#rgb+1] = tonumber(color:sub(2*i-1, 2*i), 16) end
         return imgui.ImVec4(rgb[1]/255, rgb[2]/255, rgb[3]/255, rgb[4] and rgb[4]/255 or colors[clr.Text].w)
    end

    local function render_text(string)
         local text, color = {}, {}
         local m = 1
         while string:find('{......}') do
              local n, k = string:find('{......}')
              text[#text], text[#text+1] = string:sub(m, n-1), string:sub(k+1, #string)
              color[#color+1] = color_imvec4(string:sub(n+1, k-1))
              local t1, t2 = string:sub(1, n-1), string:sub(k+1, #string)
              string = t1..t2
              m = k-7
         end
         if text[0] then
              for i, _ in ipairs(text) do
                    imgui.TextColored(color[i] or colors[clr.Text], u8(text[i]))
                    imgui.SameLine(nil, 0)
              end
              imgui.NewLine()
         else imgui.Text(u8(string)) end
    end

    render_text(string)
end