clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 i have one more question... how do i now make it so it only recives the score for the last hour? hehe... omg i never stop =) Link to comment https://forums.phpfreaks.com/topic/88076-solved-top-players-from-text-file/page/2/#findComment-450809 Share on other sites More sharing options...
resago Posted January 28, 2008 Share Posted January 28, 2008 post our entire code so far, so its on this page. Link to comment https://forums.phpfreaks.com/topic/88076-solved-top-players-from-text-file/page/2/#findComment-450811 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 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 https://forums.phpfreaks.com/topic/88076-solved-top-players-from-text-file/page/2/#findComment-450812 Share on other sites More sharing options...
resago Posted January 28, 2008 Share Posted January 28, 2008 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 https://forums.phpfreaks.com/topic/88076-solved-top-players-from-text-file/page/2/#findComment-450823 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 that code removed alot of people again =) Link to comment https://forums.phpfreaks.com/topic/88076-solved-top-players-from-text-file/page/2/#findComment-450826 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 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 =) Link to comment https://forums.phpfreaks.com/topic/88076-solved-top-players-from-text-file/page/2/#findComment-450831 Share on other sites More sharing options...
resago Posted January 28, 2008 Share Posted January 28, 2008 make sure you don't have any double spaces. post a few lines of output. Link to comment https://forums.phpfreaks.com/topic/88076-solved-top-players-from-text-file/page/2/#findComment-450834 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 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 https://forums.phpfreaks.com/topic/88076-solved-top-players-from-text-file/page/2/#findComment-450910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.