Skip to content

Commit

Permalink
Merge pull request #1 from swiftly-solution/feature/player-menu
Browse files Browse the repository at this point in the history
feature/player menu
  • Loading branch information
m3ntorsky authored Nov 9, 2024
2 parents ca5a881 + 106cd05 commit 21e7e59
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 45 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>

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions plugins/tags/globals.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Plugins = {}
Tags = {}
TagsIndexMap = {}


TagsMode_t = {
AUTO = 0,
MANUAL = 1
}
64 changes: 62 additions & 2 deletions plugins/tags/modules/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
116 changes: 116 additions & 0 deletions plugins/tags/modules/menus.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
GenerateTagsMenu = function(playerid)
local player = GetPlayer(playerid)
if not player or not player:IsValid() or not player:CBaseEntity():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(player)
if not lastTag then
table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": <font color='white'>NONE</font>", "sw_tags list"})
return
end
table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": <font color='".. lastTag.color .."'>".. lastTag.tag .. "</font>", "sw_tags list"})
else
if not TagsIndexMap[cookieSelected] then
table.insert(options, {FetchTranslation("tags.menu.option.tag", playerid) .. ": <font color='white'>NONE</font>", "sw_tags list"})
return
end
local tag = Tags[TagsIndexMap[cookieSelected]]
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
})

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(player)
if not tags then return GenerateTagsMenu(playerid) end
local options = {}

for _, tag in next, tags do

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

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
7 changes: 6 additions & 1 deletion plugins/tags/modules/pluginsloader.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit 21e7e59

Please sign in to comment.