using System; using System.Collections.Generic; using System.Threading; using Addon; namespace mw3_votemap { public class Votemap : CPlugin { string map_name; string mapname; Vote vote; int Interval; int VoteTime; int votemsginterval; List validPN; int Vtime; int successpercent; public override void OnServerFrame() { if (Interval > 0) Interval--; if (VoteTime > 0 && vote.InProgress) { if (VoteTime % votemsginterval == 0) { validPN = new List(); foreach (ServerClient player in GetClients()) { if (player.Ping < 999 && player.Ping > 0) { validPN.Add(player.ClientNum); } } if (validPN.Count == 0) { vote.votenext = false; vote.votemaprestart = false; vote.votemap = false; vote.InProgress = false; } foreach (ServerClient player in GetClients()) { if (vote.votemaprestart) { //TellClient(player.ClientNum, "^1(" + VoteTime / 50 + "s) ^2" + player.Name + " ^5called a vote for nextmap. Type ^3!y ^5or ^3!n ^5to vote [^3Need " + Math.Ceiling(validPN.Count * 0.6) + " ^2Yes " + vote.Agree.Count + " ^1No " + (vote.Against.Count) + "]", true); iPrintLnBold("^1(" + VoteTime / 50 + "s)^5Restart map? Type ^1!y ^5or ^1!n ^5to vote ^1[Need " + Math.Ceiling(validPN.Count * successpercent * 0.01) + "^6|| ^2Yes= " + vote.Agree.Count + "^6|| ^3No= " + (vote.Against.Count) + "^1]", player); } if (vote.votenext) { //TellClient(player.ClientNum, "^1(" + VoteTime / 50 + "s) ^2" + player.Name + " ^5called a vote for nextmap. Type ^3!y ^5or ^3!n ^5to vote [^3Need " + Math.Ceiling(validPN.Count * 0.6) + " ^2Yes " + vote.Agree.Count + " ^1No " + (vote.Against.Count) + "]", true); iPrintLnBold("^1(" + VoteTime / 50 + "s)^5Go to NEXTMAP? Type ^1!y ^5or ^1!n ^5to vote ^1[Need " + Math.Ceiling(validPN.Count * successpercent * 0.01) + "^6|| ^2Yes= " + vote.Agree.Count + "^6|| ^3No= " + (vote.Against.Count) + "^1]", player); } if (vote.votemap) { //TellClient(player.ClientNum, "^1(" + VoteTime / 50 + "s) ^2" + player.Name + " ^5vote for ^3<" + mapname + ">^5. Type ^3!y ^5or ^3!n ^5to vote [^3Need " + Math.Ceiling(validPN.Count * 0.6) + " ^2Yes " + vote.Agree.Count + " ^1No " + (vote.Against.Count) + "]", true); iPrintLnBold("^1(" + VoteTime / 50 + "s)^5Go to " + mapname + "? Type ^1!y ^5or ^1!n ^5to vote ^1[Need " + Math.Ceiling(validPN.Count * successpercent * 0.01) + "^6|| ^2Yes= " + vote.Agree.Count + "^6|| ^3No= " + (vote.Against.Count) + "^1]", player); } } } VoteTime--; if (VoteTime == 0 && vote.InProgress) { if (vote.votemaprestart) { if ((Convert.ToDouble(vote.Agree.Count) / Convert.ToDouble(validPN.Count) * 100) >= successpercent) { ServerSay("^6VOTE PASSED:^5MAP RESTART", true); ServerCommand("fast_restart"); } else ServerSay("^6VOTE FAILED: ^5NOT ENOUGH PLAYERS AGREE TO RESTART MAP.", true); } if (vote.votenext) { if ((Convert.ToDouble(vote.Agree.Count) / Convert.ToDouble(validPN.Count) * 100) >= successpercent) { ServerSay("^6VOTE PASSED:^5MAP CHANGED", true); ServerCommand("map_rotate"); } else ServerSay("^6VOTE FAILED: ^5NOT ENOUGH PLAYERS AGREE TO CHANGE MAP.", true); } if (vote.votemap) { if ((Convert.ToDouble(vote.Agree.Count) / Convert.ToDouble(validPN.Count) * 100) >= successpercent) { ServerSay("^6VOTE PASSED:^5MAP CHANGED", true); ServerCommand("map " + map_name); } else ServerSay("^6VOTE FAILED: ^5NOT ENOUGH PLAYERS AGREE TO CHANGE MAP.", true); } ResetVars(); } } } public override void OnServerLoad() { ServerPrint("Votemap plugin 1.21 loaded. Author: zhp0083 Special thanks: Nukem, iAegle, VSpeed"); votemsginterval = Convert.ToInt32(GetServerCFG("VOTEMAP", "votemsginterval", "")) * 50; Vtime = Convert.ToInt32(GetServerCFG("VOTEMAP", "votetime", "")) * 50; successpercent = Convert.ToInt32(GetServerCFG("VOTEMAP", "successpercent", "")); } public override ChatType OnSay(string Message, ServerClient Client) { string lowMsg = Message.ToLower(); if (lowMsg.Equals("!vn")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!^5 :x", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votenext = true; VoteTime = Vtime; } return ChatType.ChatNone; } else if (lowMsg.Equals("!y")) { if (!vote.InProgress) { TellClient(Client.ClientNum, "^6There is currently no vote in progress! ^5To start a vote, type ^6!vn ^5or ^6!vm(shortname) ^5in chat.", true); } if (vote.InProgress) { if (!vote.Agree.Contains(Client.XUID) && !vote.Against.Contains(Client.XUID)) { vote.Agree.Add(Client.XUID); ServerSay("^5" + Client.Name + " ^6voted ^5", true); } else if (vote.Agree.Contains(Client.XUID) || vote.Against.Contains(Client.XUID)) { TellClient(Client.ClientNum, "^6You already ^5voted!", true); } } return ChatType.ChatNone; } else if (lowMsg.Equals("!n")) { if (!vote.InProgress) { TellClient(Client.ClientNum, "^6There is currently no vote in progress! ^5To start a vote, type ^6!vn ^5or ^6!vm(shortname) ^5in chat.", true); } if (vote.InProgress) { if (!vote.Agree.Contains(Client.XUID) && !vote.Against.Contains(Client.XUID)) { vote.Against.Add(Client.XUID); ServerSay("^5" + Client.Name + " ^6voted ^5", true); } else if (vote.Agree.Contains(Client.XUID) || vote.Against.Contains(Client.XUID)) { TellClient(Client.ClientNum, "^6You already ^5voted!", true); } } return ChatType.ChatNone; } else if (lowMsg.Equals("!mlist")) { Thread shru = new Thread(showmaplist); shru.Start(Client); return ChatType.ChatNone; } else if (lowMsg.Equals("!vmun")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Underground"; map_name = "mp_underground"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmou")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Outpost"; map_name = "mp_radar"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmdo")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Dome"; map_name = "mp_dome"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmre")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Resistance"; map_name = "mp_paris"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmca")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Carbon"; map_name = "mp_carbon"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmin")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Interchange"; map_name = "mp_interchange"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmdt")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Downturn"; map_name = "mp_exchange"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmar")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Arkaden"; map_name = "mp_plaza2"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmlo")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Lockdown"; map_name = "mp_alpha"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmmi")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Mission"; map_name = "mp_bravo"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmse")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Seatown"; map_name = "mp_seatown"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmbo")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Bootleg"; map_name = "mp_bootleg"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmha")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Hardhat"; map_name = "mp_hardhat"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmba")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Bakaara"; map_name = "mp_mogadishu"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmvi")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Village"; map_name = "mp_village"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmte")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Terminal"; map_name = "mp_terminal_cls"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmfa")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Fallen"; map_name = "mp_lambeth"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmer")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Erosion"; map_name = "mp_courtyard_cls"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vmag")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemap = true; VoteTime = Vtime; mapname = "Aground"; map_name = "mp_aground_cls"; } return ChatType.ChatNone; } else if (lowMsg.Equals("!vfr")) { if (Interval > 0) { TellClient(Client.ClientNum, "^6You can't start a vote now! ^5wait " + Interval / 50 + " seconds.", true); return ChatType.ChatNone; } if (vote.InProgress) { TellClient(Client.ClientNum, "^6There's already a vote in progress!", true); } else { vote.Agree = new List(); vote.Against = new List(); vote.InProgress = true; vote.votemaprestart = true; VoteTime = Vtime; } return ChatType.ChatNone; } else if (lowMsg.Equals("!cmds")) { Thread shru = new Thread(showcmds); shru.Start(Client); return ChatType.ChatNone; } return ChatType.ChatContinue; } public struct Vote { public bool InProgress; public ServerClient Client; public List Agree; public List Against; public bool votenext; public bool votemap; public bool votemaprestart; } private void ResetVars() { //reset vars validPN.Clear(); VoteTime = 0; vote.Agree.Clear(); vote.Against.Clear(); vote.InProgress = false; vote.votenext = false; vote.votemap = false; vote.votemaprestart = false; //set cooldown timer Interval = Convert.ToInt32(GetServerCFG("VOTEMAP", "cooldown", "")) * 50; } private void showcmds(object cli) { ServerClient Client = (ServerClient)cli; TellClient(Client.ClientNum, "^1!vfr ^6= ^5Call a vote for fast restart", true); Thread.Sleep(5000); TellClient(Client.ClientNum, "^1!vn ^6= ^5Call a vote for nextmap", true); Thread.Sleep(5000); TellClient(Client.ClientNum, "^1!mlist ^6= ^5Show map list and short name", true); Thread.Sleep(5000); TellClient(Client.ClientNum, "^1!vm(shortname) ^6= ^5Vote for specified map. (Example:^1!vmun^5)", true); Thread.Sleep(5000); TellClient(Client.ClientNum, "^1!y ^6= ^5vote YES ^6|| ^1!n ^6= ^5vote NO", true); } private void showmaplist(object cli) { ServerClient Client = (ServerClient)cli; TellClient(Client.ClientNum, "^6[Map name] ^5= ^1[shortname]", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Underground ^5= ^1un", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Mission ^5= ^1mi", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Interchange = ^1in", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Fallen ^5= ^1fa", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Seatown ^5= ^1se", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Village ^5= ^1vi", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Bakaara ^5= ^1ba", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Dome ^5= ^1do", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Downturn ^5= ^1dt", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Lockdown ^5= ^1lo", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Outpost ^5= ^1ou", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Arkaden ^5= ^1ar", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Carbon ^5= ^1ca", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Bootleg ^5= ^1bo", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Hardhat ^5= ^1ha", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Terminal ^5= ^1te", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Erosion ^5= ^1er", true); Thread.Sleep(2500); TellClient(Client.ClientNum, "^6Aground ^5= ^1ag", true); } } }