[Plugin] TA Auto Track Timer

Post here every finished plugin

Moderator: NADEO

Post Reply
nocturne
Posts: 208
Joined: 23 Jun 2010, 21:31

[Plugin] TA Auto Track Timer

Post by nocturne »

First of all, as with any of my codings/plugins -- use at your own risk. ;)

Also.. I haven't had the chance to even run this yet -- but I think it'll work.. :thumbsup:

Config:

Code: Select all

plug-ins.load = nocturne\TA_AutoTimer

; TA Track Timer equation:  (author_time X multiplier) + adjustment
;plugins.nocturne\TA_AutoTimer.debug = false      ; enable/disable debug reporting
;plugins.nocturne\TA_AutoTimer.multiplier = 6      ; set the track time multiplier
;plugins.nocturne\TA_AutoTimer.adjustment = 60     ; set the track time adjustment (+/-)
;plugins.nocturne\TA_AutoTimer.min_time = 180      ; set the max track time
;plugins.nocturne\TA_AutoTimer.max_time = 360      ; set the min track time
Plugin [/libraries/ManiaLivePlugins/nocturne/TA_AutoTimer.php]

Code: Select all

<?php
/*
 TA Auto Track Timer v.anchiote for ML2 r27x+
	-by -nocturne=-  www.letsrock-tm.com
	
	*no licensing BS, no warranty*
	
	credits:  Nobody really...  kind of common sense.  But props go to Mistral, I believe,
				who made the first version back in TMN


*/


namespace ManiaLivePlugins\nocturne\TA_AutoTimer;


use ManiaLive\Config\Loader;
use ManiaLive\Data\Storage;				//dunno if this is needed
use ManiaLive\DedicatedApi\Connection;
use ManiaLive\Utilities\Console;
use ManiaLive\Event\Dispatcher;

class TA_AutoTimer extends \ManiaLive\PluginHandler\Plugin {

	static $debug = false;
	static $multiplier = 6;
	static $adjustment = 60;
	static $min_time = 180;
	static $max_time = 360;
	
		
	function onEndMap () {
		if ($this->connection->getNextGameInfo()->gameMode == 2) {
			$nextChallenge = $this->connection->getNextMapInfo();
			$authorTime = $nextChallenge->authorTime;
			if ($authorTime){
				$authorTime = $authorTime * 1000;									// think we need this...  ms->secs
				$time = round(($this->multiplier * $authorTime) + $adjustment);
				if ($time < $this->min_time) {
					$time = $this->min_time;
				}
				if ($time > $this->max_time) {
					$time = $this->max_time;
				}
			if ($this->debug) Console::println('['.date('H:i:s').'] [TA_AutoTimer] Timer active:  AT: '.$authorTime.'secs ;  Computed TimeLimit: '.$time.'secs...');
			$this->connection->setTimeAttackLimit($time);
			}
		} else {
			if ($this->debug) Console::println('['.date('H:i:s').'] [TA_AutoTimer] Timer inactive:  Not in TimeAttack mode...');
		}
	}
	
}

?>
Edit: FWIW, this should also run on previous versions of ML and on TMF with a simple edit.. I believe you just need change this:

Code: Select all

	function onEndMap () {
		if ($this->connection->getNextGameInfo()->gameMode == 2) {
			$nextChallenge = $this->connection->getNextMapInfo();
to this:

Code: Select all

	function onEndChallenge () {
		if ($this->connection->getNextGameInfo()->gameMode ==1) {
			$nextChallenge = $this->connection->getNextChallengeInfo();
Re-Edit: Another note... should place the plugin load/config lines at the bottom of your config, especially when running MLEPP. Lacking any more knowledge on how the plugin events are handled, I can only assume ML handles them in the order in which they were loaded, so loading this plugin behind a Jukebox plugin should result in this plugin supporting track timing when a track is queued for restart -- or at least in a perfect world.

To devs, what events come after EndChallenge before the end of the challenge, if any (I'm sure there's a StatusChanged event that would fit the bill)..? Is there anything equivalent to the old 'onPlayerWins'?
reaby
Posts: 956
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

Re: [Plugin] TA Auto Track Timer

Post by reaby »

To devs, what events come after EndChallenge before the end of the challenge, if any (I'm sure there's a StatusChanged event that would fit the bill)..? Is there anything equivalent to the old 'onPlayerWins'?
You can use onStatusChanged($statusCode, $statusName). Found out that one can use status code 6 safely.
Manialive has all the data cached at object which you can access $this->storage, but for safety (especially when using onStatusChange event) you should propably use direct calls to dedicated.

if you enable storage events, you can use callback onPlayerNewBestTime(player $player, int $best_old, int $best_new)
thoght i'm not sure if this is what you are looking for.
nocturne
Posts: 208
Joined: 23 Jun 2010, 21:31

Re: [Plugin] TA Auto Track Timer

Post by nocturne »

Status 6 should do quite nicely... thx. :thumbsup:

I don't see the need to use player times -- the author time should work best, just in case a single player finds a ridiculous cut or something along those lines. And I figure I might as well fetch the info directly rather than use the storage objects -- it only occurs once a round, and doesn't run in any loops or anything.

Though, a new 'onGameModeChanged' event in ML would be quite handy.. hehe
Post Reply

Return to “ManiaLive Plugins”

Who is online

Users browsing this forum: No registered users and 1 guest