dialog = {
{
settings = {title = "Пример диалога" ,style = 4 ,btn1 = "Далее" ,btn2 = "Закрыть" ,forward = "{ffffff}" ,backwards = "\n" ,score = true},
{
{
title = "Диалог 0 стиля\t ",
click = function(button, list, input , outs)
if button == 1 then return dialog[2] end
end
},
{
title = "Диалог 1 стиля\t ",
click = function(button, list, input , outs)
if button == 1 then return dialog[3] end
end
},
{
title = "Диалог 2 стиля\t ",
click = function(button, list, input , outs)
if button == 1 then return dialog[4] end
end
},
{
title = "Диалог 3 стиля\t ",
click = function(button, list, input , outs)
if button == 1 then return dialog[5] end
end
},
{
title = "Диалог 4 стиля\t ",
click = function(button, list, input , outs)
if button == 1 then return dialog[6] end
end
},
{
title = "Диалог 5 стиля\t ",
click = function(button, list, input , outs)
if button == 1 then return dialog[7] end
end
}
},
{
{
title = " \t ",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("А тут пусто", 0xffcecece)
return true
end
end
},
{
title = "Сохранение параметров преведущих диалоговых окон\t ",
click = function(button, list, input , outs)
if button == 1 then
dialog[8].settings.title = "Окно №1"
return dialog[8], {["i"] = 1,{"","","","",""}}
end
end
},
{
title = "Расчет номера элемента для первой таблицы\t{00ff00}Включено",
click = function(button, list, input , outs)
if button == 1 then
dialog[1].settings.score = not dialog[1].settings.score
dialog[1][2][3].title = "Расчет номера элемента для первой таблицы\t"..(dialog[1].settings.score and "{00ff00}Включено" or "{ff0000}Выключено")
return true
end
end
}
}
},
{
settings = {title = "Диалог 0 стиля" ,style = 0 ,btn1 = "Назад" ,forward = "{ff0000}" ,backwards = "\n" ,score = false},
{
text = "{ffffff}Привет\nЭто диалог нулевого стиля.",
{
click = function(button, list, input , outs)
return dialog[1]
end
}
}
},
{
settings = {title = "Диалог 1 стиля" ,style = 1 ,btn1 = "Текст",btn2 = "Назад",forward = "{ff0000}" ,backwards = "\n" ,score = false},
{
text = "{ffffff}Привет\nЭто диалог первого стиля.\n \n{ff0000}А ниже можно что то написать.",
{
click = function(button, list, input , outs)
if button == 0 then
return dialog[1]
else
sampAddChatMessage("Вы написали в диалог вот это: "..input, 0xffcecece)
return true
end
end
}
}
},
{
settings = {title = "Диалог 2 стиля" ,style = 2 ,btn1 = "Назад",forward = "{ff0000}" ,backwards = "\n" ,score = false},
{
{
title = "1",
click = function(button, list, input , outs)
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
},
{
title = "2",
click = function(button, list, input , outs)
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
},
{
title = "3",
click = function(button, list, input , outs)
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
},
{
title = "4",
click = function(button, list, input , outs)
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
},
{
title = "5",
click = function(button, list, input , outs)
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
}
}
},
{
settings = {title = "Диалог 3 стиля" ,style = 3 ,btn1 = "Текст",btn2 = "Назад",forward = "{ff0000}" ,backwards = "\n" ,score = false},
{
text = "{ffffff}Привет\nЭто диалог третьего стиля.\n \n{ff0000}А ниже можно что то написать.",
{
click = function(button, list, input , outs)
if button == 0 then
return dialog[1]
else
sampAddChatMessage("Вы написали в диалог вот это: "..input, 0xffcecece)
return true
end
end
}
}
},
{
settings = {title = "Диалог 4 стиля" ,style = 4 ,btn1 = "Далее",btn2 = "Назад",forward = "{ff0000}" ,backwards = "\n" ,score = false},
{
{
title = "1\t2",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
return dialog[1]
end
},
{
title = "1\t2",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
return dialog[1]
end
},
{
title = "1\t2",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
return dialog[1]
end
},
{
title = "1\t2",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
return dialog[1]
end
}
}
},
{
settings = {title = "Диалог 5 стиля" ,style = 5 ,btn1 = "Далее",btn2 = "Назад",forward = "{ff0000}" ,backwards = "\n" ,score = false},
{
text = "Первое\tВторое",
{
title = "1\t2",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
return dialog[1]
end
},
{
title = "1\t2",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
return dialog[1]
end
},
{
title = "1\t2",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
return dialog[1]
end
},
{
title = "1\t2",
click = function(button, list, input , outs)
if button == 1 then
sampAddChatMessage("Выбран пункт: "..(list + 1), 0xffcecece)
return dialog[1]
end
return dialog[1]
end
}
}
},
{
settings = {title = "Окно №1" ,style = 1 ,btn1 = "Далее",btn2 = "Завершить",forward = "{ff0000}" ,backwards = "\n" ,score = false},
{
text = "{ffffff}Напишите что то в диалоговое окно.",
{
click = function(button, list, input , outs)
if button == 1 then
outs[1][outs.i] = tostring(input)
outs.i = outs.i + 1
dialog[8].settings.title = "Окно №"..outs.i
if outs.i > 5 then
dialog[9][1].text = "{ffffff}"
for i = 1, #outs[1] do
dialog[9][1].text = dialog[9][1].text.."Диалог №"..i..": "..tostring(outs[1][i]).."\n"
end
return dialog[9]
else
return dialog[8], outs
end
else
return dialog[1]
end
end
}
}
},
{
settings = {title = "Итог" ,style = 0 ,btn1 = "Повторить",btn2 = "Завершить",forward = "{ff0000}" ,backwards = "\n" ,score = false},
{
text = "",
{
click = function(button, list, input , outs)
if button == 1 then
dialog[8].settings.title = "Окно №1"
return dialog[8], {["i"] = 1,{"","","","",""}}
end
return dialog[1]
end
}
}
}
}
function main()
sampRegisterChatCommand("/test", function()
lua_thread.create(function()
start_dialog(dialog[1])
end)
end)
wait(-1)
end
function start_dialog(menu)
function _dialog(menu, id, outs)
local text = tbl_split(menu.settings.style, menu, menu.settings.forward ,menu.settings.backwards ,menu.settings.score)
sampShowDialog(id, menu.settings.title, text, menu.settings.btn1, (menu.settings.btn2 ~= nil and menu.settings.btn2 or _), menu.settings.style)
repeat
wait(0)
local result, button, list, input = sampHasDialogRespond(id)
if result then
local out, outs = menu[((menu.settings.style == 0 or menu.settings.style == 1 or menu.settings.style == 3) and 1 or ((list + 1) > #menu[1] and 2 or 1))][((menu.settings.style == 0 or menu.settings.style == 1 or menu.settings.style == 3) and 1 or ((list + 1) > #menu[1] and (list - #menu[1]) + 1 or list + 1))].click(button, list, input, outs)
if type(out) == "table" then
return _dialog(out, id - 1, outs)
elseif type(out) == "boolean" then
if not out then
return out
end
return _dialog(menu, id, outs)
end
end
until result
end
function tbl_split(style, tbl, forward ,backwards ,score)
if style == 2 or style == 4 or style == 5 then
text = (style == 5 and tbl[1].text.."\n" or "")
for i, val in ipairs(tbl[1]) do
text = text..""..forward..""..(score and "{ff0000}"..i..") " or "").."{ffffff}"..val.title..""..backwards
end
if tbl[2] ~= nil then
for _, val in ipairs(tbl[2]) do
text = text..""..forward..""..val.title..""..backwards
end
end
return text
end
return tbl[1].text
end
return _dialog(menu, 1337, outs)
end