local easy_dialog = require "easy_dialog"
local samp = require "samp.events"
local Dialog = easy_dialog.Dialog
local employees = {}
local captureList = false
local employeesDialog = Dialog.new()
:setCaption(function(self)
return "Сотрудники онлайн (" .. tostring(#(self.list or {})) .. ")"
end)
:setStyle("tablist_headers")
:setHeaders({ "ID", "Имя", "Должность", "Статус" })
:setButtons("Подробнее", "Закрыть")
:setItemsPerPage(15)
:setOnStart(function(self, data)
self.list = (data and data.list) or {}
end)
:setItems(function(self)
local items = {}
for _, emp in ipairs(self.list or {}) do
local nameDisplay = emp.voice and ("{3498db}[V] {FFFFFF}" .. emp.name) or ("{FFFFFF}" .. emp.name)
local rankDisplay = string.format("{FFFF00}%s {CCCCCC}[%s]", emp.rank, emp.rankNum)
local statusDisplay = emp.status
if emp.afk then
statusDisplay = statusDisplay .. " {e74c3c}(AFK: " .. emp.afk .. ")"
end
table.insert(items, {
"{CCCCCC}" .. emp.id,
nameDisplay,
rankDisplay,
statusDisplay
})
end
return items
end)
:setOnResponse(function(self, button, index, _, item)
if button == 1 and self.list[index] then
easy_dialog.go("employee_info", { employee = self.list[index] })
end
end)
local employeeInfo = Dialog.new()
:setStyle("msgbox")
:setCaption("Карточка сотрудника")
:setButtons("Назад", "")
:setOnStart(function(self, data)
self.employee = data and data.employee
if not self.employee then
self:setContent("Ошибка данных")
return
end
local emp = self.employee
local afkInfo = emp.afk and ("{e74c3c}" .. emp.afk) or "{CCCCCC}Нет"
local voiceInfo = emp.voice and "{2ecc71}Присутствует" or "{e74c3c}Отсутствует"
local text = string.format(
"{FFFFFF}Имя: {3498db}%s\n" ..
"{FFFFFF}ID: {CCCCCC}%s\n" ..
"{FFFFFF}Ранг: {FFFF00}%s (%s)\n" ..
"{FFFFFF}Дата трудоустройства: {CCCCCC}%s\n" ..
"{FFFFFF}Voice чат: %s\n" ..
"{FFFFFF}Статус: %s\n" ..
"{FFFFFF}Время в AFK: %s",
emp.name,
emp.id,
emp.rank, emp.rankNum,
emp.datetime,
voiceInfo,
emp.status,
afkInfo
)
self:setContent(text)
end)
:setOnResponse(function()
easy_dialog.start("employees_dialog", { list = employees })
end)
function samp.onServerMessage(color, text)
if text:find("Члены организации Он%-лайн:") then
employees = {}
captureList = true
return
end
if captureList and text:find("Всего:") then
captureList = false
if #employees > 0 then
easy_dialog.start("employees_dialog", { list = employees })
end
return
end
if captureList then
if text:match("^%s*$") then return end
local id = text:match("ID:%s*(%d+)")
if not id then return end
local datetime = text:match("|%s*(%d+:%d+%s+%d+%.%d+%.%d+)") or ""
local dt_pattern = datetime:gsub("[%.%-]", "%%%1")
local nameSection = text:match(dt_pattern .. "%s*|%s*(.-):")
if nameSection then
local voice = false
local name = nameSection
if name:find("%(Voice%)") then
voice = true
name = name:gsub("%(Voice%)", "")
end
name = name:gsub("^%s+", ""):gsub("%s+$", "")
local splitPos = text:find(":", text:find(nameSection, 1, true))
if splitPos then
local tail = text:sub(splitPos + 1)
local rank, rankNum = tail:match("^%s*(.-)%[(%d+)%]")
rank = rank and rank:gsub("^%s+", ""):gsub("%s+$", "") or ""
local afkTime = nil
if tail:find("%[AFK%]") then
afkTime = tail:match("%[AFK%]:%s*(.*)$")
if afkTime then
afkTime = afkTime:gsub("^%s+", ""):gsub("%s+$", "")
end
end
local statusRaw = tail:match("%-%s*(.*)")
local status = "Неизвестно"
if statusRaw then
if afkTime then
status = statusRaw:match("^(.-)%s*|")
else
status = statusRaw
end
status = status and status:gsub("^%s+", ""):gsub("%s+$", "") or ""
end
table.insert(employees, {
id = id,
datetime = datetime,
name = name,
voice = voice,
rank = rank,
rankNum = rankNum,
status = status,
afk = afkTime
})
end
end
end
end
function main()
while not isSampAvailable() do wait(0) end
easy_dialog.init()
easy_dialog.register("employees_dialog", employeesDialog)
easy_dialog.register("employee_info", employeeInfo)
sampRegisterChatCommand("mb", function()
sampSendChat("/members")
end)
wait(-1)
end
function onScriptTerminate(script, quitGame)
if script == thisScript() then
easy_dialog.stop()
end
end