searching for Live CPList, (help with array needed)

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
ozmodiar
pedestrian
pedestrian
Posts: 6
Joined: 23 Jul 2013 08:09
Owned TM-games: TMU

searching for Live CPList, (help with array needed)

Post by ozmodiar » 23 Jul 2013 08:52

Hi guys,

i'm looking for just a small plugin showing a list off all players including their checkpoints and times/timedifference, like the one in FAST.

alternative anyone might help me with development.
shouldnt be a big deal for someone with experience, i guess. my plan was to store cps on event onCheckpoint

Code: Select all

function store_cp($aseco, $cp_item) {
	global $checkpoints, $ckps, $laps_cpcount;
//	$ckps	= array();
	$login = $cp_item[1];
	$time = $cp_item[2];
	$lap = $cp_item[3];
	$ndx = $cp_item[4];
	if ($player = $aseco->server->players->getPlayer($login))
			$nick = $player->nickname;
		else  // fall back on login
			$nick = $pl;
now to write all the infos in an array and multisort sort 'em by ndx descending and if index is the same by time ascending.
finally just go trough the array from first to last.
the displaying can be done by me, hopefully.

thx in advance for any kind of hints/help, greets, oz

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

Re: searching for Live CPList, (help with array needed)

Post by Xymph » 23 Jul 2013 08:59

ozmodiar wrote:i'm looking for just a small plugin showing a list off all players including their checkpoints and times/timedifference, like the one in FAST.
If it exists, it's here: http://plugins.xaseco.org/browse.php
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

Lambda
happy cruiser
happy cruiser
Posts: 131
Joined: 22 Feb 2009 22:03
Owned TM-games: TMU+F, TM²C

Re: searching for Live CPList, (help with array needed)

Post by Lambda » 23 Jul 2013 09:54

maybe this?
CP Live

ozmodiar
pedestrian
pedestrian
Posts: 6
Joined: 23 Jul 2013 08:09
Owned TM-games: TMU

Re: searching for Live CPList, (help with array needed)

Post by ozmodiar » 23 Jul 2013 10:01

ofcourse i had a look there, searched forums and googled...
seems only to be best cp widgets. nothing i'm looking for, or its somewehere included and not really mentioned in the description.

problem is i just cant understand/handle multidimensional array and sort it.
its just five infos to be stored and sorted by two of them, but i've been trying for days not figuering it out.


€: thx lambda! i'll have a try. first screenshot i googled was looking fine!

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

Re: searching for Live CPList, (help with array needed)

Post by Xymph » 23 Jul 2013 11:44

Lambda wrote:maybe this?
CP Live
Ok, plugins that weren't properly (with sufficient info) released through these forums (with their own topic) or on their authors' sites, cannot be added to the plugins repository. This is one of those few plugins, hence I had forgotten about it.
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

ozmodiar
pedestrian
pedestrian
Posts: 6
Joined: 23 Jul 2013 08:09
Owned TM-games: TMU

Re: searching for Live CPList, (help with array needed)

Post by ozmodiar » 25 Jul 2013 15:20

looking good so far. with tiny modifications.
but the main idea/problem is still that the cps are not sorted by time. only by cp number. isnt that somehow easily implementable?!

Code: Select all

//onCheckpoint
function cplive_get_cp($lambda, $cpdata){ 
	global $Players, $CpNb;
	global $add_to_login;

	$login = $cpdata[1] . $add_to_login;

	$CpNb[$login] = array("CPNumber" => $cpdata[4]+1, 
	"Time" => $cpdata[2],
	"Login" => $cpdata[1]);    

	if(!array_key_exists($login, $CpNb)){
		unset($Players[$login]);
		unset($CpNb[$login]);    
	}	
	cplive_list($lambda);
}
//update List
function cplive_list($lambda){
	global $Players, $CpNb;
	global $num_rows;
	global $list, $List;

	//copy array
	$List = $list = array_merge_recursive($Players, $CpNb);

	//show only when array is not empty (?!)
	if (empty($list) == array()){

	//sort by highest curr cp nuber
	$List = subval_sort($List, "CPNumber"); 

	//number of rows for displaying
	$List = array_slice($List, 0, $num_rows);
	}
	display_hud($lambda);
}
//sort 2D array by value
function subval_sort($a,$subkey){

	foreach($a as $k=>$v){
		$b[$k] = strtolower($v[$subkey]);
	}
	arsort($b);    //numbers
	foreach($b as $k=>$v){
		$c[] = $a[$k];
	}
	return $c;
}
somewhere in here? guess/hope thats ok to post lamda ;)
cheers, oz

