[fix available] CP Live plugin ?

The next generation of server controlling with clean and powerful user interface

Moderators: oliverde8, reaby, NADEO

Orpel
Posts: 7
Joined: 07 Jul 2016, 19:18

[fix available] CP Live plugin ?

Post by Orpel »

Hi there !

A new server has been set up in Canyon, with the great eXpansion controller,
to host past TMplus missions maps. If you don't know them, go check the server
for fun race, trial, lol, and endurance maps !
[maniaplanet]maniaplanet://#join=chapo001@TMPLUS@redix[/maniaplanet]

A CP live plugin was used on previous server with XAseco, and we would like to have it for eXpansion.
Its funciton is to tell at which CP each active player is, useful for trials and rpg maps.

The php source of the plugin is neatly structured, but having no clues, it would be nice if someone
knowledgeable could help on explaining what is needed to port it to eXpansion.

(I tried to contact Lambda on the email provided in source, but no reply yet)

Thanks !

Here is the source :

Code: Select all

<?php
/**
 * Checkpoint Live plugin by Lambda	(hello.lam***@yahoo.com) email address modified for 'pry-vacy'
 * plugin cplive_occam_stef 14-nov-2011
 * version:		???
 * manialnik version = 0
 *
 * 17-nov-2011
 * - Undefined variable: login on line 131 in file (136)	FIXED
 */
 
	// !!!
	global $num_rows, $xframe, $yframe, $sframe, $string_lenght, $line;
	global $color_title_text1, $color_title_text2, $color_title_text3, $color_player_text4, $color_player_text5, $color_player_text6, $color_player_text7, $color_player_text8; 
  
	//***	CONIGURATION	***//

	//number of displayed rows
	$num_rows = 20;
  
	//frame position left 
	$xframe = -63.8;	//horizontal
	$yframe = 21.5;		//vertical
	$sframe = 1.27;		//widget scale
	$string_lenght = 8;	//string lenght (login)
  
	//colors
	$color_title_text1 = 'FFF';		//CP Live text  
	$color_title_text2 = 'ABC';		//Track cp's text
	$color_title_text3 = 'ABC';		//cp's numbers	ABC
	$color_player_text4 = '567';	//Position number
	$color_player_text5 = 'F93';	//CP
	$color_player_text6 = '0F0';	//smile
	$color_player_text7 = '09D';	//Time	FFC
	$color_player_text8 = 'FFA';	//player

	//***	END CONIGURATION	***// 
  
  
