Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.26 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. *
  5. * eAR - enhanced Autoend Round v0.9
  6. * by Nanir
  7. * www.apermo.de
  8. *
  9. * Based on:
  10. *
  11. * Round Auto-End plugin.
  12. * Ends the current round after a magically computed amount of time.
  13. * Created by -nocturne=-
  14. *
  15. *
  16. * Dependencies: none
  17. */
  18.  
  19. global $game_factor, $warmup_factor, $round_max;
  20. //Settings:
  21.  
  22. //How Many unfinished Rounds in a row to skip the Challenge?
  23. $round_max = 5;
  24.  
  25. /**
  26. * Timer is calculated: Authortime x Factor + 10 Seconds, rounded up to full 10 Seconds
  27. *
  28. * Example:
  29. *
  30. * Authortime: 33.85 s
  31. * Game Factor: 2
  32. * Timelimit = 33.85 s x 2 + 10 s = 77.7 s => 80 s => 1:20 min
  33. */
  34.  
  35. //Which Factor to multiply Author Time as timelimit for Game?
  36. $game_factor = 3;
  37.  
  38. //Which Factor to multiply Author Time as timelimit for Warmup?
  39. $warmup_factor = 2.5;
  40.  
  41.  
  42. Aseco::registerEvent('onNewChallenge', 'set_timer');
  43. Aseco::registerEvent('onBeginRound', 'start_timer');
  44. Aseco::registerEvent('onMainLoop', 'check_timer');
  45. Aseco::registerEvent('onEndRound', 'disable_timer');
  46. Aseco::registerEvent('onPlayerFinish', 'player_finished');
  47. Aseco::registerEvent('onPlayerConnect', 'explain_timelimit');
  48.  
  49. Aseco::addChatCommand('resetroundlimit', 'Resets the Round Limit Counter', true);
  50.  
  51. global $IsInRounds, $round_timer,$warmup_timer, $round_time, $round_active, $rt_debug, $round_max, $round_counter, $player_finished,$nooneplayskip;
  52.  
  53. $rt_debug = false;
  54.  
  55. //Redundancy - Don't Touch
  56. $IsInRounds = false;
  57. $round_timer = 0;
  58. $round_time = 0;
  59. $warmup_timer = 0;
  60. $round_counter = 0;
  61. $round_active = false;
  62. $player_finished = false;
  63. $nooneplayskip = false;
  64.  
  65.  
  66.  
  67. function player_finished($aseco, $finish_item)
  68. {
  69. global $IsInRounds, $round_timer, $round_active, $rt_debug, $round_counter, $round_max,$player_finished;
  70. if (!$IsInRounds) {
  71. return;
  72. }
  73.  
  74. if($finish_item->score > 0)
  75. {
  76. $player_finished=true;
  77. if ($round_max>0 AND $round_counter>0)
  78. {
  79. $round_counter=0;
  80. /*
  81. $msg = '>>[RoundTimer] $f00Player finished! No-Finish Limit is reset.';
  82. $aseco->client->query('ChatSendServerMessage', $msg);
  83. */
  84. }
  85. if ($rt_debug) {
  86. //$aseco->console_text('[RoundTimer] Player Finished');
  87. }
  88. }
  89. else
  90. {
  91. if ($rt_debug) {
  92. //$aseco->console_text('[RoundTimer] Player Gave Up');
  93. }
  94. }
  95. }
  96.  
  97. function chat_resetroundlimit($aseco)
  98. {
  99. global $IsInRounds, $round_timer, $round_active, $rt_debug, $round_counter, $round_max;
  100. if (!$IsInRounds) {
  101. return;
  102. }
  103. $round_counter=0;
  104. /*
  105. $msg = '>>[RoundTimer] $f00Admin resets No-Finish Limit';
  106. $aseco->client->query('ChatSendServerMessage', $msg);
  107. */
  108. }
  109.  
  110. // called @ onPlayerConnect
  111. function explain_timelimit($aseco, $player) {
  112. global $IsInRounds, $round_timer, $round_active, $rt_debug, $round_counter, $round_max;
  113.  
  114. if (!$IsInRounds) {
  115. return;
  116. }
  117.  
  118. // if starting up, bail out immediately
  119. if ($aseco->startup_phase) return;
  120. $msg= '$f00Note: $fffTimelimit $f005 $fffMinutes & No-finish Limit $f005 $fffRounds !';
  121. $aseco->client->query('ChatSendServerMessageToLogin', $msg, $player->login);
  122. //post_limits($aseco);
  123.  
  124.  
  125. } // explain_timelimit
  126.  
  127. function post_limits($aseco) {
  128. global $round_timer,$warmup_timer, $round_counter, $round_max;;
  129.  
  130. if ($aseco->warmup_phase)
  131. {
  132. /*
  133. $minutes = floor($warmup_timer/60);
  134. $seconds = $warmup_timer%60;
  135. $timer = sprintf("%d:%02d",$minutes,$seconds);
  136. $msg = '$f00WarmUp Time-Limit: $f00' . $timer . ' min';
  137. */
  138. }
  139. else
  140. {
  141. /*
  142. $minutes = floor($round_timer/60);
  143. $seconds = $round_timer%60;
  144. $timer = sprintf("%d:%02d",$minutes,$seconds);
  145. $msg = '$f00Time-Limit: $f00' . $timer . ' min';
  146. */
  147. if ($round_max>0 AND !$aseco->warmup_phase) {
  148. if ($round_counter == "0") {
  149. } elseif ($round_counter == "5") {
  150. } else {
  151. $msg.= '$f00No-Finish Limit: $fff'.$round_counter.'/'.$round_max;
  152. $aseco->client->query('ChatSendServerMessage', $msg);
  153. }
  154. }
  155. }
  156. //$aseco->client->query('ChatSendServerMessage', $msg);
  157.  
  158. /* OLD
  159. if ($aseco->warmup_phase)
  160. {
  161.  
  162. $minutes = floor($warmup_timer/60);
  163. $seconds = $warmup_timer%60;
  164. $timer = sprintf("%d:%02d",$minutes,$seconds);
  165. $msg = '$f00WarmUp Time-Limit: $f00' . $timer . ' min';
  166.  
  167. }
  168. else
  169. {
  170.  
  171. $minutes = floor($round_timer/60);
  172. $seconds = $round_timer%60;
  173. $timer = sprintf("%d:%02d",$minutes,$seconds);
  174. $msg = '$f00Time-Limit: $f00' . $timer . ' min';
  175.  
  176. if ($round_max>0 AND !$aseco->warmup_phase)
  177. {
  178. $msg.= '$f00No-Finish Limit: $fff'.$round_counter.'/'.$round_max;
  179. $aseco->client->query('ChatSendServerMessage', $msg);
  180. }
  181. }
  182. //$aseco->client->query('ChatSendServerMessage', $msg);
  183. */
  184. }
  185.  
  186.  
  187. function set_timer($aseco) {
  188. global $IsInRounds, $round_timer, $warmup_timer,$game_factor,$warmup_factor, $round_active, $rt_debug, $round_max, $round_counter, $nooneplayskip;
  189. $round_active = false; //probably redundant, but oh well
  190. $IsInRounds = checkRounds($aseco);
  191.  
  192. if (!$IsInRounds) {
  193. return;
  194. }
  195. $nooneplayskip = false;
  196.  
  197. /*
  198. $aseco->client->query('GetCurrentChallengeInfo');
  199. $result = $aseco->client->getResponse();
  200. $authortime = $result['AuthorTime'] / 10000;
  201. $round_timer = ($authortime * $game_factor);
  202. $round_timer = ceil($round_timer+1)*10;
  203. */
  204. $round_timer = "300";
  205.  
  206. /*
  207. $warmup_timer = ($authortime * $warmup_factor);
  208. $warmup_timer = ceil($warmup_timer+1)*10;
  209. */
  210. $warmup_timer = "300";
  211.  
  212. //$aseco->console_text('[RoundTimer] Set to ' . $round_timer . ' s Warmup to '. $warmup_timer. ' s');
  213.  
  214. $round_counter=0;
  215. }
  216.  
  217. function start_timer($aseco) {
  218. global $IsInRounds, $round_time, $round_timer,$warmup_timer, $round_active, $round_counter, $round_max,$player_finished,$rt_debug;
  219.  
  220. if ($IsInRounds) {
  221. if (!$aseco->warmup_phase AND $round_max>0 AND $round_counter>=$round_max) {
  222. $aseco->client->query('NextChallenge');
  223. $aseco->client->query('ChatSendServerMessage', '$f00No-Finish Limit reached! Challenge skipped.');
  224. //$aseco->console_text('[RoundTimer] Challenge automatically skipped after ' . $round_max . 'runs without finish in a row...');
  225. }
  226.  
  227. $player_finished=false;
  228.  
  229. if ($aseco->warmup_phase) {
  230. // Warmup Phase, use Warmup Timer
  231. $round_time = $warmup_timer + time()+3;//+3 for the Countdown, the Timer Starts at -3 Seconds and would end 3 Seconds earlier than expected
  232. }
  233. else
  234. {
  235. $round_time = $round_timer + time()+3;//+3 for the Countdown, the Timer Starts at -3 Seconds and would end 3 Seconds earlier than expected
  236.  
  237. }
  238. $round_active = true;
  239.  
  240. post_limits($aseco);
  241.  
  242. if ($rt_debug) {
  243. //$aseco->console_text('[RoundTimer] Round Started!');
  244. }
  245. }
  246. }
  247.  
  248. function check_timer($aseco) {
  249. global $IsInRounds, $round_active, $round_time, $round_timer,$round_counter,$round_max,$player_finished,$rt_debug,$nooneplayskip;
  250.  
  251. if ($IsInRounds && $round_active && (time() > $round_time) && !$player_finished) {
  252.  
  253. if (!$aseco->warmup_phase AND $round_max>0)
  254. {
  255. $round_counter++;
  256. if ($round_counter>=$round_max) {
  257. $aseco->client->query('NextChallenge');
  258. $aseco->client->query('ChatSendServerMessage', '$f00No-Finish Limit reached! Challenge skipped.');
  259. //$aseco->console_text('[RoundTimer] Challenge automatically skipped after ' . $round_max . 'runs without finish in a row...');
  260. }
  261. else
  262. {
  263. $aseco->client->query('ForceEndRound');
  264. $aseco->client->query('ChatSendServerMessage', '$f00Time-Limit Reached. No-Finish limit: $f00'.$round_counter.'/'.$round_max);
  265. //$aseco->console_text('[RoundTimer] No-Finish limit: '.$round_counter.' / '.$round_max);
  266.  
  267. }
  268. }
  269. elseif($aseco->warmup_phase)
  270. {
  271. $aseco->client->query('ForceEndRound');
  272. $aseco->client->query('ChatSendServerMessage', '$f00WarmUp Time-Limit Reached.');
  273. //$aseco->console_text('[RoundTimer] Warmup automatically ended after ' . $round_timer . 'secs...');
  274. }
  275. else
  276. {
  277. $aseco->client->query('ForceEndRound');
  278. $aseco->client->query('ChatSendServerMessage', '$f00Time-Limit Reached.');
  279. //$aseco->console_text('[RoundTimer] Round automatically ended after ' . $round_timer . 'secs...');
  280. }
  281.  
  282. $round_active = false;
  283. }
  284. elseif (!$nooneplayskip AND $IsInRounds AND !$aseco->warmup_phase AND !$round_active AND (time() > $round_time+30))
  285. {
  286. $nooneplayskip = true;
  287. $aseco->client->query('NextChallenge');
  288. //$aseco->client->query('ChatSendServerMessage', '>>[RoundTimer] $f00No one playing! Challenge skipped.');
  289. //$aseco->console_text('[RoundTimer] No one Playing Challenge automatically skipped...');
  290. }
  291. }
  292.  
  293. function disable_timer($aseco) {
  294. global $IsInRounds, $round_active, $rt_debug, $round_counter, $round_max,$player_finished;
  295.  
  296.  
  297. if ($IsInRounds && $round_active) {
  298.  
  299. if (!$aseco->warmup_phase AND $round_max>0 AND !$player_finished)
  300. {
  301. $round_counter++;
  302. if ($round_counter>=$round_max) {
  303. $aseco->client->query('NextChallenge');
  304. //$aseco->client->query('ChatSendServerMessage', '$f00No-Finish limit reached! Challenge will be skipped.');
  305. //$aseco->console_text('[RoundTimer] Challenge automatically skipped after ' . $round_max . 'runs without finish...');
  306. }
  307. else
  308. {
  309. //$aseco->client->query('ChatSendServerMessage', '$f00All Players gave up. No-Finish limit: $f00'.$round_counter.' / '.$round_max);
  310. }
  311. }
  312.  
  313. $round_active = false;
  314.  
  315. if ($rt_debug) {
  316. //$aseco->console_text('[RoundTimer] End of round...');
  317. }
  318. }
  319. }
  320.  
  321. function checkRounds($aseco) {
  322. global $rt_debug, $round_timer;
  323.  
  324. if ($aseco->server->gameinfo->mode == 0) {
  325. if ($rt_debug) {
  326. //$aseco->console_text('[RoundTimer] In Rounds...');
  327. }
  328. return true;
  329. } else {
  330. if ($round_timer) {
  331. unset($round_timer);
  332. }
  333.  
  334. if ($rt_debug) {
  335. //$aseco->console_text('[RoundTimer] Not in rounds... Should not do anything.');
  336. }
  337. return false;
  338. }
  339. }
  340. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement