added menu & blacklist

update
rubin 2 years ago
parent bb741c55de
commit 7fb54c9b2c
  1. 261
      mafia-tools.lua

@ -2,8 +2,6 @@ script_name('mafia-tools')
script_author("Serhiy_Rubin")
script_version("29.01.2023")
inspect = require("inspect")
sampev = require 'samp.events'
inicfg = require "inicfg"
dlstatus = require("moonloader").download_status
@ -23,12 +21,201 @@ function main()
lua_thread.create(timer_2min.loop)
lua_thread.create(ammo_timer.loop)
lua_thread.create(request.loop)
lua_thread.create(menu.loop)
while true do
wait(0)
end
end
--[[
Синхронизация таймингов
> Комната
> Участники комнаты
> Список блокировщика
> Использовать список как: Черный/Белый
]]
-->> MENU DIALOG
menu = {}
menu.dialog = {}
menu.color = "{fffd8f}"
menu.data = {}
menu.update = function()
-->> Обновление инфы от сервера
local players = getNicknamesOnline()
local count = 0
local members = {}
for sender, sender_data in pairs(menu.data) do
count = count + 1
-- for key, v in pairs(sender_data) do
-- if ammo_timer.data[key] ~= nil then
-- if ammo_timer.data[key]["time"] < v["time"] then
-- ammo_timer.data[key]["time"] = v["time"]
-- ammo_timer.data[key]["text"] = v["text"]
-- end
-- end
-- end
members[#members+1] = {
title = string.format("%s\t", (players[sender] ~= nil and sender.."["..players[sender].."]" or sender)),
click = function(button, list, input, outs)
if button == 1 then
menu.show = {
true,
"members_user",
{
{
title = (config.data.list[sender] ~= nil and "Убрать из списка" or "Добавить в список"),
click = function(button, list, input , outs)
if button == 1 then
if config.data.list[sender] == nil then
config.data.list[sender] = true
addChatMessage(string.format("Вы добавли %s в список!", sender))
else
config.data.list[sender] = nil
addChatMessage(string.format("Вы удалили %s из списка!", sender))
end
config.save(config.data)
end
menu.show = { true, "members" }
end
},
{
title = menu.color.."Тайминги от пользователя:",
click = function(button, list, input , outs)
menu.show = { true, "members" }
end
},
{
title = menu.color..">{FFFFFF} LS: "..sender_data["ls"]["text"].." "..(sender_data["mhcars"]["time"] > 0 and math.floor(msk_time.get() - sender_data["mhcars"]["time"]).." sec" or ""),
click = function(button, list, input , outs)
menu.show = { true, "members" }
end
},
{
title = menu.color..">{FFFFFF} SF: "..sender_data["sf"]["text"].." "..(sender_data["mhcars"]["time"] > 0 and math.floor(msk_time.get() - sender_data["mhcars"]["time"]).." sec" or ""),
click = function(button, list, input , outs)
menu.show = { true, "members" }
end
},
{
title = menu.color..">{FFFFFF} LV: "..sender_data["lv"]["text"].." "..(sender_data["mhcars"]["time"] > 0 and math.floor(msk_time.get() - sender_data["mhcars"]["time"]).." sec" or ""),
click = function(button, list, input , outs)
menu.show = { true, "members" }
end
},
{
title = menu.color..">{FFFFFF} MHCARS: "..sender_data["mhcars"]["text"].." "..(sender_data["mhcars"]["time"] > 0 and math.floor(msk_time.get() - sender_data["mhcars"]["time"]).." sec" or ""),
click = function(button, list, input , outs)
menu.show = { true, "members" }
end
},
}
}
else
menu.show = { true, "main" }
end
end
}
end
menu.dialog = {
["main"] = {
settings = {title = "mafia-tools" ,style = 4 ,btn1 = "Выбрать" ,btn2 = "Закрыть" ,forward = "{ffffff}" ,backwards = "\n" ,score = false},
{
{
title = menu.color.."Синхронизация таймингов\t",
click = function(button, list, input , outs)
if button ~= 1 then return end
menu.show = { true, "main" }
end
},
{
title = menu.color..">{ffffff} Комната\t"..config.data.room,
click = function(button, list, input , outs)
if button ~= 1 then return end
menu.show = { true, "edit", function(button, list, input, outs)
if button == 1 then
if #input > 0 then
config.data.room = input
config.save(config.data)
end
end
menu.show = { true, "main" }
end, config.data.room}
end
},
{
title = menu.color..">{ffffff} Участники комнаты\t"..count,
click = function(button, list, input , outs)
if button ~= 1 then return end
menu.show = { true, "members" }
end
},
{
title = menu.color..">{ffffff} Список блокировщика\t",
click = function(button, list, input , outs)
if button ~= 1 then return end
end
},
{
title = menu.color..">{ffffff} Использовать список как:\t"..(config.data.list_block and "Черный список" or "Белый список"),
click = function(button, list, input , outs)
if button ~= 1 then return end
config.data.list_block = not config.data.list_block
config.save(config.data)
menu.show = { true, "main" }
end
}
}
},
["edit"] = {
settings = {title = "mafia-tools" ,style = 1 ,btn1 = "Выбрать" ,btn2 = "Назад" ,forward = "{ffffff}" ,backwards = "\n" ,score = true},
{
text = "",
{
click = function(button, list, input, outs)
menu.show[3](button, list, input, outs)
end
}
}
},
["members"] = {
settings = {title = "mafia-tools" ,style = 4 ,btn1 = "Выбрать" ,btn2 = "Назад" ,forward = "{ffffff}" ,backwards = "\n" ,score = true},
members
},
["members_user"] = {
settings = {title = "mafia-tools" ,style = 2 ,btn1 = "Выбрать" ,btn2 = "Назад" ,forward = "{ffffff}" ,backwards = "\n" ,score = true},
menu.show[3]
}
}
end
menu.show = { false, "main" }
menu.put = ""
menu.loop = function()
sampRegisterChatCommand('maf', function(param)
menu.show = { true, "main" }
end)
while true do
wait(0)
if menu.show[1] then
menu.show[1] = false
menu.update()
if menu.dialog[menu.show[2]] ~= nil then
start_dialog(menu.dialog[menu.show[2]], menu.show[4])
end
end
end
end
-->> MSK TIME
msk_time = {}
msk_time.update = 0
@ -77,12 +264,15 @@ request.handler = function(text)
msk_time.time = info["time"]
end
if info["result"] == "ok" then
menu.data = info["data"]
for sender, sender_data in pairs(info["data"]) do
for key, v in pairs(sender_data) do
if ammo_timer.data[key] ~= nil then
if ammo_timer.data[key]["time"] < v["time"] then
ammo_timer.data[key]["time"] = v["time"]
ammo_timer.data[key]["text"] = v["text"]
if config.data.list[sender] == nil then
for key, v in pairs(sender_data) do
if ammo_timer.data[key] ~= nil then
if ammo_timer.data[key]["time"] < v["time"] then
ammo_timer.data[key]["time"] = v["time"]
ammo_timer.data[key]["text"] = v["text"]
end
end
end
end
@ -104,7 +294,7 @@ ammo_timer.onServerMessage = function(color, message)
request.wait = 0
end
end
if message:find("Задание будет доступно через: ") then
if message:find("^ Задание будет доступно через: ") then
local p1, p2, p3 = string.match(message, "Задание будет доступно через: (%d+):(%d+):(%d+)")
if(p3 == nil)then
p1, p2 = string.match(message, "Задание будет доступно через: (%d+):(%d+)")
@ -212,7 +402,9 @@ config.default = {
y = y1
},
time_2min = 0,
room = "all"
room = "all",
list = {}, -->> Список
list_block = true, -->> Использовать как Черный или Белый список
}
config.directory = string.format("%s\\moonloader\\config\\%s\\", getGameDirectory(), thisScript().name)
config.init = function()
@ -318,6 +510,57 @@ function convertTableToString(table)
end
return result
end
function start_dialog(menu, put) -- module by trefa & modify (put & list in [])
function _dialog(menu, id, outs, put)
sampShowDialog(id, menu.settings.title, tbl_split(menu.settings.style, menu, menu.settings.forward ,menu.settings.backwards ,menu.settings.score), menu.settings.btn1, (menu.settings.btn2 ~= nil and menu.settings.btn2 or _), menu.settings.style)
repeat
wait(0)
if put ~= nil and sampIsDialogActive() then
sampSetCurrentDialogEditboxText(put)
put = nil
end
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, put)
elseif type(out) == "boolean" then
if not out then
return out
end
return _dialog(menu, id, outs, put)
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 "["..(i-1).."] " or "")..""..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, put)
end
function getNicknamesOnline()
local result = {}
for i = 0, sampGetMaxPlayerId(false) do
if sampIsPlayerConnected(i) or select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)) == i then
result[sampGetPlayerNickname(i)] = i
end
end
return result
end
-->> UPDATE MODULE
function openURL(url, fpath, message_off)

Loading…
Cancel
Save