Aseco::registerEvent('onPlayerConnect', 'player_on');
Aseco::registerEvent('onCheckpoint', 'get_cp');  
Aseco::registerEvent('onPlayerFinish', 'finish_giveup');
Aseco::registerEvent('onEndRound', 'list_cp_end');
Aseco::registerEvent('onBeginMap', 'reset_all');
Aseco::registerEvent('onPlayerDisconnect', 'player_off');
Aseco::registerEvent('onSync', 'control_start');
Aseco::registerEvent('onRestartMap', 'restart_reset');
  

	global $Players, $CpNb, $list, $all_cps;
	$Players = array();
	$CpNb = array();
  
	
	function control_start($lambda, $empty){
		
		get_cps($lambda);
	}
  
	
	function restart_reset($lambda, $empty){
	
		get_cps($lambda);
		reset_all($lambda);
		display_hud($lambda);
	}
  
	
	//onPlayerConnect
	function player_on($lambda, $ondata){
	global $Players, $CpNb;
 	global $string_lenght;
    
		$login = $ondata->login;
		$nickname = substr($login, 0, $string_lenght);
		$Players[$login] = array("Player" => $nickname);   

		$CpNb[$login] = array("CPNumber" => 0,
						  "Time" => '');
	
		title_manialink($lambda, $login);
	}

	
	//onCheckpoint
	function get_cp($lambda, $cpdata){ 
    global $CpNb;
    
		$CpNb[$cpdata[1]] = array("CPNumber" => $cpdata[4]+1, "Time" => $cpdata[2]);    
    
		display_hud($lambda);
	}

	
	//onPlayerFinish
	function finish_giveup($lambda, $finish){  
    global $all_cps;
	global $CpNb;

		$login = $finish->player->login;
		$cps = $finish->map->nbchecks;

		if ($CpNb[$login]["CPNumber"] != $cps) {
			$CpNb[$login] = array ("CPNumber" => 0,
								   "Time" => '');
		
			display_hud($lambda);
		}
	}
	
	
	//onEndRound
	function list_cp_end ($lambda, $end){
    
		$hud = '<manialink version="0" id="01928378"></manialink>';
		$hud .= '<manialink version="0" id="019283781"></manialink>';
		$lambda->client->query("SendDisplayManialinkPage", $hud, 1, false);
    } 

	
	//onBeginMap    
	function reset_all($lambda){
    global $CpNb;

		foreach ($lambda->server->players->player_list as $tpl){    
			$login = $tpl->login;
        
			$CpNb[$login] = array("CPNumber" => 0,
						   "Time" => '');
			
			title_manialink($lambda, $login);
		}   
		
		get_cps($lambda);
		display_hud($lambda);
	}

	
	//onPlayerDisconnect
	function player_off ($lambda, $info) {
    global $Players, $CpNb, $list;
    
		$login = $info->login;
    
		unset($Players[$login]);   
		unset($CpNb[$login]);
		unset($list[$login]);

		display_hud($lambda);
	}
	
	
	function subval_sort($a,$subkey) {
	
		foreach($a as $k=>$v) {
			$b[$k] = strtolower($v[$subkey]);
		}
	
		arsort($b);
		
		foreach($b as $k=>$v) {
			$c[] = $a[$k];
		}
	
		return $c;
	}
	

	function display_hud($lambda){  	
	global $Players, $CpNb, $list;
	global $all_cps, $num_rows;
	global $xframe, $yframe, $sframe;
	global $color_player_text4, $color_player_text5, $color_player_text6, $color_player_text7, $color_player_text8;
	
		$List = $list = array_merge_recursive($Players, $CpNb);
	
		if (empty($list) == array()){

			$List = subval_sort($List, "CPNumber"); 
			$List = array_slice ($List, 0, $num_rows);
	
			$hud = '<?xml version="1.0" encoding="UTF-8"?>';	
			$hud .= '<manialink version="0" id="019283781">';
			$hud .= '<frame scale="'.$sframe.'" posn="'.$xframe.' '.$yframe.'">';
		
			$pid = 1;
			$line = '';
		
			foreach ($List as $tcp){ 
			
				$line .= '$'.$color_player_text4.''.str_pad($pid, 2, '0', STR_PAD_LEFT).'. $z';
			
				if (($tcp["CPNumber"]-1) === $all_cps){    
					$line .= '$'.$color_player_text5.'CP-$'.$color_player_text6.''.str_pad(":-)",4 ,' ' ,STR_PAD_RIGHT).'$z'; 
				} else { 
					$line .= '$'.$color_player_text5.'CP-'.str_pad($tcp["CPNumber"],3 ,' ' ,STR_PAD_RIGHT).'$z';
				}
				$line .= '$'.$color_player_text7.''.str_pad(formatMilSecMinHrs($tcp["Time"]), 10,' ' ,STR_PAD_BOTH).'$z';
				$line .= '$'.$color_player_text8.''.trim($tcp["Player"]).'$z'.LF;
				$pid++;
			}

			$hud .= '<label scale="0.5" posn="0.4 -2 0.1" halign="left" valign="center" style="TextRaceMessage" text="'.$line.'"/>';
			$hud .= '</frame>';   
			$hud .= '</manialink>';
			
			$lambda->client->addCall('SendDisplayManialinkPage', array($hud, 0, false));
		}
	}
  
  
	//get all track cp's
	function get_cps($lambda){
	global $all_cps;
	
		$lambda->client->query('GetCurrentMapInfo');
		$CCInfo = $lambda->client->getResponse();
		$all_cps = ($CCInfo['NbCheckpoints'])-1;
	}
	
	
	//manialink title
	function title_manialink($lambda, $login){
	global $sframe, $xframe, $yframe, $all_cps, $line;
	global $color_title_text1, $color_title_text2, $color_title_text3;
	
		$hud = '<?xml version="1.0" encoding="UTF-8"?>';
		$hud .= '<manialink version="0" id="01928378">';
		$hud .= '<frame scale="'.$sframe.'" posn="'.$xframe.' '.$yframe.'">';
		$hud .= '<quad posn="0 0 0" sizen="15 2 0.08" halign="left" valign="center" style="BgsPlayerCard" substyle="BgCard"/>';
		$hud .= '<label scale="0.5" posn="0.4 0.1 0.1" halign="left" valign="center" style="TextRaceMessage" text=" $'.$color_title_text1.'CP Live            $'.$color_title_text2.'Track cp\'s: $'.$color_title_text3.''.$all_cps.'"/>';
		$hud .= '</frame>';
		$hud .= '</manialink>';
	
		$lambda->client->addCall('SendDisplayManialinkPageToLogin', array($login, $hud, 0, false));
	}

	//time format 0:00:00:000
	function formatMilSecMinHrs ($milliseconds) {
		
		if ($milliseconds >= 0) {
			$seconds = floor ($milliseconds / 1000);
			$minutes = floor ($seconds / 60);
			$hours = floor ($minutes / 60);
			$milliseconds = $milliseconds % 1000;
			$seconds = $seconds % 60;
			$minutes = $minutes % 60;

			if ($hours) {
				$format = '%u:%02u:%02u.%03u';
				$time = sprintf ($format, $hours, $minutes, $seconds, $milliseconds);
				return $time;
			} else {
				$format = '%u:%02u.%03u';
				$time = sprintf ($format, $minutes, $seconds, $milliseconds);
				return $time;
			}
		} else {
			echo "[formatMilliseconds] Wrong input! ($milliseconds)" . LF;
		}
	}
	
