Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Collections;
- using System.Net;
- using System.Web;
- using System.Data;
- using System.Threading;
- using System.Security;
- using System.Timers;
- using System.Diagnostics;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using PRoCon.Core;
- using PRoCon.Core.Plugin;
- using PRoCon.Core.Plugin.Commands;
- using PRoCon.Core.Players;
- using PRoCon.Core.Players.Items;
- using PRoCon.Core.Battlemap;
- using PRoCon.Core.Maps;
- namespace PRoConEvents
- {
- using EventType = PRoCon.Core.Events.EventType;
- using CapturableEvent = PRoCon.Core.Events.CapturableEvents;
- public class VoteChange : PRoConPluginAPI, IPRoConPluginInterface
- {
- double votePercentage = 0.66;
- int playerCount = 0;
- string cmdthing = "";
- List<string[]> Votes = new List<string[]>();
- List<string[]> teamVotes = new List<string[]>();
- List<string[]> modeVotes = new List<string[]>();
- string currentMap = "MP_Desert05";
- string currentMode = "TurfwarLarge0";
- string[,] Maps = new string[,] { {"Downtown", "MP_Downtown"},
- {"The Block", "MP_Bloodout"},
- {"Derailed", "MP_Eastside"},
- {"Dust Bowl", "MP_Desert05"},
- {"Bank Job", "MP_Bank"},
- {"Riptide", "MP_Offshore"},
- {"Hollywood Heights", "MP_Hills"},
- {"Everglades", "MP_Glades"},
- {"Growhouse", "MP_Growhouse"}
- };
- string[,] Modes = new string[,] { {"Blood Money", "BloodMoney0"},
- {"Hotwire", "Hotwire0"},
- {"Heist", "Heist0"},
- {"Crosshair", "Hit0"},
- {"Rescue", "Hostage0"},
- {"Team Deathmatch", "TeamDeathMatch0"},
- {"Conquest Large", "TurfwarLarge0"},
- {"Conquest Small", "TurfwarSmall0"},
- };
- string[,] MapModes = new string[,] { {"BloodMoney0", "all"},
- {"Hotwire0", "MP_Downtown MP_Eastside MP_Desert05 MP_Offshore MP_Glades"},
- {"Heist0", "all"},
- {"Hit0", "all"},
- {"Hostage0", "all"},
- {"TeamDeathMatch0", "all"},
- {"TurfwarLarge0", "MP_Downtown MP_Eastside MP_Desert05 MP_Offshore MP_Glades MP_Bloodout MP_Bank MP_Hills"},
- {"TurfwarSmall0", "all"},
- };
- public VoteChange()
- {
- }
- public void ServerCommand(params String[] args)
- {
- List<String> list = new List<String>();
- list.Add("procon.protected.send");
- list.AddRange(args);
- this.ExecuteCommand(list.ToArray());
- }
- bool checkMapMode(string map, string mode)
- {
- for(int i = 0; i < 7; ++i)
- {
- bool contains = MapModes[i,0].ToLower().Contains(mode.ToLower());
- if(contains)
- {
- if(MapModes[i,1] == "all")
- return true;
- if (MapModes[i,1].ToLower().Contains(map.ToLower()))
- return true;
- else
- return false;
- }
- }
- return false;
- }
- bool isModeCorrect(string vote, string speaker)
- {
- bool alreadyFound = false;
- string mode = "";
- for(int i = 0; i < 7; ++i)
- {
- bool contains = Modes[i,0].ToLower().Contains(vote);
- if(contains)
- {
- if(!alreadyFound)
- {
- mode = Modes[i,1];
- alreadyFound = true;
- }
- else
- {
- ServerCommand("admin.say", "Found more than one mode. Please be more specific!", "player", speaker);
- return false;
- }
- }
- }
- if(alreadyFound)
- {
- if (checkMapMode(currentMap, mode))
- {
- return true;
- }
- else
- {
- ServerCommand("admin.say", "Mode is not available for current map", "player", speaker);
- return false;
- }
- }
- ServerCommand("admin.say", "No modes corresponding to your vote were found", "player", speaker);
- return false;
- }
- bool isVoteCorrect(string vote, string speaker)
- {
- bool alreadyFound = false;
- for(int i = 0; i < 9; i++)
- {
- bool contains = Maps[i,0].ToLower().Contains(vote);
- if(contains)
- {
- if(!alreadyFound)
- {
- alreadyFound = true;
- }
- else
- {
- ServerCommand("admin.say", "Found more than one map. Please be more specific!", "player", speaker);
- return false;
- }
- }
- }
- if(alreadyFound)
- {
- return true;
- }
- return false;
- }
- string[] getMap(string vote)
- {
- string[] mapInfo = new string[2];
- for(int i = 0; i < 9; i++)
- {
- bool contains = Maps[i,0].ToLower().Contains(vote);
- if(contains)
- {
- mapInfo[0] = Maps[i,0];
- mapInfo[1] = Maps[i,1];
- return mapInfo;
- }
- }
- return mapInfo;
- }
- string[] getMode(string vote)
- {
- string[] mapInfo = new string[2];
- for(int i = 0; i < 7; i++)
- {
- bool contains = Modes[i,0].ToLower().Contains(vote);
- if(contains)
- {
- mapInfo[0] = Modes[i,0];
- mapInfo[1] = Modes[i,1];
- return mapInfo;
- }
- }
- return mapInfo;
- }
- float countVotes(string map)
- {
- float votes = 0;
- foreach(string[] vote in Votes)
- {
- if(vote[1] == map)
- {
- //ServerCommand("admin.say", "Vote found", "all");
- votes += 1;
- }
- }
- return votes;
- }
- int hasVoted(string speaker)
- {
- int index = 0;
- foreach(string[] vote in Votes)
- {
- if(vote[0] == speaker)
- return index;
- index++;
- }
- return -1;
- }
- bool teamVoteIsCorrect(string arg1, string arg2)
- {
- if(!arg1.Equals("US", StringComparison.InvariantCultureIgnoreCase) && !arg1.Equals("CH", StringComparison.InvariantCultureIgnoreCase) && !arg1.Equals("RU", StringComparison.InvariantCultureIgnoreCase))
- return false;
- if(!arg2.Equals("US", StringComparison.InvariantCultureIgnoreCase) && !arg2.Equals("CH", StringComparison.InvariantCultureIgnoreCase) && !arg2.Equals("RU", StringComparison.InvariantCultureIgnoreCase))
- return false;
- return true;
- }
- int teamVoteStringToID(string team)
- {
- if(team.Equals("us", StringComparison.InvariantCultureIgnoreCase))
- return 0;
- if(team.Equals("ru", StringComparison.InvariantCultureIgnoreCase))
- return 1;
- if(team.Equals("ch", StringComparison.InvariantCultureIgnoreCase))
- return 2;
- else
- return -1;
- }
- int countTeamVotes(string team1, string team2)
- {
- int votes = 0;
- foreach(string[] vote in teamVotes)
- {
- if(vote[1] == team1 && vote[2] == team2)
- votes++;
- }
- return votes;
- }
- int countModeVotes(string mode)
- {
- int votes = 0;
- foreach(string[] vote in modeVotes)
- {
- if(vote[1] == mode)
- votes++;
- }
- return votes;
- }
- int hasVoted_mode(string speaker)
- {
- int index = 0;
- foreach(string[] vote in modeVotes)
- {
- if(vote[0] == speaker)
- return index;
- index++;
- }
- return -1;
- }
- void parseMessage(string speaker, string message)
- {
- string[] arguments = message.Split(' ');
- if (arguments[0].Equals("!votechange", StringComparison.InvariantCultureIgnoreCase))
- {
- string vote = "";
- for(int i=1; i<arguments.Length; i++)
- {
- if(i == arguments.Length-1)
- vote += arguments[i].ToLower();
- else
- vote += arguments[i].ToLower() + " ";
- }
- if (isVoteCorrect(vote, speaker))
- {
- string[] Map = getMap(vote);
- int voteIndex = hasVoted(speaker);
- if(voteIndex == -1)
- {
- ServerCommand("admin.say", speaker + " voted for " + Map[0], "all");
- string[] voteToAdd = new string[] { speaker, Map[0] };
- Votes.Add(voteToAdd);
- }
- else
- {
- ServerCommand("admin.say", speaker + " changed vote to " + Map[0], "all");
- Votes[voteIndex][1] = Map[0];
- }
- float voteCount = countVotes(Map[0]);
- float players = (float)playerCount;
- double ratio = voteCount/players;
- if (ratio >= votePercentage)
- {
- Votes.Clear();
- ServerCommand("mapList.clear");
- currentMap = Map[1];
- ServerCommand("admin.say", (Math.Round(votePercentage,2)*100).ToString() + "% exceeded. Changing map to " + Map[0] + " in 10 seconds", "all");
- if(checkMapMode(currentMap, currentMode))
- ServerCommand("mapList.add", Map[1], currentMode, "1");
- else
- {
- ServerCommand("mapList.add", Map[1], "TurfwarSmall0", "1");
- ServerCommand("admin.say", "Changing mode to Conquest Small");
- }
- ServerCommand("mapList.save");
- this.ExecuteCommand("procon.protected.tasks.add", "10", "1", "1", "procon.protected.send", "mapList.runNextRound");
- }
- else
- ServerCommand("admin.say", Math.Round((float)(ratio*100), 2).ToString() + "% of the players have voted for " + Map[0], "all");
- }
- else
- ServerCommand("admin.say", "No maps corresponding to your vote were found", "player", speaker);
- }
- else if(arguments[0].Equals("!help", StringComparison.InvariantCultureIgnoreCase))
- {
- ServerCommand("admin.say", "!voteChange <map>", "player", speaker);
- ServerCommand("admin.say", "!voteMode <mode>", "player", speaker);
- //ServerCommand("admin.say", "!killProtection to punish your killers", "player", speaker);
- ServerCommand("admin.say", "Votes need " + (Math.Round(votePercentage,2)*100).ToString() + "% to pass.", "player", speaker);
- }
- else if (arguments[0].Equals("!votemode", StringComparison.InvariantCultureIgnoreCase))
- {
- string vote = "";
- for(int i=1; i<arguments.Length; i++)
- {
- if(i == arguments.Length-1)
- vote += arguments[i].ToLower();
- else
- vote += arguments[i].ToLower() + " ";
- }
- if (isModeCorrect(vote, speaker))
- {
- string[] Mode = getMode(vote);
- int voteIndex = hasVoted_mode(speaker);
- if(voteIndex == -1)
- {
- ServerCommand("admin.say", speaker + " voted for " + Mode[0], "all");
- string[] voteToAdd = new string[] { speaker, Mode[0] };
- modeVotes.Add(voteToAdd);
- }
- else
- {
- ServerCommand("admin.say", speaker + " changed mode vote to " + Mode[0], "all");
- modeVotes[voteIndex][1] = Mode[0];
- }
- float voteCount = countModeVotes(Mode[0]);
- float players = (float)playerCount;
- double ratio = voteCount/players;
- if (ratio >= votePercentage)
- {
- modeVotes.Clear();
- ServerCommand("mapList.clear");
- currentMode = Mode[1];
- ServerCommand("admin.say", (Math.Round(votePercentage,2)*100).ToString() + "% exceeded. Changing mode to " + Mode[0] + " in 10 seconds", "all");
- ServerCommand("mapList.add", currentMap, currentMode, "1");
- ServerCommand("mapList.save");
- this.ExecuteCommand("procon.protected.tasks.add", "10", "1", "1", "procon.protected.send", "mapList.runNextRound");
- }
- else
- ServerCommand("admin.say", Math.Round((float)(ratio*100), 2).ToString() + "% of the players have voted for " + Mode[0], "all");
- }
- }
- }
- public void LogWrite(String msg)
- {
- this.ExecuteCommand("procon.protected.pluginconsole.write", msg);
- }
- public String GetPluginName()
- {
- return "Vote Change!";
- }
- public String GetPluginVersion()
- {
- return "1.2.0.0";
- }
- public String GetPluginAuthor()
- {
- return "Hattiwatti";
- }
- public String GetPluginWebsite()
- {
- return "www.BFCinematicTools.com";
- }
- public String GetPluginDescription()
- {
- return "This plugin lets players to vote a map change. Ideal for filming servers.";
- }
- public List<CPluginVariable> GetDisplayPluginVariables()
- {
- List<CPluginVariable> lstReturn = new List<CPluginVariable>();
- lstReturn.Add(new CPluginVariable("Settings|Vote percentage to win", votePercentage.GetType(), votePercentage));
- lstReturn.Add(new CPluginVariable("Settings|rnd", cmdthing.GetType(), cmdthing));
- return lstReturn;
- }
- public List<CPluginVariable> GetPluginVariables()
- {
- return GetDisplayPluginVariables();
- }
- public void SetPluginVariable(String strVariable, String strValue)
- {
- if (Regex.Match(strVariable, @"Vote percentage to win").Success)
- {
- float tmp = 0.66f;
- float.TryParse(strValue, out tmp);
- votePercentage = tmp;
- }
- }
- public void OnPluginEnable()
- {
- ServerCommand("admin.listPlayers", "all");
- this.ExecuteCommand("procon.protected.tasks.add", "1", "300", "-1", "procon.protected.send", "admin.say", "Type !help to list available commands", "all");
- }
- public void OnPluginDisable()
- {
- }
- public override void OnVersion(String serverType, String version) { }
- public override void OnServerInfo(CServerInfo serverInfo)
- {
- }
- public override void OnResponseError(List<String> requestWords, String error) { }
- public override void OnListPlayers(List<CPlayerInfo> players, CPlayerSubset subset)
- {
- playerCount = players.Count;
- }
- public override void OnPlayerJoin(string SoldierName)
- {
- ServerCommand("admin.say", "Welcome! Type !help for available commands", "player", SoldierName);
- }
- public override void OnPlayerLeft(CPlayerInfo playerInfo)
- {
- foreach (string[] vote in Votes)
- {
- if (vote[0] == playerInfo.SoldierName)
- {
- Votes.Remove(vote);
- return;
- }
- }
- foreach (string[] vote in teamVotes)
- {
- if (vote[0] == playerInfo.SoldierName)
- {
- teamVotes.Remove(vote);
- return;
- }
- }
- }
- public override void OnGlobalChat(String speaker, String message)
- {
- parseMessage(speaker, message);
- }
- public override void OnTeamChat(String speaker, String message, int teamId)
- {
- parseMessage(speaker, message);
- }
- public override void OnSquadChat(String speaker, String message, int teamId, int squadId)
- {
- parseMessage(speaker, message);
- }
- public override void OnLoadingLevel(String mapFileName, int roundsPlayed, int roundsTotal)
- {
- Votes.Clear();
- teamVotes.Clear();
- }
- public override void OnLevelStarted()
- {
- }
- public void OnPluginLoaded(String strHostName, String strPort, String strPRoConVersion)
- {
- this.RegisterEvents(this.GetType().Name, "OnVersion", "OnServerInfo", "OnResponseError", "OnListPlayers", "OnPlayerJoin", "OnPlayerLeft", "OnPlayerKilled", "OnPlayerSpawned", "OnPlayerTeamChange", "OnGlobalChat", "OnTeamChat", "OnSquadChat", "OnRoundOverPlayers", "OnRoundOver", "OnRoundOverTeamScores", "OnLoadingLevel", "OnLevelStarted", "OnLevelLoaded");
- }
- }
- } // end namespace PRoConEvents
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement