Skip to content

Instantly share code, notes, and snippets.

@neomelonas
Last active August 29, 2015 14:15
Show Gist options
  • Save neomelonas/3ddb67c7a1c28394f985 to your computer and use it in GitHub Desktop.
Save neomelonas/3ddb67c7a1c28394f985 to your computer and use it in GitHub Desktop.
Damage dealt to medic in Competitive TF2 match.
<?php
$re = "/<(\\[\\w\\:\\d\\:\\d+\\])><(Red|Blue)>\\\" triggered \"damage\" against \\\".+<\\d+><(\\[\\w\\:\\d\\:\\d+\\])><(Red|Blue)>\"[a-z\\\"\\( ]+(\\d+)\\\"\\)/";
$log = file_get_contents('LOG.log');
preg_match_all($re, $log, $matches);
$cl = "/(\\[\\w\\:\\d\\:\\d+\\])\\>\\<(Red|Blue)\\>\\\" changed role to \\\"(\\w+)/";
preg_match_all($cl, $log, $classes);
echo "<pre>";
$meddm = array();
$class = array();
foreach($classes[1] as $k => $l){
$class[$l]['class'] = $classes[3][$k];
$class[$l]['team'] = $classes[2][$k];
preg_match('/^\[U:[0-9]:([0-9]+)\]$/i',$l, $id);
$ids = gmp_strval(gmp_add('76561197960265728', $id[1]));
$class[$l]['number'] = $ids;
$class[$l]['meddmg'] = 0;
}
$meds = array();
$j = 0;
while ($cl = current($class)){ if ($cl['class'] == 'medic') array_push($meds, key($class)); next($class); }
/* Get actual steam name from steam using steam web api steam yay steam. */
$urls = '';
foreach($class as $o){
$urls .= "$o[number],";
}
$urls = rtrim($urls, ",");
$pstat = json_decode(file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=WEBAPIKEY&steamids=".$urls));
foreach ($class as $c => $d){
foreach($pstat->response->players as $player){
if($d['number'] == $player->steamid) $class[$c]['name'] = $player->personaname;
}
}
// DAMAGE CALC
$i=0;
foreach ($matches[3] as $subm){
foreach($class as $uid => $clinfo){
if($subm == $uid && ($subm == $meds[0] || $subm == $meds[1])){
$class[$matches[1][$i]]['meddmg'] += $matches[5][$i];
}
}
$i++;
}
echo "\nDamage Dealt to Medics\n-----------------------\n";
echo "<table style='border-spacing:10px;'><tr><th>Team</th><th>Class</th><th>Name</th><th>Damage</th></tr>";
foreach($class as $id => $data){
echo '<tr><td>'.$data['team'].'</td><td>'.$data['class'].'</td><td>'.$data['name'].'</td><td>'.$data['meddmg'].'</td></tr>';
}
echo "</table>";
echo "</pre>";
echo '<a href="https://gist.github.com/neomelonas/3ddb67c7a1c28394f985">Fix what is wrong please</a>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment