Jump to content

Recommended Posts

as i've said in an earlier post i'm working on a sript that will show the player score for a CoD4 game server... highest to lowest the past hour... so i got some help in here, but what i wonder...

 

this code here

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]++;
}
}

i'm working with a 24-hour time.. so when it goes to midnight it goes back to 00.. wont that mess up? since 00 is less than 23? how can i work around that?

Link to comment
https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/
Share on other sites

next question..

 

it's now 18:23 here... (didnt add the secs now)... but it still shows the time that was yesterday at 23 and 00 etc...  how can i change the regex to catch the date also so i can make a if statement that skips everything that was yesterday?

 

this is the complete code i've got now:

<?php

function getKills($server_id) {
// 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-".$server_id."/Kills.txt";
$text = file($filename);
foreach ($text as $line) {
	preg_match('/(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match);
	$k_time=$match[1];
	$person=$match[2];
	if(substr($k_time,0,2)== "00") { substr_replace($k_time,"24",0,0); }
	if($now-$k_time<=$hourago) { 
		$score[$person]++; 
	}
}
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>';
}
?>

Thanks In Advance
- Clown

should i make the preg_match look something like this?

preg_match('/ \[\d\d.\d\d.\d\d\)(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match);

 

it's prob WAY off... i have no clue about regex so that's just a wild guess

ok ill try that out.. but atm i just cant figure out how to pull out the date with regex... been going crazy @ google and still no luck :( so until i can get the date i' stuck :(

 

file setup:

[28.01.2008 19:44:08] Omega|IzNoGood killed [1337]sleggis with unkown Zone:Headshoot Damage:55

[28.01.2008 19:44:24] [1337]sleggis killed dsr.encke with m4 silencer Zone:Torso lower Damage:42

[28.01.2008 19:44:44] dsr.encke killed Trym with unkown Zone:unkown Damage:170

[28.01.2008 19:44:47] Omega|Mora di killed Trym with ak47 Silencer Zone:Torso lower Damage:56

[28.01.2008 19:45:05] Omega|Mora di killed dsr.gnawler with Grenade Zone:unkown Damage:192

[28.01.2008 19:45:06] [1337]sleggis killed *HMC*Antman with Grenade Zone:unkown Damage:285

[28.01.2008 19:45:17] Banko.Maestro killed [1337]PuZuR with mp5 silencer Zone:Torso upper Damage:136

 

code:

foreach ($text as $line) {
	preg_match('/(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match);
	$k_time=$match[1];
	$person=$match[2];
	//echo $match[2]."<br />"; 
	$score[$person]++; 
}

 

if anyone could help me out with the preg_match i think i'll be able to fix the if's myself

that returned nothing ...

 

foreach ($text as $line) {
	preg_match("@^\[(\d{2}.\d{2}.\d{4} \d{2}:\d{2}:\d{2})\] (.+?) killed (.+?) with (.+) Damage:(\d{1,})$@i",$line,$match);
	$k_time = $match[1];
	$person = $match[2];
	echo $match[1]." - ".$match[2]." - ".$match[3]." - ".$match[4]."<br />";
	$score[$person]++;
}

 

output

- - -

 

i really wanna learn how to setup a regex string thingy... is there a tutorial for 100% noobs? i mean like so detailed that noone can read trough the whole thing and at the end still dont understand how to do it =)

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.