Lambda
happy cruiser
happy cruiser
Posts: 131
Joined: 22 Feb 2009 22:03
Owned TM-games: TMU+F, TM²C

Re: searching for Live CPList, (help with array needed)

Post by Lambda » 25 Jul 2013 16:02

try this

Code: Select all

$List = subval_sort($List, "CPNumber");
to

Code: Select all

$List = subval_sort($List, "Time");

ozmodiar
pedestrian
pedestrian
Posts: 6
Joined: 23 Jul 2013 08:09
Owned TM-games: TMU

Re: searching for Live CPList, (help with array needed)

Post by ozmodiar » 25 Jul 2013 21:50

without trying, i guess that shouldnt work.
imagine cp 1 is at round about 5 sec and cp 2 is at 10 sec.
player 1 at cp 2 with 10sec
player 2 at cp 2 with 11sec
player 3 at cp 1 with 5sec.

it needs to be sorted by cp, and if cps are equal by time.
this from the aseco plugin.rounds.php should do basically what i want

Code: Select all

// called @ onEndRound
function report_round($aseco) {
	global $rounds_count, $round_times, $round_pbs;

	// if someone finished (in Rounds/Team/Cup mode), then report this round
	if (!empty($round_times)) {
		$rounds_count++;
		// sort by times, PBs & PIDs
		$round_scores = array();

		ksort($round_times);
		foreach($round_times as &$item){
			// sort only times which were driven more than once
			if (count($item) > 1) {
				$scores = array();
				$pbs = array();
				$pids = array();
				foreach ($item as $key => &$row) {
					$scores[$key] = $row['score'];
					$pbs[$key] = $round_pbs[$row['login']];
					$pids[$key] = $row['playerid'];
				}
				// sort order: SCORE, PB and PID, like the game does
				array_multisort($scores, SORT_NUMERIC, $pbs, SORT_NUMERIC, $pids, SORT_NUMERIC, $item);
			}
			// merge all score arrays
			$round_scores = array_merge($round_scores, $item);
		}
somethin like arraymultisort($cps,sort_asc, $times, sort_desc)
but my basic skills are not enough to implement that into yours.
but would anyways be good in your plugin :) if you have (or someone else has) the time and desire :1
cheers mate

ozmodiar
pedestrian
pedestrian
Posts: 6
Joined: 23 Jul 2013 08:09
Owned TM-games: TMU

Re: searching for Live CPList, (help with array needed)

Post by ozmodiar » 29 Jul 2013 06:19

think i figured it out. instead of your

Code: Select all

$List = subval_sort($List, "CPNumber");
i tryed

Code: Select all

	foreach ($List as $key => $row) {
		$CPNumber[$key]    = $row['CPNumber'];
		$Time[$key] = $row['Time'];
		$Login[$key] = $row['Login'];
		}

	array_multisort($CPNumber, SORT_DESC, $Time, SORT_ASC, $Login, SORT_STRING, $List);
	}
first test was looking fine.

Lambda
happy cruiser
happy cruiser
Posts: 131
Joined: 22 Feb 2009 22:03
Owned TM-games: TMU+F, TM²C

Re: searching for Live CPList, (help with array needed)

Post by Lambda » 29 Jul 2013 09:03

Nice.

I am also looking for a solution in the function 'array_multisort':

Code: Select all

function cplive_multisort ($a, $b, $c){
  foreach ($a as $k => $v) {
    $d[$k] = $v[$b];
    $e[$k] = $v[$c];
  }
  array_multisort($d, SORT_DESC, $e, SORT_ASC, $a);
  return $a;
}
and it works fine (for now).

ozmodiar
pedestrian
pedestrian
Posts: 6
Joined: 23 Jul 2013 08:09
Owned TM-games: TMU

Re: searching for Live CPList, (help with array needed)

Post by ozmodiar » 29 Jul 2013 09:32

on rpg servers this probably wont be an issue, but if u use it on tech servers with 20 to 30 or even more players i suggest you to also put a third parameter to sort. game does it by pb and pid. i just used login.
otherwise when two players have the same time at the same cp, it might happen the players switch postition every time one of the remaining 30other players passes the cp. cause the list is rewritten on every pass.
looks pretty funny, as the players are jumping around really fast ;)

check this vid
at 0:05:45
the scoreboard on the right. using multisort only with time and no other parameter

Post Reply