Skip to content

Commit

Permalink
update(src): Some bug fixed on conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
m3ntorsky committed Nov 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 658862e commit 106cd05
Showing 3 changed files with 125 additions and 117 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<a href="https://github.com/swiftly-solution/weapon_restrictor">
<a href="https://github.com/swiftly-solution/swiftly">
<img src="https://cdn.swiftlycs2.net/swiftly-logo.png" alt="SwiftlyLogo" width="80" height="80">
</a>

@@ -19,6 +19,8 @@
</p>


## 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
53 changes: 47 additions & 6 deletions plugins/tags/modules/menus.lua
Original file line number Diff line number Diff line change
@@ -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) .. ": <font color='white'>NONE</font>", "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) .. ": <font color='".. tag.color .."'>".. tag.tag .. "</font>", "sw_tags list"})
local item = switch(tag.color, {
teamcolor = function()
return switch(player:CBaseEntity().TeamNum, {
[Team.CT] = function ()
return "<font color='blue'>".. tag.tag .. "</font>"
end,
[Team.T] = function ()
return "<font color='yellow'>".. tag.tag .. "</font>"
end,
[Team.Spectator] = function ()
return "<font color='white'>".. tag.tag .. "</font>"
end,
[Team.None] = function ()
return "<font color='white'>".. tag.tag .. "</font>"
end
})
end,
default = function ()
return "<font color='".. tag.color .."'>".. tag.tag .. "</font>"
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, {"<font color='".. tag.color .."'>".. tag.tag .. "</font>", "sw_tags set " .. tag.identifier})

switch(tag.color, {
teamcolor = function()
switch(player:CBaseEntity().TeamNum, {
[Team.CT] = function()
table.insert(options, {"<font color='blue'>".. tag.tag .. "</font>", "sw_tags set " .. tag.identifier})
end,
[Team.T] = function()
table.insert(options, {"<font color='yellow'>".. tag.tag .. "</font>", "sw_tags set " .. tag.identifier})
end,
[Team.Spectator] = function()
table.insert(options, {"<font color='white'>".. tag.tag .. "</font>", "sw_tags set " .. tag.identifier})
end,
[Team.None] = function()
table.insert(options, {"<font color='white'>".. tag.tag .. "</font>", "sw_tags set " .. tag.identifier})
end
})
end,
default = function()
table.insert(options, {"<font color='".. tag.color .."'>".. tag.tag .. "</font>", "sw_tags set " .. tag.identifier})
end
})
end
if #options < 1 then return GenerateTagsMenu(playerid) end

177 changes: 67 additions & 110 deletions plugins/tags/modules/tagsloader.lua
Original file line number Diff line number Diff line change
@@ -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,137 +165,87 @@ 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
return false, nil
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")

0 comments on commit 106cd05

Please sign in to comment.