?>
Last edited by reaby on 10 Jul 2016, 12:31, edited 1 time in total.
Reason: added fix available-tag at topic
oliverde8
Posts: 1286
Joined: 16 Jun 2010, 07:33
Location: in a Blue Box

Re: CP Live plugin ?

Post by oliverde8 »

Hi,

The plugin can of course be ported, but it would require a complete rewrite. eXpansions plugins are differently structured from Aseco base controller structures. The generation of Manialinks is very different.

Which game mode are you running on? The live rankins widget displays CP progress (sort of) on all game modes beside TA.
Image
Developper for The next generation, Clean and Powerfull controller eXpansion for your SM & TM server . Working on eXpansion² with full MP4 support and many other awesome features...
Orpel
Posts: 7
Joined: 07 Jul 2016, 19:18

Re: CP Live plugin ?

Post by Orpel »

Well thanks a lot your reply, Oliver ! Obviously, the game mode is TA ! :roll:

The idea is to know which CP is everybody at, and the time it was reached,
interesting info for a map with lots of CPs and long completion time.

I had a shy look at https://github.com/eXpansionPluginPack/ ... t%20plugin
It mentions listening to events.

I inferred that we would need to listen
- the connection/deconnection of a player, to create/update a list of active players,
- the reaching of a CP by a player, to get associated time.
Then refresh the list of players, sorted by CP and time.
Why does it sound so simple ? :D

1 - Are such events easy to capture ?
2 - Could the live ranking widget be used as a base instead of reinventing the wheel and tyre ?
oliverde8
Posts: 1286
Joined: 16 Jun 2010, 07:33
Location: in a Blue Box

Re: CP Live plugin ?

Post by oliverde8 »

Hi,

first I think reaby is working on something, not 100% sure :D need to ask him.

Tes those events are easy to plug into. Basically there is 2 ways of doing this plugin.

1 Simple Way
The same way the plugin is done in XAseco. So listening to those events is very easy :

Code: Select all

public function eXpOnLoad()
    {
        // This wll allow this plugin to listen to player enter ... events
         $this->enableDedicatedEvents();
    }

public function onPlayerConnect($login, $isSpectator)
    {

    }

    public function onPlayerDisconnect($login, $reason = null)
    {

    }

    public function onPlayerCheckpoint($playerUid, $login, $score, $curLap, $checkpointIndex)
    {

    }

    public function onPlayerFinish($playerUid, $login, $timeOrScore)
    {

    }
Refreshing the widget is as well. probably need to put a timer rhingy to prevent the widget to be updated more then once every 2 seconds. You need for that to :

