From 658862e7aca3ca21e2c96d5e1b6d96077983d798 Mon Sep 17 00:00:00 2001 From: m3ntor Date: Sat, 9 Nov 2024 09:44:19 +0100 Subject: [PATCH 1/2] update(src): Added player side menu --- plugins/tags/globals.lua | 6 ++ plugins/tags/modules/commands.lua | 64 ++++++++++++- plugins/tags/modules/menus.lua | 75 +++++++++++++++ plugins/tags/modules/pluginsloader.lua | 7 +- plugins/tags/modules/tagsloader.lua | 128 +++++++++++++++++++++++-- plugins/tags/utils.lua | 12 +++ translations/translation.tags.json | 27 ++++++ 7 files changed, 306 insertions(+), 13 deletions(-) create mode 100644 plugins/tags/modules/menus.lua diff --git a/plugins/tags/globals.lua b/plugins/tags/globals.lua index 74e9576..04ea79f 100644 --- a/plugins/tags/globals.lua +++ b/plugins/tags/globals.lua @@ -1,3 +1,9 @@ Plugins = {} Tags = {} TagsIndexMap = {} + + +TagsMode_t = { + AUTO = 0, + MANUAL = 1 +} \ No newline at end of file diff --git a/plugins/tags/modules/commands.lua b/plugins/tags/modules/commands.lua index 0de9602..de55510 100644 --- a/plugins/tags/modules/commands.lua +++ b/plugins/tags/modules/commands.lua @@ -143,6 +143,57 @@ local consoleCommands = { end } +local playerCommands = { + show = function(playerid, args, argc, silent) + return GenerateTagsMenu(playerid) + end, + toggle = function(playerid, args, argc, silent) + + local player = GetPlayer(playerid) + if not player or not player:IsValid() then return end + + if argc < 2 then return GenerateTagsMenu(playerid) end + + local option = args[2] + + switch(option, { + ["enable"] = function() + local value = exports["cookies"]:GetPlayerCookie(playerid, "tags.enable") + exports["cookies"]:SetPlayerCookie(playerid, "tags.enable", not value) + end, + ["mode"] = function() + local value = exports["cookies"]:GetPlayerCookie(playerid, "tags.mode") + switch(value, { + [TagsMode_t.AUTO] = function() exports["cookies"]:SetPlayerCookie(playerid, "tags.mode", TagsMode_t.MANUAL) end, + [TagsMode_t.MANUAL] = function() exports["cookies"]:SetPlayerCookie(playerid, "tags.mode", TagsMode_t.AUTO) end + }) + end + }) + SetupTag(playerid) + return GenerateTagsMenu(playerid) + + end, + list = function(playerid, args, argc, silent) + return GenerateTagsListMenu(playerid) + end, + set = function(playerid, args, argc, silent) + if argc < 2 then + return GenerateTagsMenu(playerid) + end + + local identifier = args[2] + + if not identifier or not TagsIndexMap[identifier] then + return GenerateTagsMenu(playerid) + end + + exports["cookies"]:SetPlayerCookie(playerid,"tags.selected", identifier) + SetupTag(playerid) + return GenerateTagsMenu(playerid) + + end +} + commands:Register("tags", function(playerid, args, argc, silent, prefix) if playerid < 0 then @@ -157,7 +208,16 @@ commands:Register("tags", function(playerid, args, argc, silent, prefix) end return consoleCommands[option](playerid, args, argc, silent) + else + if argc < 1 then + return playerCommands["show"](playerid, args, argc, silent) + end + local option = args[1] + + if not playerCommands[option] then + return playerCommands["show"](playerid, args, argc, silent) + end + + return playerCommands[option](playerid, args, argc, silent) end - -- TODO: Player menu style - return end) diff --git a/plugins/tags/modules/menus.lua b/plugins/tags/modules/menus.lua new file mode 100644 index 0000000..80e748a --- /dev/null +++ b/plugins/tags/modules/menus.lua @@ -0,0 +1,75 @@ +GenerateTagsMenu = function(playerid) + local player = GetPlayer(playerid) + if not player or not player:IsValid() then return end + + local options = {} + + local cookieEnabled = exports["cookies"]:GetPlayerCookie(playerid, "tags.enable") or false + + switch(cookieEnabled, { + + [true] = function() + table.insert(options, {FetchTranslation("tags.menu.option.enable", playerid) .. ": ".. FetchTranslation("tags.menu.option.on", playerid), "sw_tags toggle enable"}) + + local cookieMode = exports["cookies"]:GetPlayerCookie(playerid, "tags.mode") + + switch(cookieMode, { + [TagsMode_t.AUTO] = function() table.insert(options, {FetchTranslation("tags.menu.option.mode", playerid) .. ": ".. FetchTranslation("tags.menu.option.mode.auto", playerid), "sw_tags toggle mode"}) end, + [TagsMode_t.MANUAL] = function() + table.insert(options, {FetchTranslation("tags.menu.option.mode", playerid) .. ": ".. FetchTranslation("tags.menu.option.mode.manual", playerid), "sw_tags toggle mode"}) + local cookieSelected = exports["cookies"]:GetPlayerCookie(playerid, "tags.selected") + + if cookieSelected == "auto" then + local lastTag = DetermineLastTag(playerid) + if not lastTag then + table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": NONE", "sw_tags list"}) + return + end + table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": ".. lastTag.tag .. "", "sw_tags list"}) + else + if not TagsIndexMap[cookieSelected] then + table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": NONE", "sw_tags list"}) + return + end + local tag = Tags[TagsIndexMap[cookieSelected]] + table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": ".. tag.tag .. "", "sw_tags list"}) + end + end + }) + + end, + [false] = function() + table.insert(options, {FetchTranslation("tags.menu.option.enable", playerid) .. ": ".. FetchTranslation("tags.menu.option.off", playerid), "sw_tags toggle enable"}) + end, + }) + + + if #options < 1 then return end + + local menuId = "tags_".. os.clock() + + menus:RegisterTemporary(menuId, tostring(FetchTranslation("tags.menu.title", playerid) or "Tags Menu"), tostring(config:Fetch("tags.menu.color") or "0000FF"), options) + player:HideMenu() + player:ShowMenu(menuId) + +end + + +GenerateTagsListMenu = function(playerid) + local player = GetPlayer(playerid) + if not player or not player:IsValid() then return end + local tags = DetermineTags(playerid) + if not tags then return GenerateTagsMenu(playerid) end + + local options = {} + + for _, tag in next, tags do + table.insert(options, {"".. tag.tag .. "", "sw_tags set " .. tag.identifier}) + end + if #options < 1 then return GenerateTagsMenu(playerid) end + + local menuId = "tags_list_".. os.clock() + menus:RegisterTemporary(menuId, tostring(FetchTranslation("tags.menu.option.tag.list", playerid) or "Tags List Menu"), tostring(config:Fetch("tags.menu.color") or "0000FF"), options) + player:HideMenu() + player:ShowMenu(menuId) +end \ No newline at end of file diff --git a/plugins/tags/modules/pluginsloader.lua b/plugins/tags/modules/pluginsloader.lua index fc561ca..d7c5e0c 100644 --- a/plugins/tags/modules/pluginsloader.lua +++ b/plugins/tags/modules/pluginsloader.lua @@ -1,10 +1,15 @@ AddEventHandler("OnAllPluginsLoaded", function (event) - local supportedPlugins = {"vipcore","admins"} + local supportedPlugins = {"vipcore","admins","cookies"} for i = 1, #supportedPlugins, 1 do local pluginName = supportedPlugins[i] if GetPluginState(pluginName) == PluginState_t.Started then Plugins[pluginName] = true + if pluginName == "cookies" then + exports["cookies"]:RegisterCookie("tags.enable", true) + exports["cookies"]:RegisterCookie("tags.mode", TagsMode_t.AUTO ) + exports["cookies"]:RegisterCookie("tags.selected", "auto" ) + end print("Plugin found: {green}" .. pluginName.."{default}") end end diff --git a/plugins/tags/modules/tagsloader.lua b/plugins/tags/modules/tagsloader.lua index 08c6a73..c21054f 100644 --- a/plugins/tags/modules/tagsloader.lua +++ b/plugins/tags/modules/tagsloader.lua @@ -72,14 +72,8 @@ function ReloadTags() end -function SetupTag(playerid) - if #Tags == 0 then return end - local player = GetPlayer(playerid) - if not player then return end - - local tag = DetermineTag(playerid) +function SetPlayerTag(player, tag) if not tag then return end - player:SetChatTag(tag.tag) player:SetChatTagColor(PrepareColor(tag.color)) player:SetNameColor(PrepareColor(tag.name_color)) @@ -90,10 +84,40 @@ function SetupTag(playerid) else player:CCSPlayerController().Clan = "" end - RefreshScoreboard(playerid) + + RefreshScoreboard(player:GetSlot()) +end + +function SetupTag(playerid) + if #Tags == 0 then return end + local player = GetPlayer(playerid) + if not player then return end + + ClearTag(playerid) + + local cookieEnabled = exports["cookies"]:GetPlayerCookie(playerid, "tags.enable") or false + + if not cookieEnabled then return end + + local cookieMode = exports["cookies"]:GetPlayerCookie(playerid, "tags.mode") + + if cookieMode == TagsMode_t.AUTO then + local tag = DetermineLastTag(playerid) + SetPlayerTag(player, tag) + elseif cookieMode == TagsMode_t.MANUAL then + local cookieSelected = exports["cookies"]:GetPlayerCookie(playerid, "tags.selected") + + if cookieSelected == "auto" then + local tag = DetermineLastTag(playerid) + SetPlayerTag(player, tag) + else + local tag = Tags[TagsIndexMap[cookieSelected]] + SetPlayerTag(player, tag) + end + end end -function DetermineTag(playerid) +function DetermineLastTag(playerid) local lastTag = nil local player = GetPlayer(playerid) if not player or not player:IsValid() or not player:CBaseEntity():IsValid() then return nil end @@ -169,7 +193,7 @@ function DetermineTag(playerid) } } - for i, cond in ipairs(conditions) do + for i, cond in next, conditions do local conditionResult, tag = cond.condition() if conditionResult then if tag then @@ -182,6 +206,90 @@ function DetermineTag(playerid) end +function DetermineTags(playerid) + local listTags = {} + local player = GetPlayer(playerid) + if not player or not player:IsValid() or not player:CBaseEntity():IsValid() then return nil end + + local teamID = player:CBaseEntity().TeamNum + local steamID = player:GetSteamID() + + local conditions = { + + -- identifier: everyone + { condition = function() return TagsIndexMap["everyone"], Tags[TagsIndexMap["everyone"]] end }, + + -- identifier: team:tt + { condition = function() return TagsIndexMap["team:tt"] and teamID == Team.T, Tags[TagsIndexMap["team:tt"]] end }, + + -- identifier: team:ct + { condition = function() return TagsIndexMap["team:ct"] and teamID == Team.CT, Tags[TagsIndexMap["team:ct"]] end }, + + -- identifier: team:spec + { condition = function() return TagsIndexMap["team:spec"] and teamID == Team.Spectator, Tags[TagsIndexMap["team:spec"]] end }, + + -- identifier: steamid:(steamid64) + { condition = function() return steamID and TagsIndexMap["steamid:" .. steamID], Tags[TagsIndexMap["steamid:" .. steamID]] end }, + + -- identifier: vip:(group_name) + { + condition = function() + if Plugins["vipcore"] then + local vipGroup = player:GetVar("vip.group") or "none" + if vipGroup ~= nil and vipGroup ~= "none" then + local index = TagsIndexMap["vip:" .. vipGroup] + if index then + return true, Tags[index] + end + end + end + return false, nil + end + }, + + -- identifier: admins:flags:(flags_string) or admins:group:(group_name) + { + condition = function() + if Plugins["admins"] then + local adminFlags = player:GetVar("admin.flags") or 0 + local adminGroup = exports["admins"]:GetAdminGroup(playerid) or "none" + + -- Dodajemy tagi dla grupy admina + if adminGroup ~= "none" then + for key, index in pairs(TagsIndexMap) do + local group, groupCount = string.gsub(key, "admin:group:", "", 1) + if groupCount ~= 0 and group == adminGroup then + table.insert(listTags, Tags[index]) -- Dodajemy tag grupy admina + end + end + end + + -- Dodajemy tagi dla flag admina + if adminFlags ~= 0 then + for key, index in pairs(TagsIndexMap) do + local flags, flagsCount = string.gsub(key, "admin:flags:", "", 1) + if flagsCount ~= 0 and exports["admins"]:HasFlags(playerid, flags) then + table.insert(listTags, Tags[index]) -- Dodajemy tag flagi admina + end + end + end + end + return false, nil -- W tej sekcji nie zwracamy tagu, ponieważ wszystkie tagi już zostały dodane do listy + end + } + } + + for i, cond in next, conditions do + local conditionResult, tag = cond.condition() + if conditionResult and tag then + table.insert(listTags, tag) + end + end + + return listTags +end + + AddEventHandler("OnPlayerConnectFull", function (event) local playerid = event:GetInt("userid") local player = GetPlayer(playerid) diff --git a/plugins/tags/utils.lua b/plugins/tags/utils.lua index ddef666..73e717a 100644 --- a/plugins/tags/utils.lua +++ b/plugins/tags/utils.lua @@ -20,3 +20,15 @@ function RefreshScoreboard(playerid) local event = Event("OnNextlevelChanged") event:FireEventToClient(playerid) end + + +function ClearTag(playerid) + local player = GetPlayer(playerid) + if not player or not player:IsValid() then return end + player:SetChatTag("") + player:SetChatTagColor("{teamcolor}") + player:SetNameColor("{teamcolor}") + player:SetChatColor("{default}") + player:CCSPlayerController().Clan = "" + RefreshScoreboard(playerid) +end diff --git a/translations/translation.tags.json b/translations/translation.tags.json index 8b9284a..78845e9 100644 --- a/translations/translation.tags.json +++ b/translations/translation.tags.json @@ -22,5 +22,32 @@ }, "not_exists": { "en": "A tag with the identifier {green}{ID}{default} does not exist." + }, + "menu.title": { + "en": "Tags Menu" + }, + "menu.option.enable": { + "en": "Enable" + }, + "menu.option.on": { + "en": "" + }, + "menu.option.off": { + "en": "" + }, + "menu.option.mode": { + "en": "Mode" + }, + "menu.option.mode.auto": { + "en": "AUTO" + }, + "menu.option.mode.manual": { + "en": "MANUAL" + }, + "menu.option.tag": { + "en": "Tag" + }, + "menu.option.tag.list": { + "en": "Tag List" } } \ No newline at end of file From 106cd05e8321d02d41886da678bbcd8ee98f089a Mon Sep 17 00:00:00 2001 From: m3ntor Date: Sat, 9 Nov 2024 20:39:33 +0100 Subject: [PATCH 2/2] update(src): Some bug fixed on conditions --- README.md | 12 +- plugins/tags/modules/menus.lua | 53 ++++++++- plugins/tags/modules/tagsloader.lua | 177 +++++++++++----------------- 3 files changed, 125 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index bb67732..d3828fa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- + SwiftlyLogo @@ -19,6 +19,8 @@

+## Requirements 🛠️ +- [Cookies](https://github.com/swiftly-solution/cookies/releases) ## Installation 👀 1. Download the newest [release](https://github.com/m3ntorsky/tags/releases) @@ -57,6 +59,14 @@ - Reloads the tags configuration from the database. +### Tags Menu Commands 💬 + +* Base commands provided by this plugin: + +| Command | Description | +|:----------------:|:--------------------------------------:| +| !tags | Tags Chat Manager. | + ### Creating A Pull Request 😃 1. Fork the Project diff --git a/plugins/tags/modules/menus.lua b/plugins/tags/modules/menus.lua index 80e748a..5d687d1 100644 --- a/plugins/tags/modules/menus.lua +++ b/plugins/tags/modules/menus.lua @@ -1,6 +1,6 @@ GenerateTagsMenu = function(playerid) local player = GetPlayer(playerid) - if not player or not player:IsValid() then return end + if not player or not player:IsValid() or not player:CBaseEntity():IsValid() then return end local options = {} @@ -20,7 +20,7 @@ GenerateTagsMenu = function(playerid) local cookieSelected = exports["cookies"]:GetPlayerCookie(playerid, "tags.selected") if cookieSelected == "auto" then - local lastTag = DetermineLastTag(playerid) + local lastTag = DetermineLastTag(player) if not lastTag then table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": NONE", "sw_tags list"}) return @@ -32,7 +32,28 @@ GenerateTagsMenu = function(playerid) return end local tag = Tags[TagsIndexMap[cookieSelected]] - table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": ".. tag.tag .. "", "sw_tags list"}) + local item = switch(tag.color, { + teamcolor = function() + return switch(player:CBaseEntity().TeamNum, { + [Team.CT] = function () + return "".. tag.tag .. "" + end, + [Team.T] = function () + return "".. tag.tag .. "" + end, + [Team.Spectator] = function () + return "".. tag.tag .. "" + end, + [Team.None] = function () + return "".. tag.tag .. "" + end + }) + end, + default = function () + return "".. tag.tag .. "" + end + }) + table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": ".. item, "sw_tags list"}) end end }) @@ -58,13 +79,33 @@ end GenerateTagsListMenu = function(playerid) local player = GetPlayer(playerid) if not player or not player:IsValid() then return end - local tags = DetermineTags(playerid) + local tags = DetermineTags(player) if not tags then return GenerateTagsMenu(playerid) end - local options = {} for _, tag in next, tags do - table.insert(options, {"".. tag.tag .. "", "sw_tags set " .. tag.identifier}) + + switch(tag.color, { + teamcolor = function() + switch(player:CBaseEntity().TeamNum, { + [Team.CT] = function() + table.insert(options, {"".. tag.tag .. "", "sw_tags set " .. tag.identifier}) + end, + [Team.T] = function() + table.insert(options, {"".. tag.tag .. "", "sw_tags set " .. tag.identifier}) + end, + [Team.Spectator] = function() + table.insert(options, {"".. tag.tag .. "", "sw_tags set " .. tag.identifier}) + end, + [Team.None] = function() + table.insert(options, {"".. tag.tag .. "", "sw_tags set " .. tag.identifier}) + end + }) + end, + default = function() + table.insert(options, {"".. tag.tag .. "", "sw_tags set " .. tag.identifier}) + end + }) end if #options < 1 then return GenerateTagsMenu(playerid) end diff --git a/plugins/tags/modules/tagsloader.lua b/plugins/tags/modules/tagsloader.lua index c21054f..0187aff 100644 --- a/plugins/tags/modules/tagsloader.lua +++ b/plugins/tags/modules/tagsloader.lua @@ -102,7 +102,7 @@ function SetupTag(playerid) local cookieMode = exports["cookies"]:GetPlayerCookie(playerid, "tags.mode") if cookieMode == TagsMode_t.AUTO then - local tag = DetermineLastTag(playerid) + local tag = DetermineLastTag(player) SetPlayerTag(player, tag) elseif cookieMode == TagsMode_t.MANUAL then local cookieSelected = exports["cookies"]:GetPlayerCookie(playerid, "tags.selected") @@ -117,37 +117,44 @@ function SetupTag(playerid) end end -function DetermineLastTag(playerid) - local lastTag = nil - local player = GetPlayer(playerid) - if not player or not player:IsValid() or not player:CBaseEntity():IsValid() then return nil end - +local function GetPlayerTags(player) + local tags = {} local teamID = player:CBaseEntity().TeamNum local steamID = player:GetSteamID() local conditions = { -- identifier: everyone - { condition = function() return TagsIndexMap["everyone"], Tags[TagsIndexMap["everyone"]] end }, + { condition = function() + return TagsIndexMap["everyone"], Tags[TagsIndexMap["everyone"]] + end }, -- identifier: team:tt - { condition = function() return TagsIndexMap["team:tt"] and teamID == Team.T, Tags[TagsIndexMap["team:tt"]] end }, + { condition = function() + return TagsIndexMap["team:tt"] and teamID == Team.T, Tags[TagsIndexMap["team:tt"]] + end }, -- identifier: team:ct - { condition = function() return TagsIndexMap["team:ct"] and teamID == Team.CT, Tags[TagsIndexMap["team:ct"]] end }, + { condition = function() + return TagsIndexMap["team:ct"] and teamID == Team.CT, Tags[TagsIndexMap["team:ct"]] + end }, -- identifier: team:spec - { condition = function() return TagsIndexMap["team:spec"] and teamID == Team.Spectator, Tags[TagsIndexMap["team:spec"]] end }, + { condition = function() + return TagsIndexMap["team:spec"] and teamID == Team.Spectator, Tags[TagsIndexMap["team:spec"]] + end }, -- identifier: steamid:(steamid64) - { condition = function() return steamID and TagsIndexMap["steamid:" .. steamID], Tags[TagsIndexMap["steamid:" .. steamID]] end }, + { condition = function() + return steamID and TagsIndexMap["steamid:" .. steamID], Tags[TagsIndexMap["steamid:" .. steamID]] + end }, -- identifier: vip:(group_name) { condition = function() if Plugins["vipcore"] then local vipGroup = player:GetVar("vip.group") or "none" - if vipGroup ~= nil and vipGroup ~= "none" then + if vipGroup ~= "none" then local index = TagsIndexMap["vip:" .. vipGroup] if index then return true, Tags[index] @@ -158,88 +165,31 @@ function DetermineLastTag(playerid) end }, - -- identifier: admins:flags:(flags_string) or admins:group:(group_name) + -- identifier: admins:flags:(flags_string) { condition = function() if Plugins["admins"] then - local adminFlags = player:GetVar("admin.flags") or 0 - local adminGroup = exports["admins"]:GetAdminGroup(playerid) or "none" - local latestAdminTag = nil - - if adminGroup ~= "none" then - for key, index in pairs(TagsIndexMap) do - local group, groupCount = string.gsub(key, "admin:group:", "", 1) - if groupCount ~= 0 and group == adminGroup then - latestAdminTag = Tags[index] - return true, latestAdminTag - end - end - end - - + local adminFlags = player:GetVar("admin.flags") or 0 if adminFlags ~= 0 then - for key, index in pairs(TagsIndexMap) do - local flags, flagsCount = string.gsub(key, "admin:flags:", "", 1) - if flagsCount ~= 0 and exports["admins"]:HasFlags(playerid, flags) then - latestAdminTag = Tags[index] - return true, latestAdminTag + local adminTags = {} + for key, _ in next, TagsIndexMap do + local flags, flagsCount = key:gsub("admin:flags:", "", 1) + if flagsCount ~= 0 and exports["admins"]:HasFlags(player:GetSlot(), flags) then + -- Dodajemy tag tylko, jeśli jeszcze go nie mamy + if not table.contains(adminTags, key) then + table.insert(adminTags, key) + end end end - end - return false, nil - end - return false, nil - end - } - } - - for i, cond in next, conditions do - local conditionResult, tag = cond.condition() - if conditionResult then - if tag then - lastTag = tag - end - end - end - - return lastTag -end - - -function DetermineTags(playerid) - local listTags = {} - local player = GetPlayer(playerid) - if not player or not player:IsValid() or not player:CBaseEntity():IsValid() then return nil end - - local teamID = player:CBaseEntity().TeamNum - local steamID = player:GetSteamID() - - local conditions = { - - -- identifier: everyone - { condition = function() return TagsIndexMap["everyone"], Tags[TagsIndexMap["everyone"]] end }, - - -- identifier: team:tt - { condition = function() return TagsIndexMap["team:tt"] and teamID == Team.T, Tags[TagsIndexMap["team:tt"]] end }, - - -- identifier: team:ct - { condition = function() return TagsIndexMap["team:ct"] and teamID == Team.CT, Tags[TagsIndexMap["team:ct"]] end }, - - -- identifier: team:spec - { condition = function() return TagsIndexMap["team:spec"] and teamID == Team.Spectator, Tags[TagsIndexMap["team:spec"]] end }, - - -- identifier: steamid:(steamid64) - { condition = function() return steamID and TagsIndexMap["steamid:" .. steamID], Tags[TagsIndexMap["steamid:" .. steamID]] end }, - - -- identifier: vip:(group_name) - { - condition = function() - if Plugins["vipcore"] then - local vipGroup = player:GetVar("vip.group") or "none" - if vipGroup ~= nil and vipGroup ~= "none" then - local index = TagsIndexMap["vip:" .. vipGroup] - if index then - return true, Tags[index] + if #adminTags > 0 then + table.sort(adminTags) + for _, tagKey in ipairs(adminTags) do + local index = TagsIndexMap[tagKey] + -- Dodajemy tag tylko, jeśli jeszcze go nie mamy + if not table.contains(tags, Tags[index]) then + table.insert(tags, Tags[index]) + end + end end end end @@ -247,48 +197,55 @@ function DetermineTags(playerid) end }, - -- identifier: admins:flags:(flags_string) or admins:group:(group_name) + -- identifier: admins:groups:(group_name) { condition = function() if Plugins["admins"] then - local adminFlags = player:GetVar("admin.flags") or 0 - local adminGroup = exports["admins"]:GetAdminGroup(playerid) or "none" - - -- Dodajemy tagi dla grupy admina + local adminGroup = exports["admins"]:GetAdminGroup(player:GetSlot()) or "none" if adminGroup ~= "none" then - for key, index in pairs(TagsIndexMap) do - local group, groupCount = string.gsub(key, "admin:group:", "", 1) + for key, index in next, TagsIndexMap do + local group, groupCount = key:gsub("admin:group:", "", 1) if groupCount ~= 0 and group == adminGroup then - table.insert(listTags, Tags[index]) -- Dodajemy tag grupy admina - end - end - end - - -- Dodajemy tagi dla flag admina - if adminFlags ~= 0 then - for key, index in pairs(TagsIndexMap) do - local flags, flagsCount = string.gsub(key, "admin:flags:", "", 1) - if flagsCount ~= 0 and exports["admins"]:HasFlags(playerid, flags) then - table.insert(listTags, Tags[index]) -- Dodajemy tag flagi admina + -- Dodajemy tag tylko, jeśli jeszcze go nie mamy + if not table.contains(tags, Tags[index]) then + table.insert(tags, Tags[index]) + end + return true, Tags[index] end end end end - return false, nil -- W tej sekcji nie zwracamy tagu, ponieważ wszystkie tagi już zostały dodane do listy + return false, nil end } } - for i, cond in next, conditions do + -- Przejście przez warunki i dodanie wszystkich pasujących tagów + for _, cond in next, conditions do local conditionResult, tag = cond.condition() if conditionResult and tag then - table.insert(listTags, tag) + -- Dodajemy tag tylko, jeśli jeszcze go nie mamy + if not table.contains(tags, tag) then + table.insert(tags, tag) + end end end - return listTags + return tags end +function DetermineTags(player) + if not player or not player:IsValid() or not player:CBaseEntity():IsValid() then + return nil + end + + return GetPlayerTags(player) +end + +function DetermineLastTag(player) + local tags = DetermineTags(player) + return #tags > 0 and tags[#tags] or nil +end AddEventHandler("OnPlayerConnectFull", function (event) local playerid = event:GetInt("userid")