Skip to content

Commit 17fe162

Browse files
committed
init(project): First commit.
0 parents  commit 17fe162

File tree

9 files changed

+308
-0
lines changed

9 files changed

+308
-0
lines changed

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<p align="center">
2+
<a href="https://github.com/swiftly-solution/map-chooser">
3+
<img src="https://cdn.swiftlycs2.net/swiftly-logo.png" alt="SwiftlyLogo" width="80" height="80">
4+
</a>
5+
6+
<h3 align="center">[Swiftly] Map Chooser</h3>
7+
8+
<p align="center">
9+
A simple plugin for Swiftly that implements a basic map voting system.
10+
<br/>
11+
</p>
12+
</p>
13+
14+
<p align="center">
15+
<img src="https://img.shields.io/github/downloads/swiftly-solution/map-chooser/total" alt="Downloads">
16+
<img src="https://img.shields.io/github/contributors/swiftly-solution/map-chooser?color=dark-green" alt="Contributors">
17+
<img src="https://img.shields.io/github/issues/swiftly-solution/map-chooser" alt="Issues">
18+
<img src="https://img.shields.io/github/license/swiftly-solution/map-chooser" alt="License">
19+
</p>
20+
21+
---
22+
23+
### Installation 👀
24+
25+
1. Download the newest [release](https://github.com/swiftly-solution/map-chooser/releases).
26+
2. Everything is drag & drop, so i think you can do it!
27+
28+
29+
### Configuring the plugin 🧐
30+
31+
- After installing the plugin, you should change the default prefix from `addons/swiftly/configs/plugins/map-chooser.json`(optional)
32+
- You can change the rounds left to vote and the maps from the config: `addons/swiftly/configs/plugins/map-chooser.json`
33+
34+
### Creating A Pull Request 😃
35+
36+
1. Fork the Project
37+
2. Create your Feature Branch
38+
3. Commit your Changes
39+
4. Push to the Branch
40+
5. Open a Pull Request
41+
42+
### Have ideas/Found bugs? 💡
43+
44+
Join [Swiftly Discord Server](https://swiftlycs2.net/discord) and send a message in the topic from `📕╎plugins-sharing` of this plugin!
45+
46+
---

configs/map-chooser.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"prefix": "[{LIME}SWIFTLY{DEFAULT}]",
3+
"maplist": {
4+
"de_dust2": "Dust II",
5+
"de_mirage": "Mirage",
6+
"de_train": "Train",
7+
"de_nuke": "Nuke",
8+
"de_overpass": "Overpass"
9+
},
10+
"VoteAfterRound": 7,
11+
"color": "00b869"
12+
}

plugins/map-chooser/commands.lua

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
commands:Register("vote", function (playerid, args, argsCount, silent, prefix)
2+
local player = GetPlayer(playerid)
3+
if not player or not player:IsValid() then return end
4+
5+
if not isvoteactive then
6+
return ReplyToCommand(playerid, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.cannotvote"))
7+
end
8+
9+
if player:GetVar("voted") ~= nil then
10+
return ReplyToCommand(playerid, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.alreadyvoted"))
11+
end
12+
13+
local option = args[1]
14+
local mplist = config:Fetch("map-chooser.maplist")
15+
16+
if not mplist or type(mplist) ~= "table" then
17+
print("Error: Map List is not valid")
18+
return
19+
end
20+
21+
if mplist[option] then
22+
if not mapVotes[option] then
23+
mapVotes[option] = 0
24+
end
25+
ReplyToCommand(playerid, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.voted"):gsub("{MAP}", mplist[option]))
26+
player:SetVar("voted", true)
27+
mapVotes[option] = mapVotes[option] + 1
28+
player:HideMenu()
29+
end
30+
end)
31+
32+
commands:Register("nextmap", function (playerid, args, argsCount, silent, prefix)
33+
local player = GetPlayer(playerid)
34+
if not player or not player:IsValid() then return end
35+
36+
player:SendMsg(MessageType.Console, "Next map: "..(nextMapName == "" and "None" or nextMapName))
37+
if playerid ~= -1 then
38+
ReplyToCommand(playerid, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.checkconsole"))
39+
end
40+
end)
41+
commands:RegisterRawAlias("nextmap", "nextmap")
42+
43+
commands:Register("rtv", function (playerid, args, argsCount, silent, prefix)
44+
local player = GetPlayer(playerid)
45+
if not player or not player:IsValid() then return end
46+
47+
if wasRTV then return ReplyToCommand(playerid, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.alreadyrtv")) end
48+
49+
rtvCount = rtvCount + 1
50+
local requiredPlayers = math.ceil(playermanager:GetPlayerCount() / 2)
51+
52+
if rtvCount >= requiredPlayers then
53+
StartPlayersVote()
54+
wasRTV = true
55+
else
56+
return ReplyToCommand(playerid, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.rtv"):gsub("{COUNT}", rtvCount):gsub("{REQUIRED}", requiredPlayers))
57+
end
58+
end)

plugins/map-chooser/core.lua

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function GetPluginAuthor()
2+
return "SwiftlyCS2 Development"
3+
end
4+
5+
function GetPluginVersion()
6+
return "1.0.0"
7+
end
8+
9+
function GetPluginName()
10+
return "Map Chooser"
11+
end
12+
13+
function GetPluginWebsite()
14+
return "https://github.com/swiftly-solution/map-chooser"
15+
end

plugins/map-chooser/functions.lua

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--- @param player Player
2+
function StartVote(player)
3+
isvoteactive = true
4+
player:ShowMenu("chooser_menu")
5+
for i = 1, playermanager:GetPlayerCap() do
6+
ReplyToCommand(i-1, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.votemap"))
7+
ReplyToCommand(i-1, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.votemap"))
8+
ReplyToCommand(i-1, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.votemap"))
9+
end
10+
11+
SetTimeout(10000, function ()
12+
player:HideMenu()
13+
end)
14+
end
15+
16+
function StopVote()
17+
isvoteactive = false
18+
19+
local mostvotes, totalVotes = GetMapWinner()
20+
21+
for i = 1, playermanager:GetPlayerCap() do
22+
local player = GetPlayer(i-1)
23+
if player and player:IsValid() then
24+
player:HideMenu()
25+
player:SetVar("voted", true)
26+
ReplyToCommand(i-1, config:Fetch("map-chooser.prefix"), FetchTranslation("map-chooser.mapwon"):gsub("{MAP_NAME}", nextMapName):gsub("{VOTES}", mostvotes):gsub("{PRECENTAGE}", (mostvotes * 100) / totalVotes))
27+
end
28+
end
29+
30+
if not wasVote then
31+
SetTimeout(15000, function ()
32+
if nextMapID == "" then return end
33+
server:ChangeMap(nextMapID, tostring(tonumber(nextMapID)) == nextMapID)
34+
end)
35+
end
36+
end
37+
38+
function GetMapWinner()
39+
local mplist = config:Fetch("map-chooser.maplist")
40+
if not mplist or type(mplist) ~= "table" then
41+
print("Error: maplist is not valid")
42+
return
43+
end
44+
45+
local mostvotes = 0
46+
local totalVotes = 0
47+
48+
for mapid, mapname in next,mplist,nil do
49+
local votes = mapVotes[mapid] or 0
50+
totalVotes = totalVotes + votes
51+
if votes > mostvotes then
52+
nextMapID = mapid
53+
nextMapName = mapname
54+
mostvotes = votes
55+
end
56+
end
57+
58+
if nextMapID == "" then
59+
nextMapID, nextMapName = next(mplist, nil)
60+
end
61+
62+
return mostvotes, totalVotes
63+
64+
end
65+
66+
function StartPlayersVote()
67+
rtvCount = 0
68+
69+
for i = 1, playermanager:GetPlayerCap() do
70+
local player = GetPlayer(i-1)
71+
if player and player:IsValid() then
72+
StartVote(player)
73+
end
74+
end
75+
76+
SetTimeout(10000, function ()
77+
StopVote()
78+
end)
79+
end

plugins/map-chooser/globals.lua

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mapVotes = {}
2+
isvoteactive = false
3+
4+
nextMapID = ""
5+
nextMapName = ""
6+
7+
rtvCount = 0
8+
wasRTV = false
9+
wasVote = false

plugins/map-chooser/main.lua

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
AddEventHandler("OnMapLoad", function (event)
2+
isvoteactive = false
3+
nextMapID = ""
4+
nextMapName = ""
5+
wasRTV = false
6+
wasVote = false
7+
return EventResult.Continue
8+
end)
9+
10+
AddEventHandler("OnPluginStart", function (event)
11+
RegisterMenus()
12+
return EventResult.Continue
13+
end)
14+
15+
AddEventHandler("OnRoundPrestart", function (event)
16+
local gamerules = GetCCSGameRules()
17+
if gamerules.TotalRoundsPlayed == config:Fetch("map-chooser.VoteAfterRound") then
18+
wasVote = true
19+
StartPlayersVote()
20+
end
21+
22+
return EventResult.Continue
23+
end)
24+
25+
AddEventHandler("OnCsWinPanelMatch", function(event)
26+
SetTimeout(2000, function ()
27+
if nextMapID == "" then return end
28+
server:ChangeMap(nextMapID, tostring(tonumber(nextMapID)) == nextMapID)
29+
end)
30+
return EventResult.Continue
31+
end)

plugins/map-chooser/menus.lua

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function RegisterMenus()
2+
local mplist = config:Fetch("map-chooser.maplist")
3+
4+
if not mplist or type(mplist) ~= "table" then
5+
print("Error: maplist is not valid")
6+
return
7+
end
8+
9+
local options = {}
10+
11+
for mapid, mapname in next,mplist,nil do
12+
if mapname and mapname ~= "" and mapid and mapid ~= "" then
13+
table.insert(options, { mapname, "sw_vote ".. mapid})
14+
else
15+
print(string.format("Map \"%s\" (%s) is not valid", mapname or "", mapid or ""))
16+
end
17+
end
18+
19+
menus:Register("chooser_menu", FetchTranslation("map-chooser.vote_title"), tostring(config:Fetch("map-chooser.color")), options)
20+
end
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"votemap": {
3+
"en": "Vote for a new map!",
4+
"ro": "Votează pentru o hartă!"
5+
},
6+
"alreadyvoted": {
7+
"en": "You have already voted for the map!",
8+
"ro": "Ai votat deja pentru hartă!"
9+
},
10+
"cannotvote": {
11+
"en": "You cannot vote yet.",
12+
"ro": "Nu poți vota încă."
13+
},
14+
"voted": {
15+
"en": "You have voted for {GREEN}{MAP}{DEFAULT}.",
16+
"ro": "Ai votat pentru {GREEN}{MAP}{DEFAULT}."
17+
},
18+
"checkconsole": {
19+
"en": "Check the console for the next map.",
20+
"ro": "Verifică consola pentru următoarea hartă."
21+
},
22+
"alreadyrtv": {
23+
"en": "You can't change the vote again in the same match.",
24+
"ro": "Nu poți schimba votul din nou în același meci."
25+
},
26+
"rtv": {
27+
"en": "Rock the vote! {GREEN}{COUNT}/{REQUIRED}{DEFAULT} voted to change the vote.",
28+
"ro": "Schimbă votul! {GREEN}{COUNT}/{REQUIRED}{DEFAULT} au votat pentru a schimba votul."
29+
},
30+
"mapwon": {
31+
"en": "The map {GREEN}{MAP_NAME}{DEFAULT} won with {GREEN}{VOTES} votes ({PRECENTAGE}%){DEFAULT}!",
32+
"ro": "Harta {GREEN}{MAP_NAME}{DEFAULT} a câștigat cu {GREEN}{VOTES} voturi ({PRECENTAGE}%){DEFAULT}!"
33+
},
34+
"vote_title": {
35+
"en": "Time to vote for a new map!",
36+
"ro": "Timpul să votezi o hartă!"
37+
}
38+
}

0 commit comments

Comments
 (0)