Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Reflection;
- using System.Collections.Generic;
- using System.Data;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Timers;
- 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;
- using PRoCon.Core.HttpServer;
- namespace PRoConEvents {
- public class CBFlagPlugin : PRoConPluginAPI, IPRoConPluginInterface {
- private int secondsToCount;
- private bool sayOrYell;
- private bool updating;
- private bool restarting;
- private System.Timers.Timer UpdateTimer;
- private System.Timers.Timer RestartTimer;
- private bool autoRestartEnable;
- private int autoRestartDelay;
- private bool m_isPluginEnabled;
- private List<TeamScore> currentTeamScore = new List<TeamScore>();
- public CBFlagPlugin() {
- this.secondsToCount = 3;
- this.sayOrYell = false;
- this.updating = false;
- this.restarting = false;
- this.autoRestartEnable = false;
- this.autoRestartDelay = 5;
- this.m_isPluginEnabled = false;
- }
- public string GetPluginName() {
- return "B-Flag Plugin";
- }
- public string GetPluginVersion() {
- return "420.1.0.0";
- }
- public string GetPluginAuthor() {
- return "J4nssent";
- }
- public string GetPluginWebsite() {
- return "www.youtube.com/watch?v=dQw4w9WgXcQ";
- }
- public string GetPluginDescription() {
- return @"
- <h2>Description</h2>
- <p>Provides a countdown. With the !count command. You can choose between say and yell.</p>
- <p>Now you can also change the team with a simple command and you can suicide youself.</p>
- <p>This program also provides an automatic restart, so you don't have to wait 45 seconds at the end of a match.</p>
- <h2>Commands</h2>
- <blockquote><h4>@count</h4>Counts down</blockquote>
- <blockquote><h4>@moveme <i>team</i> </h4>Teamswitches player, <i>team </i> can be US or RU </blockquote>
- <blockquote><h4>@suicide</h4>Commit suicide</blockquote>
- <h2>Settings</h2>
- <blockquote><h4>Enabled</h4>Enables/Disables AutoRestart</blockquote>
- <blockquote><h4>Scoreboard</h4>Number of seconds the scoreboard will appear before restarting.</blockquote>
- <blockquote><h4>Seconds</h4>The number to count down from</blockquote>
- <blockquote><h4>Type (SayYell)</h4>False to say and True to yell the countdown.</blockquote>";
- }
- public void OnPluginLoaded(string strHostName, string strPort, string strPRoConVersion) {
- this.RegisterEvents(this.GetType().Name, "OnPlayerKilled", "OnRegisteredCommand", "OnUnregisteredCommand", "OnServerInfo" );
- }
- public void OnPluginEnable() {
- this.ExecuteCommand("procon.protected.pluginconsole.write", "^bB-Flag Plugin ^2Enabled!");
- this.m_isPluginEnabled = true;
- this.RegisterAllCommands();
- }
- public void OnPluginDisable() {
- this.ExecuteCommand("procon.protected.pluginconsole.write", "^bB-Flag Plugin ^1Disabled!" );
- this.m_isPluginEnabled = false;
- this.UnregisterAllCommands();
- }
- public List<CPluginVariable> GetDisplayPluginVariables() {
- List<CPluginVariable> lstReturn = new List<CPluginVariable>();
- lstReturn.Add(new CPluginVariable("Countdown|Seconds", typeof(int), secondsToCount));
- lstReturn.Add(new CPluginVariable("Countdown|Type (Say=false, Yell=true)", typeof(bool), sayOrYell));
- lstReturn.Add(new CPluginVariable("AutoRestart|Enabled", typeof(bool), autoRestartEnable));
- lstReturn.Add(new CPluginVariable("AutoRestart|Scoreboard", typeof(int), autoRestartDelay));
- return lstReturn;
- }
- public List<CPluginVariable> GetPluginVariables() {
- return GetDisplayPluginVariables();
- }
- public void SetPluginVariable(string strVariable, string strValue) {
- if (Regex.Match(strVariable, @"Seconds").Success)
- {
- int tmpSecs = 2;
- int.TryParse(strValue, out tmpSecs);
- secondsToCount = tmpSecs;
- }
- else if (Regex.Match(strVariable, @"Type").Success)
- {
- bool tmpSayOrYell = false;
- Boolean.TryParse(strValue, out tmpSayOrYell);
- sayOrYell = tmpSayOrYell;
- }
- else if (Regex.Match(strVariable, @"Enabled").Success)
- {
- bool tmpAutoRestartEnable = false;
- Boolean.TryParse(strValue, out tmpAutoRestartEnable);
- autoRestartEnable = tmpAutoRestartEnable;
- }
- else if (Regex.Match(strVariable, @"Scoreboard").Success)
- {
- int tmpTime = 5;
- int.TryParse(strValue, out tmpTime);
- autoRestartDelay = tmpTime;
- }
- this.RegisterAllCommands();
- }
- private void UnregisterAllCommands() {
- this.UnregisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandCount", this.Listify<string>("@", "!", "#"), "count", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Counts down"));
- this.UnregisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandMoveMe", this.Listify<string>("@", "!", "#"), "moveme", this.Listify<MatchArgumentFormat>(new MatchArgumentFormat("team", this.Listify<string>("RU","US"))), new ExecutionRequirements(ExecutionScope.All), "Moves a player to the other team"));
- this.UnregisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandSuicide", this.Listify<string>("@", "!", "#"), "suicide", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Commit suicide"));
- }
- private void RegisterAllCommands() {
- if (this.m_isPluginEnabled == true) {
- this.RegisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandCount", this.Listify<string>("@", "!", "#"), "count", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Counts down"));
- this.RegisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandMoveMe", this.Listify<string>("@", "!", "#"), "moveme", this.Listify<MatchArgumentFormat>(new MatchArgumentFormat("team", this.Listify<string>("RU","US"))), new ExecutionRequirements(ExecutionScope.All), "Moves a player to the other team"));
- this.RegisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandSuicide", this.Listify<string>("@", "!", "#"), "suicide", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Commit suicide"));
- }
- }
- #region commands
- public void OnCommandCount(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope) {
- if (this.sayOrYell == false) {
- for (int i = this.secondsToCount; i > 0; i--)
- {
- this.ExecuteCommand("procon.protected.send", "admin.say", i.ToString(), "all");
- }
- this.ExecuteCommand("procon.protected.send", "admin.say", "GO!", "all");
- }else{
- for (int i = this.secondsToCount; i > 0; i--)
- {
- if(i==3)
- {
- this.ExecuteCommand("procon.protected.send", "admin.yell", "333333333"+Environment.NewLine+" 33"+Environment.NewLine+" 33"+Environment.NewLine+"333333333"+Environment.NewLine+" 33"+Environment.NewLine+" 33"+Environment.NewLine+"333333333");
- }
- if(i==2)
- {
- this.ExecuteCommand("procon.protected.send", "admin.yell", "222222222" + Environment.NewLine + " 22" + Environment.NewLine + " 22" + Environment.NewLine + "222222222" + Environment.NewLine + " 22 ." + Environment.NewLine + " 22 ." + Environment.NewLine + "222222222");
- }
- if(i==1)
- {
- this.ExecuteCommand("procon.protected.send", "admin.yell", "11111111" + Environment.NewLine + " 11 " + Environment.NewLine + " 11 " + Environment.NewLine + " 11 " + Environment.NewLine + " 11" + Environment.NewLine + " 11" + Environment.NewLine + " 11");
- }
- }
- this.ExecuteCommand("procon.protected.send", "admin.yell", "!!!!" + Environment.NewLine + "!!!!" + Environment.NewLine + "!!!!" + Environment.NewLine + "!!!!" + Environment.NewLine + "!!!!" + Environment.NewLine + "" + Environment.NewLine + "!!!!");
- }
- }
- public void OnCommandMoveMe(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope) {
- if (capCommand.MatchedArguments[0].Argument == "RU") {
- this.ExecuteCommand("procon.protected.send", "admin.movePlayer", strSpeaker, "2", "1", "true");
- } else if (capCommand.MatchedArguments[0].Argument == "US"){
- this.ExecuteCommand("procon.protected.send", "admin.movePlayer", strSpeaker, "1", "1", "true");
- }
- }
- public void OnCommandSuicide(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope) {
- this.ExecuteCommand("procon.protected.send", "admin.killPlayer", strSpeaker);
- }
- #endregion
- #region events
- public override void OnPlayerKilled (Kill kKillerVictimDetails) {
- this.ExecuteCommand("procon.protected.send", "admin.killPlayer", kKillerVictimDetails.Victim.SoldierName);
- }
- public void OnServerInfo(CServerInfo csiServerInfo) {
- if (this.autoRestartEnable == true && this.m_isPluginEnabled == true) {
- this.currentTeamScore = new List<TeamScore>(csiServerInfo.TeamScores);
- if (currentTeamScore.Count == 0 && restarting == false) {
- UpdateTimer.Enabled = false;
- this.updating = false;
- SetRestartTimer();
- this.restarting = true;
- } else if ((currentTeamScore[0].Score < 10 || currentTeamScore[1].Score < 10) && this.updating == false ) {
- SetUpdateTimer();
- this.updating = true;
- }
- }
- }
- #endregion
- private void SetUpdateTimer() {
- UpdateTimer = new System.Timers.Timer(3000);
- UpdateTimer.Elapsed += OnUpdate;
- UpdateTimer.AutoReset = true;
- UpdateTimer.Enabled = true;
- }
- private void SetRestartTimer() {
- RestartTimer = new System.Timers.Timer(4000 + (this.autoRestartDelay * 1000));
- RestartTimer.Elapsed += OnRestart;
- RestartTimer.Enabled = true;
- }
- private void OnUpdate(object source, ElapsedEventArgs e) {
- this.ExecuteCommand("procon.protected.send", "serverInfo");
- }
- private void OnRestart(object source, ElapsedEventArgs e) {
- this.ExecuteCommand("procon.protected.pluginconsole.write", "restarting...");
- this.ExecuteCommand("procon.protected.send", "mapList.restartRound");
- RestartTimer.Enabled = false;
- this.restarting = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement