Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * eAR - enhanced Autoend Round v0.9
- * by Nanir
- * www.apermo.de
- *
- * Based on:
- *
- * Round Auto-End plugin.
- * Ends the current round after a magically computed amount of time.
- * Created by -nocturne=-
- *
- *
- * Dependencies: none
- */
- global $game_factor, $warmup_factor, $round_max;
- //Settings:
- //How Many unfinished Rounds in a row to skip the Challenge?
- $round_max = 5;
- /**
- * Timer is calculated: Authortime x Factor + 10 Seconds, rounded up to full 10 Seconds
- *
- * Example:
- *
- * Authortime: 33.85 s
- * Game Factor: 2
- * Timelimit = 33.85 s x 2 + 10 s = 77.7 s => 80 s => 1:20 min
- */
- //Which Factor to multiply Author Time as timelimit for Game?
- $game_factor = 3;
- //Which Factor to multiply Author Time as timelimit for Warmup?
- $warmup_factor = 2.5;
- Aseco::registerEvent('onNewChallenge', 'set_timer');
- Aseco::registerEvent('onBeginRound', 'start_timer');
- Aseco::registerEvent('onMainLoop', 'check_timer');
- Aseco::registerEvent('onEndRound', 'disable_timer');
- Aseco::registerEvent('onPlayerFinish', 'player_finished');
- Aseco::registerEvent('onPlayerConnect', 'explain_timelimit');
- Aseco::addChatCommand('resetroundlimit', 'Resets the Round Limit Counter', true);
- global $IsInRounds, $round_timer,$warmup_timer, $round_time, $round_active, $rt_debug, $round_max, $round_counter, $player_finished,$nooneplayskip;
- $rt_debug = false;
- //Redundancy - Don't Touch
- $IsInRounds = false;
- $round_timer = 0;
- $round_time = 0;
- $warmup_timer = 0;
- $round_counter = 0;
- $round_active = false;
- $player_finished = false;
- $nooneplayskip = false;
- function player_finished($aseco, $finish_item)
- {
- global $IsInRounds, $round_timer, $round_active, $rt_debug, $round_counter, $round_max,$player_finished;
- if (!$IsInRounds) {
- return;
- }
- if($finish_item->score > 0)
- {
- $player_finished=true;
- if ($round_max>0 AND $round_counter>0)
- {
- $round_counter=0;
- /*
- $msg = '>>[RoundTimer] $f00Player finished! No-Finish Limit is reset.';
- $aseco->client->query('ChatSendServerMessage', $msg);
- */
- }
- if ($rt_debug) {
- //$aseco->console_text('[RoundTimer] Player Finished');
- }
- }
- else
- {
- if ($rt_debug) {
- //$aseco->console_text('[RoundTimer] Player Gave Up');
- }
- }
- }
- function chat_resetroundlimit($aseco)
- {
- global $IsInRounds, $round_timer, $round_active, $rt_debug, $round_counter, $round_max;
- if (!$IsInRounds) {
- return;
- }
- $round_counter=0;
- /*
- $msg = '>>[RoundTimer] $f00Admin resets No-Finish Limit';
- $aseco->client->query('ChatSendServerMessage', $msg);
- */
- }
- // called @ onPlayerConnect
- function explain_timelimit($aseco, $player) {
- global $IsInRounds, $round_timer, $round_active, $rt_debug, $round_counter, $round_max;
- if (!$IsInRounds) {
- return;
- }
- // if starting up, bail out immediately
- if ($aseco->startup_phase) return;
- $msg= '$f00Note: $fffTimelimit $f005 $fffMinutes & No-finish Limit $f005 $fffRounds !';
- $aseco->client->query('ChatSendServerMessageToLogin', $msg, $player->login);
- //post_limits($aseco);
- } // explain_timelimit
- function post_limits($aseco) {
- global $round_timer,$warmup_timer, $round_counter, $round_max;;
- if ($aseco->warmup_phase)
- {
- /*
- $minutes = floor($warmup_timer/60);
- $seconds = $warmup_timer%60;
- $timer = sprintf("%d:%02d",$minutes,$seconds);
- $msg = '$f00WarmUp Time-Limit: $f00' . $timer . ' min';
- */
- }
- else
- {
- /*
- $minutes = floor($round_timer/60);
- $seconds = $round_timer%60;
- $timer = sprintf("%d:%02d",$minutes,$seconds);
- $msg = '$f00Time-Limit: $f00' . $timer . ' min';
- */
- if ($round_max>0 AND !$aseco->warmup_phase) {
- if ($round_counter == "0") {
- } elseif ($round_counter == "5") {
- } else {
- $msg.= '$f00No-Finish Limit: $fff'.$round_counter.'/'.$round_max;
- $aseco->client->query('ChatSendServerMessage', $msg);
- }
- }
- }
- //$aseco->client->query('ChatSendServerMessage', $msg);
- /* OLD
- if ($aseco->warmup_phase)
- {
- $minutes = floor($warmup_timer/60);
- $seconds = $warmup_timer%60;
- $timer = sprintf("%d:%02d",$minutes,$seconds);
- $msg = '$f00WarmUp Time-Limit: $f00' . $timer . ' min';
- }
- else
- {
- $minutes = floor($round_timer/60);
- $seconds = $round_timer%60;
- $timer = sprintf("%d:%02d",$minutes,$seconds);
- $msg = '$f00Time-Limit: $f00' . $timer . ' min';
- if ($round_max>0 AND !$aseco->warmup_phase)
- {
- $msg.= '$f00No-Finish Limit: $fff'.$round_counter.'/'.$round_max;
- $aseco->client->query('ChatSendServerMessage', $msg);
- }
- }
- //$aseco->client->query('ChatSendServerMessage', $msg);
- */
- }
- function set_timer($aseco) {
- global $IsInRounds, $round_timer, $warmup_timer,$game_factor,$warmup_factor, $round_active, $rt_debug, $round_max, $round_counter, $nooneplayskip;
- $round_active = false; //probably redundant, but oh well
- $IsInRounds = checkRounds($aseco);
- if (!$IsInRounds) {
- return;
- }
- $nooneplayskip = false;
- /*
- $aseco->client->query('GetCurrentChallengeInfo');
- $result = $aseco->client->getResponse();
- $authortime = $result['AuthorTime'] / 10000;
- $round_timer = ($authortime * $game_factor);
- $round_timer = ceil($round_timer+1)*10;
- */
- $round_timer = "300";
- /*
- $warmup_timer = ($authortime * $warmup_factor);
- $warmup_timer = ceil($warmup_timer+1)*10;
- */
- $warmup_timer = "300";
- //$aseco->console_text('[RoundTimer] Set to ' . $round_timer . ' s Warmup to '. $warmup_timer. ' s');
- $round_counter=0;
- }
- function start_timer($aseco) {
- global $IsInRounds, $round_time, $round_timer,$warmup_timer, $round_active, $round_counter, $round_max,$player_finished,$rt_debug;
- if ($IsInRounds) {
- if (!$aseco->warmup_phase AND $round_max>0 AND $round_counter>=$round_max) {
- $aseco->client->query('NextChallenge');
- $aseco->client->query('ChatSendServerMessage', '$f00No-Finish Limit reached! Challenge skipped.');
- //$aseco->console_text('[RoundTimer] Challenge automatically skipped after ' . $round_max . 'runs without finish in a row...');
- }
- $player_finished=false;
- if ($aseco->warmup_phase) {
- // Warmup Phase, use Warmup Timer
- $round_time = $warmup_timer + time()+3;//+3 for the Countdown, the Timer Starts at -3 Seconds and would end 3 Seconds earlier than expected
- }
- else
- {
- $round_time = $round_timer + time()+3;//+3 for the Countdown, the Timer Starts at -3 Seconds and would end 3 Seconds earlier than expected
- }
- $round_active = true;
- post_limits($aseco);
- if ($rt_debug) {
- //$aseco->console_text('[RoundTimer] Round Started!');
- }
- }
- }
- function check_timer($aseco) {
- global $IsInRounds, $round_active, $round_time, $round_timer,$round_counter,$round_max,$player_finished,$rt_debug,$nooneplayskip;
- if ($IsInRounds && $round_active && (time() > $round_time) && !$player_finished) {
- if (!$aseco->warmup_phase AND $round_max>0)
- {
- $round_counter++;
- if ($round_counter>=$round_max) {
- $aseco->client->query('NextChallenge');
- $aseco->client->query('ChatSendServerMessage', '$f00No-Finish Limit reached! Challenge skipped.');
- //$aseco->console_text('[RoundTimer] Challenge automatically skipped after ' . $round_max . 'runs without finish in a row...');
- }
- else
- {
- $aseco->client->query('ForceEndRound');
- $aseco->client->query('ChatSendServerMessage', '$f00Time-Limit Reached. No-Finish limit: $f00'.$round_counter.'/'.$round_max);
- //$aseco->console_text('[RoundTimer] No-Finish limit: '.$round_counter.' / '.$round_max);
- }
- }
- elseif($aseco->warmup_phase)
- {
- $aseco->client->query('ForceEndRound');
- $aseco->client->query('ChatSendServerMessage', '$f00WarmUp Time-Limit Reached.');
- //$aseco->console_text('[RoundTimer] Warmup automatically ended after ' . $round_timer . 'secs...');
- }
- else
- {
- $aseco->client->query('ForceEndRound');
- $aseco->client->query('ChatSendServerMessage', '$f00Time-Limit Reached.');
- //$aseco->console_text('[RoundTimer] Round automatically ended after ' . $round_timer . 'secs...');
- }
- $round_active = false;
- }
- elseif (!$nooneplayskip AND $IsInRounds AND !$aseco->warmup_phase AND !$round_active AND (time() > $round_time+30))
- {
- $nooneplayskip = true;
- $aseco->client->query('NextChallenge');
- //$aseco->client->query('ChatSendServerMessage', '>>[RoundTimer] $f00No one playing! Challenge skipped.');
- //$aseco->console_text('[RoundTimer] No one Playing Challenge automatically skipped...');
- }
- }
- function disable_timer($aseco) {
- global $IsInRounds, $round_active, $rt_debug, $round_counter, $round_max,$player_finished;
- if ($IsInRounds && $round_active) {
- if (!$aseco->warmup_phase AND $round_max>0 AND !$player_finished)
- {
- $round_counter++;
- if ($round_counter>=$round_max) {
- $aseco->client->query('NextChallenge');
- //$aseco->client->query('ChatSendServerMessage', '$f00No-Finish limit reached! Challenge will be skipped.');
- //$aseco->console_text('[RoundTimer] Challenge automatically skipped after ' . $round_max . 'runs without finish...');
- }
- else
- {
- //$aseco->client->query('ChatSendServerMessage', '$f00All Players gave up. No-Finish limit: $f00'.$round_counter.' / '.$round_max);
- }
- }
- $round_active = false;
- if ($rt_debug) {
- //$aseco->console_text('[RoundTimer] End of round...');
- }
- }
- }
- function checkRounds($aseco) {
- global $rt_debug, $round_timer;
- if ($aseco->server->gameinfo->mode == 0) {
- if ($rt_debug) {
- //$aseco->console_text('[RoundTimer] In Rounds...');
- }
- return true;
- } else {
- if ($round_timer) {
- unset($round_timer);
- }
- if ($rt_debug) {
- //$aseco->console_text('[RoundTimer] Not in rounds... Should not do anything.');
- }
- return false;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement