eAR - Enhanced Autoendround

Discuss everything about Xymph's Aseco flavoured server control scripts for TM Forever / classic TMN and for TM² Canyon.

Moderators: Xymph, TM-Patrol

Post Reply
Nanir
cyclist
cyclist
Posts: 32
Joined: 25 Dec 2009 10:30
Owned TM-games: TMUF

eAR - Enhanced Autoendround

Post by Nanir » 25 Jan 2010 19:51

I have a server in Roundmode and was tired of players either incapable of finding the way, or not giving up. So i looked for a plugin to solve this. And found: Autoendround (viewtopic.php?p=157333#p157333)

But I wasnt completely fine with it, so i enhanced it.
Thx and credits for most of the code to nocturne.

New Features:
-a Message on start of each round that there is a timelimit
-autoskip if there were several unfinished rounds in a row(optional) number selectable
-chatcommand to reset this
-playerfinish disables timer and the visible clock for finishtimeout will run to 0.
-easy setting of the timelimit with a multiplicator
-2 different multiplicators for warmup and game

Known Bugs
-sometimes buggy during startup
-if you use autoqueue and restart aseco a the round will count as notfinished.
-in case the autoskip limit is reached because all have given up, the skip happens at the next start
-resertroundlimit currently no only admin command

Planned
-Add Support for Team and Cup Mode
-...


I hope some can make use of it :)

Code: Select all

<?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 = 3;

/** 
 * 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 = 2;

//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] $fff$iPlayer 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] $fff$iAdmin 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= '>[RoundTimer] $fff$iWe are using RoundTimer to set a timelimit';
  if ($round_max>0) {
      $msg .= ' and a limit of rounds.';
  }
  else
  {
      $msg .= '.';
  }
 	$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 = '>>[RoundTimer] $fff$iWarmUp Time-Limit: $f00' . $timer . ' min';
  }
  else
  {
    $minutes = floor($round_timer/60);
    $seconds = $round_timer%60;
    $timer = sprintf("%d:%02d",$minutes,$seconds); 
    $msg = '>>[RoundTimer] $fff$iTime-Limit: $f00' . $timer . ' min';
    if ($round_max>0 AND !$aseco->warmup_phase)
    {
      $msg.= '$fff No-Finish limit: $f00'.$round_counter.' / '.$round_max;
    }
  }
  $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;
   
   $warmup_timer = ($authortime * $warmup_factor); 
   $warmup_timer = ceil($warmup_timer+1)*10;
   
   $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', '>>[RoundTimer] $fff$iNo-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', '>>[RoundTimer] $fff$iNo-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', '>>[RoundTimer] $fff$iTime-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', '>>[RoundTimer] $fff$iWarmUp Time-Limit Reached.');
        $aseco->console_text('[RoundTimer] Warmup automatically ended after ' . $round_timer . 'secs...');
      }
      else
      {
        $aseco->client->query('ForceEndRound');
        $aseco->client->query('ChatSendServerMessage', '>>[RoundTimer] $fff$iTime-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] $fff$iNo 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', '>>[RoundTimer] $fff$iNo-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', '>>[RoundTimer] $fff$iAll 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;
   }
}
?>

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: eAR - Enhanced Autoendround

Post by nocturne » 26 Jan 2010 16:24

Ah, kinda of nifty... Honestly, I had never bothered running a rounds server until just recently, when I found out my original Aseco plugin didn't work to begin with, so I'm half-surprised the Xaseco version did either, hehe.. :lol:
Last edited by nocturne on 26 Jan 2010 22:14, edited 1 time in total.

Nanir
cyclist
cyclist
Posts: 32
Joined: 25 Dec 2009 10:30
Owned TM-games: TMUF

Re: eAR - Enhanced Autoendround

Post by Nanir » 26 Jan 2010 20:24

I hope you like the work I ve done with your code ;)

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: eAR - Enhanced Autoendround

Post by nocturne » 26 Jan 2010 21:21

As for team mode:

Code: Select all

   if ($aseco->server->gameinfo->mode == 0 || $aseco->server->gameinfo->mode == 2) {
      if ($rt_debug) {
         $aseco->console_text('[RoundTimer] In Rounds/Team Mode...');
      }
      return true;
Not sure how to add Cup Mode, as I can't find the mode number in the documentation:
game mode used between Rounds (0), TimeAttack (1), Team (2), Laps (3) and Stunts (4)
Edit: Found it... it's mode 5. Who would have guessed, hehe.

Xymph
Pit Crew
Pit Crew
Posts: 5650
Joined: 19 Aug 2007 12:58
Owned TM-games: TMN, TMU, TMF, TM²
Contact:

Re: eAR - Enhanced Autoendround

Post by Xymph » 26 Jan 2010 21:31

nocturne wrote:Not sure how to add Cup Mode, as I can't find the mode number in the documentation:
You must have used old documentation; the ListMethods.html included with the current dedicated version does list it, as does this.
Developer of XASECO for TMF/TMN ESWC & XASECO2 for TM²: see XAseco.org
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: eAR - Enhanced Autoendround

Post by nocturne » 26 Jan 2010 22:13

I was looking in the Dedicated readme, both from the server package and the gamers.org/tmf portal.

Xymph
Pit Crew
Pit Crew
Posts: 5650
Joined: 19 Aug 2007 12:58
Owned TM-games: TMN, TMU, TMF, TM²
Contact:

Re: eAR - Enhanced Autoendround

Post by Xymph » 26 Jan 2010 23:10

nocturne wrote:I was looking in the Dedicated readme, both from the server package and the gamers.org/tmf portal.
Yeah, that's marked as TMU because it isn't for TMF. :wink: Nadeo never updated it since the (classic) TMU days. The Methods list in the package and on the portal is accurate and complete though (I went through quite a few typo-fix iterations on that one with xbx throughout last year).
Developer of XASECO for TMF/TMN ESWC & XASECO2 for TM²: see XAseco.org
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: eAR - Enhanced Autoendround

Post by nocturne » 27 Jan 2010 16:53

Noticed a lil bug I think..

Code: Select all

   $round_timer = ($authortime * $game_factor);
   $round_timer = ceil($round_timer+1)*10;
   
   $warmup_timer = ($authortime * $warmup_factor); 
   $warmup_timer = ceil($warmup_timer+1)*10;
Don't you want to be adding 10 instead of multiplying? Might as well add that integer as a configurable 'buffer' variable while you're at it.

Nanir
cyclist
cyclist
Posts: 32
Joined: 25 Dec 2009 10:30
Owned TM-games: TMUF

Re: eAR - Enhanced Autoendround

Post by Nanir » 27 Jan 2010 18:48

It works exactly as I intended it to to ;)

You should quote the complete passage.

Code: Select all

$authortime = $result['AuthorTime'] / 10000;                           
   $round_timer = ($authortime * $game_factor);
   $round_timer = ceil($round_timer+1)*10;
   
   $warmup_timer = ($authortime * $warmup_factor);
   $warmup_timer = ceil($warmup_timer+1)*10;
I devide by 10k not only by 1k ;)
You can round to full 10 seconds unless you devide by 10, round and multiply afterwards with 10 again. And I am no friend of "dirty" times.
I checked it against several author times, and it does exactly what i wanted it to do. It runs on my own server ;)

And I did not intend a too hard time limit. Cause some author times are really out of reach for a lot. I just wanted a time limit to prevent idle players or players who refuse to give up and not finding the way, to annoy other players.
And i find it very annoying to join a server in rounds mode and see how long its been unused and seeing several players who finished once or twice and left on the scoreboard.
Thats the main reason I added the Skip feature. Just to make sure that you get a "fresh game" if you enter after a while where the server s been idle.

Nanir
cyclist
cyclist
Posts: 32
Joined: 25 Dec 2009 10:30
Owned TM-games: TMUF

Re: eAR - Enhanced Autoendround

Post by Nanir » 29 Jan 2010 13:09

I ll be off for at least 1 month, so if someone wants to continue it... feel free.

Olymptor
sunday driver
sunday driver
Posts: 59
Joined: 16 May 2009 00:15
Owned TM-games: TMUF, TMO, TMS

Re: eAR - Enhanced Autoendround

Post by Olymptor » 26 Jul 2010 22:38

Is it not possible to directly update an existing file in xaseco ?
(Of course a line where we can change factor of X author time)
Because this plugin is very good but i prefer original beacuse it displays the clock on right with time least.

Northern Lights
sunday driver
sunday driver
Posts: 64
Joined: 27 Apr 2010 17:30
Owned TM-games: TMU

Re: eAR - Enhanced Autoendround

Post by Northern Lights » 23 Feb 2011 11:37

Will this plugin allow me to run my server in Cup Mode and have a set time for the track as in Time Attack ... for example 6 minutes per track.

And will it also allow people to restart their run if they crash as in Time Attack ?

That for me is the ultimate plugin and a great server attraction. To have Cup Mode in Time Attack format where the quickest person gets the most points etc.

jamie_macdonald
TM-Patrol
TM-Patrol
Posts: 1612
Joined: 10 Jul 2008 19:48
Owned TM-games: TMUF, TMNF, TMS
Manialink(s): ET
Location: London, UK
Contact:

Re: eAR - Enhanced Autoendround

Post by jamie_macdonald » 23 Feb 2011 13:52

Hi Northern Lights ;)

I think that it will set a time limit as mentioned but as far as i am aware if in cup.rounds mode there is no way to force the player to the start line again (if the round continues with other players). Of course if all players finish the round starts afresh (after point counting).

So i think its a way of having a dual limit criteria in other modes (ie if points reached or time limit reached (whichever first) the match will end).

I could of course, be reading it wrong :thumbsup:

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: eAR - Enhanced Autoendround

Post by nocturne » 26 Feb 2011 20:07

You can tweak it for your own desired time limits... though with rounds/cup you can't quite restart like in TA, only respawn to last cp (which would be the start if the player hasn't cleared any cp's). Also, should follow the dialog in this thread concerned modes outside of Rounds. Guess it would be best to change the original checkRounds function to this:

Code: Select all

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;
	} elseif ($aseco->server->gameinfo->mode == 5) {
		if ($rt_debug) {
			$aseco->console_text('[RoundTimer] In Cup Mode...');
		}
		return true;
	} elseif ($aseco->server->gameinfo->mode == 2) {
		if ($rt_debug) {
			$aseco->console_text('[RoundTimer] In Team Mode...');
		}
		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;
	}
}
Chief Janitorial Supervisor of the Let'sRock! TM community : www.LetsRock-TM.com

Post Reply