Autotime help

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
dago
sunday driver
sunday driver
Posts: 61
Joined: 20 Feb 2009 18:43
Owned TM-games: tmuf

Autotime help

Post by dago » 04 Aug 2009 17:39

Autotime plugin seem tu adjust the time on the up side only.
It never bring it back down.

Any thought?

Xaseco 1.09
Dont know witch version of autotime but i have autotime.xml

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>

<autotime>

	<!-- Set the multiplicator for author time (e.g. 6x author -->

	<!-- time = new timelimit); set to 0 to disable function   -->

	<multiplicator>6</multiplicator>

	<!-- Set minimum timelimit in minutes -->

	<mintime>3.5</mintime>

	<!-- Set maximum timelimit in minutes -->

	<maxtime>5</maxtime>

	<!-- Set default timelimit in minutes if any error occurs -->

	<defaulttime>3.5</defaulttime>

	<!-- 2 = in TMF message window, 1 = in chat, 0 = none -->

	<display>1</display>

	<message>{#server}>> Set {1} timelimit for {#highlite}{2}{#server} : {#highlite}{3}{#server} (Author time: {#highlite}{4}{#server})</message>

</autotime>

Code: Select all

<?php
/* vim: set noexpandtab tabstop=2 softtabstop=2 shiftwidth=2: */

/**
 * Auto TimeLimit plugin.
 * Changes Timelimit for TimeAttack dynamically depending on the next
 * track's author time.
 *
 * Original by ck|cyrus
 * Rewrite by Xymph
 *
 * Dependencies: none (but must be after plugin.rasp_jukebox.php in plugins.xml)
 */

Aseco::registerEvent('onSync', 'load_atlconfig');
Aseco::registerEvent('onEndRace', 'autotimelimit');

global $atl_config, $atl_active, $atl_restart;

// load ATL configuration
function load_atlconfig($aseco) {
	global $atl_config, $atl_active, $atl_restart;

	// initialize flags
	$atl_active = false;
	$atl_restart = false;

	// load config file
	$config_file = 'autotime.xml';
	if (file_exists($config_file)) {
		if ($xml = $aseco->xml_parser->parseXml($config_file)) {
			$atl_config = $xml['AUTOTIME'];
			$atl_active = true;
		} else {
			trigger_error('[ATL] Could not read/parse config file ' . $config_file . ' !', E_USER_WARNING);
		}
	} else {
		trigger_error('[ATL] Could not find config file ' . $config_file . ' !', E_USER_WARNING);
	}
}  // load_atlconfig

// called @ onEndRace
function autotimelimit($aseco, $data) {
	global $atl_config, $atl_active, $atl_restart;

	// if not active, bail out immediately
	if (!$atl_active) return;
	// if restarting, bail out immediately
	if ($atl_restart) {
		$atl_restart = false;
		return;
	}

	// get next game settings
	$aseco->client->query('GetNextGameInfo');
	$nextgame = $aseco->client->getResponse();

	// check for TimeAttack on next track
	if ($nextgame['GameMode'] == 1) {
		// check if auto timelimit enabled
		if ($atl_config['MULTIPLICATOR'][0] > 0) {
			// check if at least one active player on the server
			if (active_player($aseco)) {
				// get next track details
				$challenge = get_trackinfo($aseco, 1);
				$newtime = intval($challenge->authortime);
			} else {
				// server already switched so get current track name
				$challenge = get_trackinfo($aseco, 0);
				$newtime = 0;  // force default
				$newtime = intval($challenge->authortime);
			}

			// compute new timelimit
			if ($newtime <= 0) {
				$newtime = $atl_config['DEFAULTTIME'][0] * 60 * 1000;
				$tag = 'default';
			} else {
				$newtime *= $atl_config['MULTIPLICATOR'][0];
				$newtime -= ($newtime % 1000);  // round down to seconds
				$tag = 'new';
			}
			// check for min/max times
			if ($newtime < $atl_config['MINTIME'][0] * 60 * 1000) {
				$newtime = $atl_config['MINTIME'][0] * 60 * 1000;
				$tag = 'min';
			} elseif ($newtime > $atl_config['MAXTIME'][0] * 60 * 1000) {
				$newtime = $atl_config['MAXTIME'][0] * 60 * 1000;
				$tag = 'max';
			}

			// set and log timelimit (strip .00 sec)
			$aseco->client->addcall('SetTimeAttackLimit', array($newtime));
			$aseco->console('set {1} timelimit for [{2}]: {3} (Author time: {4})',
			                $tag, stripColors($challenge->name, false),
			                substr(formatTime($newtime), 0, -3),
			                formatTime($challenge->authortime));

			// display timelimit (strip .00 sec)
			$message = formatText($atl_config['MESSAGE'][0], $tag,
			                      stripColors($challenge->name),
			                      substr(formatTime($newtime), 0, -3),
			                      formatTime($challenge->authortime));
			if ($atl_config['DISPLAY'][0] == 2 && function_exists('send_window_message'))
				send_window_message($aseco, $message, true);
			elseif ($atl_config['DISPLAY'][0] > 0)
				$aseco->client->query('ChatSendServerMessage', $aseco->formatColors($message));
		}
	}
}  // autotimelimit

// get info on current/next track
function get_trackinfo($aseco, $offset) {

	// get current/next track using /nextmap algorithm
	if ($aseco->server->getGame() != 'TMF') {
		$aseco->client->query('GetCurrentChallengeIndex');
		$trkid = $aseco->client->getResponse();
		$trkid += $offset;
		$aseco->client->resetError();
		$rtn = $aseco->client->query('GetChallengeList', 1, $trkid);
		$track = $aseco->client->getResponse();
		if ($aseco->client->isError()) {
			// get first track
			$rtn = $aseco->client->query('GetChallengeList', 1, 0);
			$track = $aseco->client->getResponse();
		}
	} else {  // TMF
		if ($offset == 1)
			$aseco->client->query('GetNextChallengeIndex');
		else
			$aseco->client->query('GetCurrentChallengeIndex');
		$trkid = $aseco->client->getResponse();
		$rtn = $aseco->client->query('GetChallengeList', 1, $trkid);
		$track = $aseco->client->getResponse();
	}

	// get track info
	$rtn = $aseco->client->query('GetChallengeInfo', $track[0]['FileName']);
	$trackinfo = $aseco->client->getResponse();
	return new Challenge($trackinfo);
}  // get_trackinfo

// check for at least one active player
function active_player($aseco) {

	$total = 0;
	// check all connected players
	foreach ($aseco->server->players->player_list as $player) {
		// get current player status
		if (!$aseco->isSpectator($player))
			return true;
	}
	return false;
}  // active_player
?>
thanks

©D
join VITAMINEC
Servermania V 0.98
xaseco 1.10

User avatar
szkodnik
cyclist
cyclist
Posts: 30
Joined: 17 Aug 2009 16:27
Owned TM-games: TMU, TMS, TMO
Manialink(s): tmtp://#join=szkodziu
Location: Poland, Szczecin

Re: Autotime help

Post by szkodnik » 17 Aug 2009 18:03

Standard xaseco\autotime.xml is not working correctly.
I edited code and everything is working but in code is not one important function.
How script is working?
On end of time is getting info about next track. Look in author time, get settings from autotime.xml and set up new timelimit for next track. Everything it's ok but there's not function for again calculate time when I want replay current track. For example we have author time for track 5 seconds. Script set up 1:00 for this track (12*5s=1m). Next track has author time 1 minute. Script is calculating [12*1m=12m and 12>7 so =>7m (with my settings)] and set up timelimit for next track 7 minutes. Players want replay of track, admin click retry and we play previous map (5s author time) but with 7 minutes time limit.
Can anyone try add function for this?
My xaseco\autotime.hml

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<autotime>
        <!-- Set the multiplicator for author time (e.g. 6x author -->
        <!-- time = new timelimit); set to 0 to disable function   -->
        <multiplicator>12</multiplicator>
        <!-- Set minimum timelimit in minutes -->
        <mintime>0.5</mintime>
        <!-- Set maximum timelimit in minutes -->
        <maxtime>7</maxtime>
        <!-- Set default timelimit in minutes if any error occurs -->
        <defaulttime>7</defaulttime>
        <!-- 2 = in TMF message window, 1 = in chat, 0 = none -->
        <display>0</display>
        <message>{#server}>> Set {1} timelimit for {#highlite}{2}{#server} : {#highlite}{3}{#server} (Author time: {#highlite}
{4}{#server})</message>
</autotime>
and xaseco\plugins\plugin.autotime.php

Code: Select all

<?php
/* vim: set noexpandtab tabstop=2 softtabstop=2 shiftwidth=2: */

/**
 * Auto TimeLimit plugin.
 * Changes Timelimit for TimeAttack dynamically depending on the next
 * track's author time.
 *
 * Original by ck|cyrus
 * Rewrite by Xymph
 *
 * Dependencies: none (but must be after plugin.rasp_jukebox.php in plugins.xml)
 */

Aseco::registerEvent('onSync', 'load_atlconfig');
Aseco::registerEvent('onEndRace', 'autotimelimit');

global $atl_config, $atl_active, $atl_restart;

// load ATL configuration
function load_atlconfig($aseco) {
        global $atl_config, $atl_active, $atl_restart;

        // initialize flags
        $atl_active = false;
        $atl_restart = false;

        // load config file
        $config_file = 'autotime.xml';
        if (file_exists($config_file)) {
                if ($xml = $aseco->xml_parser->parseXml($config_file)) {
                        $atl_config = $xml['AUTOTIME'];
                        $atl_active = true;
                } else {
                        trigger_error('[ATL] Could not read/parse config file ' . $config_file . ' !', E_USER_WARNING);
                }
        } else {
                trigger_error('[ATL] Could not find config file ' . $config_file . ' !', E_USER_WARNING);
        }
}  // load_atlconfig

// process auto timelimit
function autotimelimit($aseco, $data) {
        global $atl_config, $atl_active, $atl_restart;

        // if not active, bail out immediately
        if (!$atl_active) return;
        // if restarting, bail out immediately
        if ($atl_restart) {
                $atl_restart = false;
                return;
        }

        // get next game settings
        $aseco->client->query('GetNextGameInfo');
        $nextgame = $aseco->client->getResponse();

        // check for TimeAttack on next track
        if ($nextgame['GameMode'] == 1) {
                // check if auto timelimit enabled
                if ($atl_config['MULTIPLICATOR'][0] > 0) {
                        // check if at least one active player on the server
                        if (active_player($aseco)) {
                                // get next track details
                                $challenge = get_trackinfo($aseco, 1);
                                $newtime = intval($challenge->authortime);
                        } else {
                                // server already switched so get current track name
                                $challenge = get_trackinfo($aseco, 0);
                                $newtime = 0;  // force default
                                $newtime = intval($challenge->authortime);
                        }

                        // compute new timelimit
                        if ($newtime <= 0) {
                                $newtime = $atl_config['MULTIPLICATOR'][0];
                                $tag = 'default';
                        } else {
                                $newtime *= $atl_config['MULTIPLICATOR'][0];
                                $newtime -= $atl_config['MULTIPLICATOR'][0]; //($newtime % 1000);  // round down to seconds
                                $tag = 'new';
                        }
                        // check for min/max times
                        if ($newtime < $atl_config['MINTIME'][0] * 60 * 1000) {
                                $newtime = $atl_config['MINTIME'][0] * 60 * 1000;
                                $tag = 'min';
                        } elseif ($newtime > $atl_config['MAXTIME'][0] * 60 * 1000) {
                                $newtime = $atl_config['DEFAULTTIME'][0] * 60 * 1000;
                                $tag = 'default';
                        }

                        // set and log timelimit (strip .00 sec)
                        $aseco->client->addcall('SetTimeAttackLimit', array($newtime));
                        $aseco->console('set {1} timelimit for [{2}]: {3} (Author time: {4})',
                                        $tag, stripColors($challenge->name),
                                        substr(formatTime($newtime), 0, -3),
                                        formatTime($challenge->authortime));

                        // display timelimit (strip .00 sec)
                        $message = formatText($atl_config['MESSAGE'][0], $tag,
                                              stripColors($challenge->name),
                                              substr(formatTime($newtime), 0, -3),
                                              formatTime($challenge->authortime));
                        if ($atl_config['DISPLAY'][0] == 2 && function_exists('send_window_message'))
                                send_window_message($aseco, $message, true);
                        elseif ($atl_config['DISPLAY'][0] > 0)
                                $aseco->client->query('ChatSendServerMessage', $aseco->formatColors($message));
                }
        }
}  // autotimelimit

// get info on current/next track
function get_trackinfo($aseco, $offset) {

        // get current/next track using /nextmap algorithm
        if ($aseco->server->getGame() != 'TMF') {
                $aseco->client->query('GetCurrentChallengeIndex');
                $trkid = $aseco->client->getResponse();
                $trkid += $offset;
                $aseco->client->resetError();
                $rtn = $aseco->client->query('GetChallengeList', 1, $trkid);
                $track = $aseco->client->getResponse();
                if ($aseco->client->isError()) {
                        // get first track
                        $rtn = $aseco->client->query('GetChallengeList', 1, 0);
                        $track = $aseco->client->getResponse();
                }
        } else {  // TMF
                if ($offset == 1)
                        $aseco->client->query('GetNextChallengeIndex');
                else
                        $aseco->client->query('GetCurrentChallengeIndex');
                $trkid = $aseco->client->getResponse();
                $rtn = $aseco->client->query('GetChallengeList', 1, $trkid);
                $track = $aseco->client->getResponse();
        }

        // get track info
        $rtn = $aseco->client->query('GetChallengeInfo', $track[0]['FileName']);
        $trackinfo = $aseco->client->getResponse();
        return new Challenge($trackinfo);
}  // get_trackinfo

// check for at least one active player
function active_player($aseco) {

        $total = 0;
        // check all connected players
        foreach ($aseco->server->players->player_list as $player) {
                // get current player status
                if (!$aseco->isSpectator($player))
                        return true;
        }
        return false;
}  // active_player
?>
I don't know english, PHP and MySQL but I scratch along ; )
TM accs: 20szn, szkodziu, szkodnisia

dago
sunday driver
sunday driver
Posts: 61
Joined: 20 Feb 2009 18:43
Owned TM-games: tmuf

Re: Autotime help

Post by dago » 17 Aug 2009 20:44

dago wrote:Autotime plugin seem tu adjust the time on the up side only.
It never bring it back down.

©D
Correction

I think i have narrowed my problem to:

If computed time is higher than minimum limit, time is ajusted on the down side but if computed time is lower than minimum limit, timelimit is not adjusted to minimun time.

If anyone has an idee i would be glad to test it.

Thanks

Dan
join VITAMINEC
Servermania V 0.98
xaseco 1.10

User avatar
szkodnik
cyclist
cyclist
Posts: 30
Joined: 17 Aug 2009 16:27
Owned TM-games: TMU, TMS, TMO
Manialink(s): tmtp://#join=szkodziu
Location: Poland, Szczecin

Re: Autotime help

Post by szkodnik » 17 Aug 2009 21:44

I don't know why, but <defaulttime>3.5</defaulttime> here must be integer. Try change mintime for 3. Maybe <mintime> too. If that will not working, try this:

Code: Select all

// check for min/max times
                        if ($newtime < $atl_config['MINTIME'][0] * 60 * 1000) {
                                $newtime = $atl_config['DEFAULTTIME'][0] * 60 * 1000;
                                $tag = 'min';
                        }
But defaulttime value MUST be integer.
I don't know english, PHP and MySQL but I scratch along ; )
TM accs: 20szn, szkodziu, szkodnisia

dago
sunday driver
sunday driver
Posts: 61
Joined: 20 Feb 2009 18:43
Owned TM-games: tmuf

Re: Autotime help

Post by dago » 18 Aug 2009 11:57

szkodnik wrote:I don't know why, but <defaulttime>3.5</defaulttime> here must be integer. Try change mintime for 3. Maybe <mintime> too.
Looks like that was it. Seems to work fine now.

Thanks.

Dan
join VITAMINEC
Servermania V 0.98
xaseco 1.10

Post Reply