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<int> 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
<int>();
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 ^3!y ^5or ^3!n ^5to vote [^3Need " + Math.Ceiling(validPN.Count * successpercent * 0.01) + " ^2Y " + vote.Agree.Count + " ^1N " + (vote.Against.Count) + "]", 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 ^3NEXTMAP^5? Type ^3!y ^5or ^3!n ^5to vote [^3Need " + Math.Ceiling(validPN.Count * successpercent * 0.01) + " ^2Y " + vote.Agree.Count + " ^1N " + (vote.Against.Count) + "]", 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 ^3" + mapname + "^5? Type ^3!y ^5or ^3!n ^5to vote[^3Need " + Math.Ceiling(validPN.Count * successpercent * 0.01) + " ^2Y " + vote.Agree.Count + " ^1N " + (vote.Against.Count) + "]", player);
}
}
}
VoteTime--;
if (VoteTime == 0 && vote.InProgress)
{
if (vote.votemaprestart)
{
if ((Convert.ToDouble(vote.Agree.Count) / Convert.ToDouble(validPN.Count) * 100) >= successpercent)
{
ServerSay("^3VOTE PASSED:MAP RESTART", true);
ServerCommand("fast_restart");
}
else
ServerSay("^3VOTE FAILED: NOT ENOUGH PLAYERS AGREE TO RESTART MAP.", true);
}
if (vote.votenext)
{
if ((Convert.ToDouble(vote.Agree.Count) / Convert.ToDouble(validPN.Count) * 100) >= successpercent)
{
ServerSay("^3VOTE PASSED:MAP CHANGED", true);
ServerCommand("map_rotate");
}
else
ServerSay("^3VOTE FAILED: NOT ENOUGH PLAYERS AGREE TO CHANGE MAP.", true);
}
if (vote.votemap)
{
if ((Convert.ToDouble(vote.Agree.Count) / Convert.ToDouble(validPN.Count) * 100) >= successpercent)
{
ServerSay("^3VOTE PASSED:MAP CHANGED", true);
ServerCommand("map " + map_name);
}
else
ServerSay("^3VOTE FAILED: NOT 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); vote.InProgress = true;
vote.votenext = true;
VoteTime = Vtime;
}
return ChatType.ChatNone;
}
else if (lowMsg.Equals("!y"))
{
if (!vote.InProgress)
{
TellClient(Client.ClientNum, "^3There is currently no vote in progress! To start a vote, type ^2!vn ^3or ^2!vm(shortname) ^3in chat.", true);
}
if (vote.InProgress)
{
if (!vote.Agree.Contains(Client.XUID) && !vote.Against.Contains(Client.XUID))
{
vote.Agree.Add(Client.XUID);
ServerSay("^3"+ Client.Name+" ^2voted ^1<YES>",true);
}
else if (vote.Agree.Contains(Client.XUID) || vote.Against.Contains(Client.XUID))
{
TellClient(Client.ClientNum, "^3You already voted!", true);
}
}
return ChatType.ChatNone;
}
else if (lowMsg.Equals("!n"))
{
if (!vote.InProgress)
{
TellClient(Client.ClientNum, "^3There is currently no vote in progress! To start a vote, type ^2!vn ^3or ^2!vm(shortname) ^3in chat.", true);
}
if (vote.InProgress)
{
if (!vote.Agree.Contains(Client.XUID) && !vote.Against.Contains(Client.XUID))
{
vote.Against.Add(Client.XUID);
ServerSay("^3" + Client.Name + " ^2voted ^1<NO>", true);
}
else if (vote.Agree.Contains(Client.XUID) || vote.Against.Contains(Client.XUID))
{
TellClient(Client.ClientNum, "^3You already voted!", 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); vote.InProgress = true;
vote.votemap = true;
VoteTime = Vtime;
mapname = "Village";
map_name = "mp_village";
}
return ChatType.ChatNone;
}
else if (lowMsg.Equals("!vmfa"))
{
if (Interval > 0)
{
TellClient(Client.ClientNum, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); vote.InProgress = true;
vote.votemap = true;
VoteTime = Vtime;
mapname = "Fallen";
map_name = "mp_lambeth";
}
return ChatType.ChatNone;
}
else if (lowMsg.Equals("!vfr"))
{
if (Interval > 0)
{
TellClient(Client.ClientNum, "^3You can't start a vote now! wait " + Interval / 50 + " seconds.", true);
return ChatType.ChatNone;
}
if (vote.InProgress)
{
TellClient(Client.ClientNum, "^3There's already a vote in progress!", true);
}
else
{
vote.
Agree = new List
<string>(); vote.
Against = new List
<string>(); 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<string> Agree;
public List<string> 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, "^3!vfr ^5--- ^2call a vote for fast restart", true);
Thread.Sleep(5000);
TellClient(Client.ClientNum, "^3!vn ^5--- ^2call a vote for nextmap", true);
Thread.Sleep(5000);
TellClient(Client.ClientNum, "^3!mlist ^5--- ^2show map list and short name", true);
Thread.Sleep(5000);
TellClient(Client.ClientNum, "^3!vm(shortname) ^7--- ^2vote for specified map. ^1Ex:^3!vmun", true);
Thread.Sleep(5000);
TellClient(Client.ClientNum, "^3!y ^5--- ^2vote YES, ^3!n ^5--- ^2vote NO", true);
}
private void showmaplist(object cli)
{
ServerClient Client = (ServerClient)cli;
TellClient(Client.ClientNum, "^3[Map name] [shortname]", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Underground un", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Mission mi", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Interchange in", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Fallen fa", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Seatown se", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Village vi", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Bakaara ba", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Dome do", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Downturn dt", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Lockdown lo", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Outpost ou", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Arkaden ar", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Carbon ca", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Bootleg bo", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Hardhat ha", true);
Thread.Sleep(2500);
TellClient(Client.ClientNum, "^3Resistance re", true);
}
}
}