Code: Select all

$this->enableTickerEvent(); in onLoad again

function onTick()
    {
        if ($this->lastSend < time() - 2 && $this->widget) {
            // Refresh window
            $this->widget->show(null); // to refresh all players put null simply. You will need to create the widget

            // Update tick
            $this->lastSend = time();
        }
    }

2 Maniascript Way
One of core elements of eXpansion it's the heavy use of Maniascript. So your plugin sends a template manialink with maniascript. And the maniascript will then update it on each player. It's like javascript on a web page.

The current Live Rankings uses this. It switches between different maniascripts according to the game mode. Maybe extending the widget and making it use the round maniascript in TA might work.
Image
Developper for The next generation, Clean and Powerfull controller eXpansion for your SM & TM server . Working on eXpansion² with full MP4 support and many other awesome features...
reaby
Posts: 956
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

Re: CP Live plugin ?

Post by reaby »

Hi,

Yep, I had some free time so i rewrote it using the 1st method you introduced... Dev branch has now LiveCP plugin :)
If you wish to modify this, just feel free to fork the github repo and send merge request :)
(or use this topic to post your changed zip)

This is how it looks atm:
Image

You might want to disable dedimania widget, as this is at the same place as that for TA :)

We have also started to prepare an update for the master branch.
It'll take unknown time to finish as it needs to be as stable as possible...

-
Reaby
chapelier
Posts: 69
Joined: 08 Sep 2014, 16:43

Re: [fix available] CP Live plugin ?

Post by chapelier »

Looks great !
Thx a lot.
Orpel
Posts: 7
Joined: 07 Jul 2016, 19:18

Re: [fix available] CP Live plugin ?

Post by Orpel »

Wow ! You guys rock ! :)

Thanks for being so responsive and providing a ready made solution so quick ! The gauge is a nice addition :thumbsup:

I looked a bit at the php files to see how to change the layout, I believe you must have a template to use to match the look of records widget ?

After testing, a little improvement could be :
- after a completed run, keep Finish info till player pass CP1 again, so as to keep the completed time for a while (else the info is blanked as soon as car returns to Start...
Is Widgets_Livecp.php the place to do it ? functions on lines 92, 125 and 144 ?

And thanks again for your work and eXplanations
reaby
Posts: 956
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

Re: [fix available] CP Live plugin ?

Post by reaby »

Orpel wrote:Wow ! You guys rock ! :)

Thanks for being so responsive and providing a ready made solution so quick ! The gauge is a nice addition :thumbsup:
Many thanks :)
Orpel wrote: I looked a bit at the php files to see how to change the layout, I believe you must have a template to use to match the look of records widget ?
Somewhat I thought you would liked it to look more like the original. Changing it to look like other "windowed" widgets is just to add background and titlebar, and we have own template elements for those...
Orpel wrote: After testing, a little improvement could be :
- after a completed run, keep Finish info till player pass CP1 again, so as to keep the completed time for a while (else the info is blanked as soon as car returns to Start...
Oooh, another misunderstanding then, but it's most likely an easy fix :)
Orpel wrote: Is Widgets_Livecp.php the place to do it ? functions on lines 92, 125 and 144 ?
Have to see where it resets it at that point. Most likely I would guess somewhere near 92, but it can reset on some other event as well :) We'll see. I have again time today, so I'll take a look, but you can give it a try while waiting also :)
Orpel wrote: And thanks again for your work and eXplanations
Thanks!

-
Reaby
reaby
Posts: 956
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

Re: [fix available] CP Live plugin ?

Post by reaby »

Just informing that an update is now available for the livecp at DEV.
Also I changed the plugins version upwards.
Now at 1.0.1.0, this should have been done after we did massive changes to 1.0.0.5 structures.

-
Reaby
Orpel
Posts: 7
Joined: 07 Jul 2016, 19:18

Re: [fix available] CP Live plugin ?

Post by Orpel »

Well, update is set and running, everyone loves it :thumbsup:

We can't thank you enough, you made easy what we thought would be a hard labour of programming !

Come and play with us any time ;)
Post Reply

Return to “eXpansion”

Who is online

Users browsing this forum: No registered users and 1 guest