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>';
?>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.