интеграция по таблице

Статус
В этой теме нельзя размещать новые ответы.

fsrxvdd

Активный
Автор темы
117
25
Версия MoonLoader
.026-beta
1:
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

massive = {
    ['ХП'] = '/usedrugs 3', u8'Нажмите на кнопку 1',
    ['Броня'] = '/armour', u8'Нажмите на кнопку 2',
    ['Маска'] = '/mask', u8'Нажмите на кнопку 3',
    ['Ремка'] = '/repcar', u8'Нажмите на кнопку 4',
    ['Канистра'] = '/fillcar', u8'Нажмите на кнопку 5'
}

local renderWindow = imgui.new.bool(true)

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

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 300, 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)
        if imgui.Begin('Main Window', renderWindow) then
            for i, j, k in massive do
                if imgui.Button(i) then
                    sampSendChat(j)
                end
                imgui.Text(k)
        imgui.End()
        end
    end
end)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui', function()
        renderWindow[0] = not renderWindow[0]
    end)
    wait(-1)
end
Почему не работает интеграция по таблице?
 
Решение
Lua:
massive = {
    ['ХП'] = {command = '/usedrugs 3', text = 'Нажмите на кнопку 1'},
    ['Броня'] = {command = '/armour', text = 'Нажмите на кнопку 2'},
    ['Маска'] = {command = '/mask', text = 'Нажмите на кнопку 3'},
    ['Ремка'] = {command = '/repcar', text = 'Нажмите на кнопку 4'},
    ['Канистра'] = {command = '/fillcar', text = 'Нажмите на кнопку 5'},
}

for key, value in ipairs(massive) do
    if imgui.Button(u8(key)) then
        sampSendChat(value.command)
    end
    imgui.Text(u8(value.text))
end
Lua:
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

massive = {
    ['ХП'] = {cmd = '/usedrugs 3', desc = u8'Нажмите на кнопку 1'},
    ['Броня'] = {cmd...

Byte

Участник
97
16
Lua:
massive = {
    ['ХП'] = {command = '/usedrugs 3', text = 'Нажмите на кнопку 1'},
    ['Броня'] = {command = '/armour', text = 'Нажмите на кнопку 2'},
    ['Маска'] = {command = '/mask', text = 'Нажмите на кнопку 3'},
    ['Ремка'] = {command = '/repcar', text = 'Нажмите на кнопку 4'},
    ['Канистра'] = {command = '/fillcar', text = 'Нажмите на кнопку 5'},
}

for key, value in ipairs(massive) do
    if imgui.Button(u8(key)) then
        sampSendChat(value.command)
    end
    imgui.Text(u8(value.text))
end
Lua:
local imgui = require 'mimgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

massive = {
    ['ХП'] = {cmd = '/usedrugs 3', desc = u8'Нажмите на кнопку 1'},
    ['Броня'] = {cmd = '/armour', desc = u8'Нажмите на кнопку 2'},
    ['Маска'] = {cmd = '/mask', desc = u8'Нажмите на кнопку 3'},
    ['Ремка'] = {cmd = '/repcar', desc = u8'Нажмите на кнопку 4'},
    ['Канистра'] = {cmd = '/fillcar', desc = u8'Нажмите на кнопку 5'}
}

local renderWindow = imgui.new.bool(true)

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

local newFrame = imgui.OnFrame(
    function() return renderWindow[0] end,
    function(player)
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 300, 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)
        if imgui.Begin('Main Window', renderWindow) then
            for name, data in pairs(massive) do
                if imgui.Button(name) then
                    sampSendChat(data.cmd)
                end
                imgui.Text(data.desc)
            end
            imgui.End()
        end
    end
)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('mimgui', function()
        renderWindow[0] = not renderWindow[0]
    end)
    wait(-1)
end
 
Статус
В этой теме нельзя размещать новые ответы.