-- В начало
local sf = require 'sampfuncs'
local script = {
dialogs = {
paragraph1 = true;
paragraph2 = false;
paragraph3 = false
}
}
-- в main()
function main()
sampRegisterChatCommand("dialog", function() lua_thread.create(dialog) end)
wait(-1)
end
-- Куда нибудь
function dialog()
local status = {}
for v, k in pairs(script.dialogs) do
if k == true then
status[v] = '{32C13E}[ON]'
elseif k == false then
status[v] = '{E21F1F}[OFF]'
end
end
local dialogs = {
{
title = 'Пункт 1: '..status['paragraph1'],
onclick = function(menu, row)
script.dialogs.paragraph1 = not script.dialogs.paragraph1
menu[row].title = 'Пункт 1: '..(script.dialogs.paragraph1 and '{32C13E}[ON]' or '{E21F1F}[OFF]')
return true
end
},
{
title = 'Пункт 2: '..status['paragraph2'],
onclick = function(menu, row)
script.dialogs.paragraph2 = not script.dialogs.paragraph2
menu[row].title = 'Пункт 2: '..(script.dialogs.paragraph2 and '{32C13E}[ON]' or '{E21F1F}[OFF]')
return true
end
},
{
title = 'Пункт 3: '..status['paragraph3'],
onclick = function(menu, row)
script.dialogs.paragraph3 = not script.dialogs.paragraph3
menu[row].title = 'Пункт 3: '..(script.dialogs.paragraph3 and '{32C13E}[ON]' or '{E21F1F}[OFF]')
return true
end
}
}
submenus_show(dialogs, "Тест", "Выбрать", "Закрыть")
end
function submenus_show(menu, caption, select_button, close_button, back_button)
select_button, close_button, back_button = select_button or 'Select', close_button or 'Close', back_button or 'Back'
prev_menus = {}
function display(menu, id, caption)
local string_list = {}
for i, v in ipairs(menu) do
table.insert(string_list, type(v.submenu) == 'table' and v.title .. ' >>' or v.title)
end
sampShowDialog(id, caption, table.concat(string_list, '\n'), select_button, (#prev_menus > 0) and back_button or close_button, sf.DIALOG_STYLE_LIST)
repeat
wait(0)
local result, button, list = sampHasDialogRespond(id)
if result then
if button == 1 and list ~= -1 then
local item = menu[list + 1]
if type(item.submenu) == 'table' then -- submenu
table.insert(prev_menus, {menu = menu, caption = caption})
if type(item.onclick) == 'function' then
item.onclick(menu, list + 1, item.submenu)
end
return display(item.submenu, id + 1, item.submenu.title and item.submenu.title or item.title)
elseif type(item.onclick) == 'function' then
local result = item.onclick(menu, list + 1)
if not result then return result end
return display(menu, id, caption)
end
else -- if button == 0
if #prev_menus > 0 then
local prev_menu = prev_menus[#prev_menus]
prev_menus[#prev_menus] = nil
return display(prev_menu.menu, id - 1, prev_menu.caption)
end
return false
end
end
until result
end
return display(menu, 31337, caption or menu.title)
end