Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.95 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Reflection;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Text.RegularExpressions;
  8. using System.Threading;
  9. using System.Timers;
  10.  
  11. using PRoCon.Core;
  12. using PRoCon.Core.Plugin;
  13. using PRoCon.Core.Plugin.Commands;
  14. using PRoCon.Core.Players;
  15. using PRoCon.Core.Players.Items;
  16. using PRoCon.Core.Battlemap;
  17. using PRoCon.Core.Maps;
  18. using PRoCon.Core.HttpServer;
  19.  
  20. namespace PRoConEvents {
  21. public class CBFlagPlugin : PRoConPluginAPI, IPRoConPluginInterface {
  22.  
  23. private int secondsToCount;
  24. private bool sayOrYell;
  25.  
  26. private bool updating;
  27. private bool restarting;
  28.  
  29. private System.Timers.Timer UpdateTimer;
  30. private System.Timers.Timer RestartTimer;
  31.  
  32. private bool autoRestartEnable;
  33. private int autoRestartDelay;
  34.  
  35. private bool m_isPluginEnabled;
  36.  
  37. private List<TeamScore> currentTeamScore = new List<TeamScore>();
  38.  
  39.  
  40.  
  41. public CBFlagPlugin() {
  42.  
  43. this.secondsToCount = 3;
  44. this.sayOrYell = false;
  45.  
  46. this.updating = false;
  47. this.restarting = false;
  48.  
  49. this.autoRestartEnable = false;
  50. this.autoRestartDelay = 5;
  51.  
  52. this.m_isPluginEnabled = false;
  53. }
  54.  
  55. public string GetPluginName() {
  56. return "B-Flag Plugin";
  57. }
  58.  
  59. public string GetPluginVersion() {
  60. return "420.1.0.0";
  61. }
  62.  
  63. public string GetPluginAuthor() {
  64. return "J4nssent";
  65. }
  66.  
  67. public string GetPluginWebsite() {
  68. return "www.youtube.com/watch?v=dQw4w9WgXcQ";
  69. }
  70.  
  71. public string GetPluginDescription() {
  72. return @"
  73. <h2>Description</h2>
  74. <p>Provides a countdown. With the !count command. You can choose between say and yell.</p>
  75. <p>Now you can also change the team with a simple command and you can suicide youself.</p>
  76. <p>This program also provides an automatic restart, so you don't have to wait 45 seconds at the end of a match.</p>
  77.  
  78. <h2>Commands</h2>
  79. <blockquote><h4>@count</h4>Counts down</blockquote>
  80. <blockquote><h4>@moveme <i>team</i> </h4>Teamswitches player, <i>team </i> can be US or RU </blockquote>
  81. <blockquote><h4>@suicide</h4>Commit suicide</blockquote>
  82.  
  83. <h2>Settings</h2>
  84. <blockquote><h4>Enabled</h4>Enables/Disables AutoRestart</blockquote>
  85. <blockquote><h4>Scoreboard</h4>Number of seconds the scoreboard will appear before restarting.</blockquote>
  86.  
  87. <blockquote><h4>Seconds</h4>The number to count down from</blockquote>
  88. <blockquote><h4>Type (SayYell)</h4>False to say and True to yell the countdown.</blockquote>";
  89. }
  90.  
  91. public void OnPluginLoaded(string strHostName, string strPort, string strPRoConVersion) {
  92.  
  93. this.RegisterEvents(this.GetType().Name, "OnPlayerKilled", "OnRegisteredCommand", "OnUnregisteredCommand", "OnServerInfo" );
  94. }
  95.  
  96. public void OnPluginEnable() {
  97. this.ExecuteCommand("procon.protected.pluginconsole.write", "^bB-Flag Plugin ^2Enabled!");
  98.  
  99.  
  100. this.m_isPluginEnabled = true;
  101. this.RegisterAllCommands();
  102. }
  103.  
  104. public void OnPluginDisable() {
  105. this.ExecuteCommand("procon.protected.pluginconsole.write", "^bB-Flag Plugin ^1Disabled!" );
  106.  
  107. this.m_isPluginEnabled = false;
  108. this.UnregisterAllCommands();
  109. }
  110.  
  111. public List<CPluginVariable> GetDisplayPluginVariables() {
  112.  
  113. List<CPluginVariable> lstReturn = new List<CPluginVariable>();
  114.  
  115. lstReturn.Add(new CPluginVariable("Countdown|Seconds", typeof(int), secondsToCount));
  116. lstReturn.Add(new CPluginVariable("Countdown|Type (Say=false, Yell=true)", typeof(bool), sayOrYell));
  117. lstReturn.Add(new CPluginVariable("AutoRestart|Enabled", typeof(bool), autoRestartEnable));
  118. lstReturn.Add(new CPluginVariable("AutoRestart|Scoreboard", typeof(int), autoRestartDelay));
  119.  
  120. return lstReturn;
  121. }
  122.  
  123. public List<CPluginVariable> GetPluginVariables() {
  124. return GetDisplayPluginVariables();
  125. }
  126.  
  127. public void SetPluginVariable(string strVariable, string strValue) {
  128. if (Regex.Match(strVariable, @"Seconds").Success)
  129. {
  130. int tmpSecs = 2;
  131. int.TryParse(strValue, out tmpSecs);
  132. secondsToCount = tmpSecs;
  133. }
  134. else if (Regex.Match(strVariable, @"Type").Success)
  135. {
  136. bool tmpSayOrYell = false;
  137. Boolean.TryParse(strValue, out tmpSayOrYell);
  138. sayOrYell = tmpSayOrYell;
  139. }
  140. else if (Regex.Match(strVariable, @"Enabled").Success)
  141. {
  142. bool tmpAutoRestartEnable = false;
  143. Boolean.TryParse(strValue, out tmpAutoRestartEnable);
  144. autoRestartEnable = tmpAutoRestartEnable;
  145. }
  146. else if (Regex.Match(strVariable, @"Scoreboard").Success)
  147. {
  148. int tmpTime = 5;
  149. int.TryParse(strValue, out tmpTime);
  150. autoRestartDelay = tmpTime;
  151. }
  152. this.RegisterAllCommands();
  153. }
  154.  
  155. private void UnregisterAllCommands() {
  156.  
  157. this.UnregisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandCount", this.Listify<string>("@", "!", "#"), "count", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Counts down"));
  158.  
  159. 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"));
  160.  
  161. this.UnregisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandSuicide", this.Listify<string>("@", "!", "#"), "suicide", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Commit suicide"));
  162. }
  163.  
  164. private void RegisterAllCommands() {
  165.  
  166. if (this.m_isPluginEnabled == true) {
  167.  
  168. this.RegisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandCount", this.Listify<string>("@", "!", "#"), "count", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Counts down"));
  169.  
  170. 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"));
  171.  
  172. this.RegisterCommand(new MatchCommand("CBFlagPlugin", "OnCommandSuicide", this.Listify<string>("@", "!", "#"), "suicide", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Commit suicide"));
  173. }
  174. }
  175.  
  176. #region commands
  177.  
  178. public void OnCommandCount(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope) {
  179. if (this.sayOrYell == false) {
  180. for (int i = this.secondsToCount; i > 0; i--)
  181. {
  182. this.ExecuteCommand("procon.protected.send", "admin.say", i.ToString(), "all");
  183. }
  184. this.ExecuteCommand("procon.protected.send", "admin.say", "GO!", "all");
  185. }else{
  186. for (int i = this.secondsToCount; i > 0; i--)
  187. {
  188. if(i==3)
  189. {
  190. 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");
  191. }
  192. if(i==2)
  193. {
  194. 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");
  195. }
  196. if(i==1)
  197. {
  198. 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");
  199. }
  200. }
  201. this.ExecuteCommand("procon.protected.send", "admin.yell", "!!!!" + Environment.NewLine + "!!!!" + Environment.NewLine + "!!!!" + Environment.NewLine + "!!!!" + Environment.NewLine + "!!!!" + Environment.NewLine + "" + Environment.NewLine + "!!!!");
  202. }
  203. }
  204.  
  205. public void OnCommandMoveMe(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope) {
  206.  
  207. if (capCommand.MatchedArguments[0].Argument == "RU") {
  208.  
  209. this.ExecuteCommand("procon.protected.send", "admin.movePlayer", strSpeaker, "2", "1", "true");
  210.  
  211. } else if (capCommand.MatchedArguments[0].Argument == "US"){
  212.  
  213. this.ExecuteCommand("procon.protected.send", "admin.movePlayer", strSpeaker, "1", "1", "true");
  214.  
  215. }
  216. }
  217.  
  218. public void OnCommandSuicide(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope) {
  219.  
  220. this.ExecuteCommand("procon.protected.send", "admin.killPlayer", strSpeaker);
  221.  
  222. }
  223.  
  224. #endregion
  225.  
  226. #region events
  227.  
  228. public override void OnPlayerKilled (Kill kKillerVictimDetails) {
  229.  
  230. this.ExecuteCommand("procon.protected.send", "admin.killPlayer", kKillerVictimDetails.Victim.SoldierName);
  231.  
  232. }
  233.  
  234. public void OnServerInfo(CServerInfo csiServerInfo) {
  235.  
  236. if (this.autoRestartEnable == true && this.m_isPluginEnabled == true) {
  237.  
  238. this.currentTeamScore = new List<TeamScore>(csiServerInfo.TeamScores);
  239.  
  240. if (currentTeamScore.Count == 0 && restarting == false) {
  241.  
  242. UpdateTimer.Enabled = false;
  243. this.updating = false;
  244.  
  245. SetRestartTimer();
  246. this.restarting = true;
  247.  
  248. } else if ((currentTeamScore[0].Score < 10 || currentTeamScore[1].Score < 10) && this.updating == false ) {
  249.  
  250. SetUpdateTimer();
  251. this.updating = true;
  252. }
  253. }
  254. }
  255.  
  256. #endregion
  257.  
  258. private void SetUpdateTimer() {
  259.  
  260. UpdateTimer = new System.Timers.Timer(3000);
  261.  
  262. UpdateTimer.Elapsed += OnUpdate;
  263. UpdateTimer.AutoReset = true;
  264. UpdateTimer.Enabled = true;
  265.  
  266. }
  267.  
  268. private void SetRestartTimer() {
  269.  
  270. RestartTimer = new System.Timers.Timer(4000 + (this.autoRestartDelay * 1000));
  271.  
  272. RestartTimer.Elapsed += OnRestart;
  273. RestartTimer.Enabled = true;
  274.  
  275. }
  276.  
  277. private void OnUpdate(object source, ElapsedEventArgs e) {
  278.  
  279. this.ExecuteCommand("procon.protected.send", "serverInfo");
  280.  
  281. }
  282.  
  283. private void OnRestart(object source, ElapsedEventArgs e) {
  284.  
  285. this.ExecuteCommand("procon.protected.pluginconsole.write", "restarting...");
  286. this.ExecuteCommand("procon.protected.send", "mapList.restartRound");
  287.  
  288. RestartTimer.Enabled = false;
  289. this.restarting = false;
  290. }
  291. }
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement