Jump to content

[SOLVED] top players from text file


clown[NOR]

Recommended Posts

this is the code i've got now

 

<?php

// Calculate time
$c_time = date("H:i:s");
$n_hour = date("H")-1;
$n_ms = date("i:s");
$n_time = $n_hour.":".$n_ms;

$filename = "http://ts.1337gamer.no:28950/cod-server-1/Kills.txt";
$text = file($filename);
foreach ($text as $line) {
preg_match('/\] (.+) killed/',$line,$match);
$person=$match[1];
$score[$person]++;
}
arsort($score);
echo '
<table border="1" cellspacing="0" cellpadding="0" width="200 bordercolor="#000000">
	<tr>
		<td width="150"><strong>Player</strong></td>
		<td width="50"><strong>Kills</strong></td>
	</tr>
';
foreach ($score as $killer => $kills) {
if (!empty($killer)) {
	echo '
		<tr>
			<td width="150">'.$killer.'</td>
			<td width="50">'.$kills.'</td>
		</tr>
	';
}
}
echo '</table>';
?>

foreach ($text as $line) {
  preg_match('/(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match);
 $blamtime=$match[1];
 $person=$match[2];
 if($now-$blamtime<=$hourago)
      $score[$person]++;
}

 

from your code, I take it you can come up with something appropriate for the if statement.

 

never mind last post... got it working now after a deeper dive into the code =) thank you very much for all the help ... tomorrow when the server fills back up i will have the answer if it's perfect or some flaws =)

Result:

(1337) -Optima- has 24 kills.

PRoji has 21 kills.

lizard- has 20 kills.

[-Z-] has 20 kills.

[1337]Rapperen has 17 kills.

[1337]mentaL has 13 kills.

[1337]Maximus has 10 kills.

Jyrki has 10 kills.

Sigh has 10 kills.

Nixn has 9 kills.

SatyR has 9 kills.

NIRVANA has 9 kills.

berserker727 has 8 kills.

maukka has 8 kills.

tribe|zwrk has 8 kills.

tribe|DuFFy has 6 kills.

GratoQ has 4 kills.

-{FsA}-Sadm0on has 4 kills.

Falckenberg has 4 kills.

|SLS&Co|'''Pire has 4 kills.

oxfile mariachi has 3 kills.

BF_WARRIOR has 3 kills.

jesus has 3 kills.

Alyna has 2 kills.

Sniblu has 2 kills.

[1337]Crazy has 2 kills.

[JDG]Brunnen-G has 1 kills.

dsr.encke has 1 kills.

MrMack has 1 kills.

 

Code:

<?php

// One hour ago
$n_hour = date("H")-1;
$n_ms = date("i:s");
$hourago = $n_hour.":".$n_ms;

$filename = "http://ts.1337gamer.no:28950/cod-server-1/Kills.txt";
$text = file($filename);
foreach ($text as $line) {
preg_match('/(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match);
$blamtime=$match[1];
$person=$match[2];
if($now-$blamtime<=$hourago) { 
	$score[$person]++; 
	$time[$blamtime]++;
}
}
arsort($score);
echo '
<table border="1" cellspacing="0" cellpadding="0" width="300 bordercolor="#000000">
	<tr>
		<td width="150"><strong>Player</strong></td>
		<td width="50"><strong>Kills</strong></td>
	</tr>
';
foreach ($score as $killer => $kills) {
if (!empty($killer)) {
	echo "<strong>$killer</strong> has <strong>$kills</strong> kills.<br />";
	/** 'echo '
		<tr>
			<td width="150">'.$killer.'</td>
			<td width="50">'.$kills.'</td>
		</tr>
	';*/
}
}
echo '</table>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.