Jump to content
php.lv forumi

Help :(


courage

Recommended Posts

es esmu tads iesacejs ar php bet es nesaprotu.... http://80.70.31.185/pstag/ps_tag.php?wID=137 dazi zin kas tas ir bet tie kuri nezin pateiksu. ta ir bildes formata statistika(mainiga) bet kapec vins man negrib radit?

 

<?php

include ("config.inc.php");

//-------------------------------------------------------------
//This function was taken from the PS2 by StormTrooper
function compacttime($seconds, $format="hh:mm:ss") {
$d = $h = $m = $s = "00";
if (!isset($seconds)) $seconds = 0;
$old = $seconds;
$str = $format;
if ( (strpos($str, 'dd') !== FALSE) && ($seconds / (60*60*24)) >= 1)  { $d = sprintf("%d", $seconds / (60*60*24)); $seconds -= $d * (60*60*24); }
if ( (strpos($str, 'hh') !== FALSE) && ($seconds / (60*60)) >= 1)	 { $h = sprintf("%d", $seconds / (60*60)); $seconds -= $h * (60*60); }
if ( (strpos($str, 'mm') !== FALSE) && ($seconds / 60) >= 1)		  { $m = sprintf("%d", $seconds / 60); $seconds -= $m * (60); }
if ( (strpos($str, 'ss') !== FALSE) && ($seconds % 60) >= 1)		  { $s = sprintf("%d", $seconds % 60); }
$str = str_replace('dd', sprintf('%02d',$d), $str);
$str = str_replace('hh', sprintf('%02d',$h), $str);
$str = str_replace('mm', sprintf('%02d',$m), $str);
$str = str_replace('ss', sprintf('%02d',$s), $str);
return $str;
}
//-------------------------------------------------------------

function imagettftextalign($image, $size, $angle, $x, $y, $color, $font, $text, $alignment='L') {
  //check width of the text
  $bbox = imagettfbbox ($size, $angle, $font, $text);
  $textWidth = $bbox[2] - $bbox[0];
  switch ($alignment) {
   case "R":
	   $x -= $textWidth;
	   break;
   case "C":
	   $x -= $textWidth / 2;
	   break;
  }

  //write text
  imagettftext ($image, $size, $angle, $x, $y, $color, $font, $text);

}
//--------------------------------------------------------------

//Get the player information and the player id which will be used on the other queries
$wID = $_GET['wID'];
$result_main =  mysql_query("SELECT plrid, name, totaluses FROM pstats_plrids WHERE worldid='" . $wID . "' ORDER BY totaluses DESC");
if (!$result_main) { die("ERR:" . mysql_error()); }
while ($row = mysql_fetch_array($result_main)) 
{
$playerName = $row[1];
$playerID = $row[0];
//mysql_free_result($result);

$result =  mysql_query("SELECT rank, skill FROM pstats_plr WHERE plrid=" . $playerID);
if (!$result) { die("ERR:" . mysql_error()); }
$row = mysql_fetch_row($result);
$playerRank += $row[0];
$playerSkill += $row[1];
mysql_free_result($result); 

//Fills the information 
$result = mysql_query("SELECT kills,deaths,killstreak,deathstreak,shots,hits,games,rounds,plrconnects,onlinetime FROM pstats_plrdata WHERE plrid=".$playerID);
if (!$result) { die("ERR:" . mysql_error()); }
while ( $row = mysql_fetch_array($result)) 
{
	//On the right side
	if ($row[4]>1) { $playerAcc = round(($row[5]*100)/$row[4],2); }
	$playerKills += $row[0];
	$playerDeaths += $row[1];
	// Kill and Death streak are only from the last game
	$playerKStrk = $row[2];
	$playerDStrk = $row[3];
	//On the left side
	$playerGames += $row[6];
	$playerRounds += $row[7];
	$playerConnects += $row[8];
	$playerT += $row[9];
}
$playerTOnline = compacttime($playerT,"hh:mm:ss");
mysql_free_result($result);

//Get the weapon which the player has most kills 
$result = mysql_query("SELECT kills,weaponid FROM pstats_plrweapons WHERE plrid=".$playerID." ORDER BY kills DESC");
if (!$result) { die("ERR:" . mysql_error()); }
$row = mysql_fetch_row($result);
$weaponID = $row[1];
mysql_free_result($result);

$result = mysql_query("SELECT plrid,weaponid,kills,deaths,damage,headshots,shots,hits FROM pstats_plrweapons WHERE plrid='".$playerID."' AND weaponid='" . $weaponID ."'");
if (!$result) { die("ERR:" . mysql_error()); }
//$row = mysql_fetch_row($result);
while ( $row = mysql_fetch_array($result)) 
{
	$weaponKills += $row[2];
	$weaponDeaths += $row[3];
	$weaponDamage += $row[4];
	$weaponHeadShots += $row[5];
	$weaponShots += $row[6];
	$weaponHits += $row[7];
}
// Some times weaponShots is being returned as 0
if ($weaponShots < 1)
{
	$weaponAcc = "ERROR";//$weaponShots;
}
else
{
	$weaponAcc = round(($weaponHits*100)/($weaponShots),2); 
}
mysql_free_result($result);

//Get the weapon name from the weapon ID;
$result = mysql_query("SELECT name FROM pstats_defs_weapons WHERE id='".$weaponID."'");
if (!$result) {die("ERR:" . mysql_error()); }
$row = mysql_fetch_row($result);
if ($weaponName == NULL) { $weaponName = $row[0]; }
mysql_free_result($result);

} //End loop to get the information of a STEAMID, for unkown reasons to me the same STEAMID can have multiple PlayerIDs

// make sure gd and freetype are loaded; we need them for the signature image
if (!extension_loaded("gd"))
{
echo "gd extension missing";
exit();
}

if (!in_array("imagettftext", get_extension_funcs("gd")))
{
echo "FreeType extensions missing from gd";
exit();
}

//Preares the source image and copies it to the final image
$srcimage = @imagecreatefromjpeg(IMAGEPATH."/".IMAGEFILE);
$src_x = imagesx($srcimage); $src_y = imagesy($srcimage);
$finalimage = imagecreatetruecolor($src_x, $src_y);
imagecopy ($finalimage, $srcimage, 0, 0, 0, 0, $src_x, $src_y);

/*
To instert images into the image use:
  $<desc_name> = @imagecreatefrom[type] ( <path> );
  imagecopy ($finalimage, $<desc_name>, <dst_x>, <dst_y>, <src_x>, <src_y>, imagesx($<dsc_name>)-1, imagesy($<dsc_name>-1);
*/

//$fgcolor = imagecolorallocate($finalimage, 239,163 ,015); //Define the color of the TEXT to used in the image
$fgcolor = imagecolorallocate($finalimage, FONTCOLOR_R, FONTCOLOR_G, FONTCOLOR_B); //Define the color of the TEXT to used in the image

//Information on the left side
imagettftext($finalimage, FONTSIZE, 0, 115, 15, $fgcolor, FONTFILE, "Player Name: ".$playerName);
imagettftext($finalimage, FONTSIZE, 0, 115, 27, $fgcolor, FONTFILE, " - Rank:".$playerRank);
imagettftext($finalimage, FONTSIZE, 0, 115, 39, $fgcolor, FONTFILE, " - Skill: ".$playerSkill);
imagettftext($finalimage, FONTSIZE, 0, 115, 51, $fgcolor, FONTFILE, " - Games/Rounds: ".$playerGames."/".$playerRounds);
imagettftext($finalimage, FONTSIZE, 0, 115, 63, $fgcolor, FONTFILE, " - Connects: ".$playerConnects);
imagettftext($finalimage, FONTSIZE, 0, 115, 75, $fgcolor, FONTFILE, " - Time online: ".$playerTOnline);
//imagettftext($finalimage, FONTSIZE, 0, 370, 125, $fgcolor, FONTFILE, "");

//Information on the right side
imagettftext($finalimage, FONTSIZE, 0, 260, 27, $fgcolor, FONTFILE, "Kills: ".$playerKills);
imagettftext($finalimage, FONTSIZE, 0, 260, 39, $fgcolor, FONTFILE, "Deaths: ".$playerDeaths);
imagettftext($finalimage, FONTSIZE, 0, 260, 51, $fgcolor, FONTFILE, "Kill Streak: ".$playerKStrk);
imagettftext($finalimage, FONTSIZE, 0, 260, 63, $fgcolor, FONTFILE, "Death Streak: ".$playerDStrk);
imagettftext($finalimage, FONTSIZE, 0, 260, 75, $fgcolor, FONTFILE, "Accruacy: ".$playerAcc."%");

//Weapon Statistics
//imagettftext($finalimage, FONTSIZE, 0, 115, 87, $fgcolor, FONTFILE, "Mostly skilled with");
imagettftext($finalimage, FONTSIZE, 0, 115, 87, $fgcolor, FONTFILE, "Weapon  Kills  Deaths  Damage  Accruacy  HS");

$weapon = @imagecreatefromgif(WEAPONIMAGES.$weaponName.".gif");
imagecopy ($finalimage, $weapon, 120,89,0,0,imagesx($weapon),imagesy($weapon));
imagettftextalign($finalimage, FONTSIZE, 0, 175, 99, $fgcolor, FONTFILE, $weaponKills,"C");
imagettftextalign($finalimage, FONTSIZE, 0, 209, 99, $fgcolor, FONTFILE, $weaponDeaths,"C");
imagettftextalign($finalimage, FONTSIZE, 0, 255, 99, $fgcolor, FONTFILE, $weaponDamage,"C");
imagettftextalign($finalimage, FONTSIZE, 0, 305, 99, $fgcolor, FONTFILE, $weaponAcc."%","C");
imagettftextalign($finalimage, FONTSIZE, 0, 339, 99, $fgcolor, FONTFILE, $weaponHeadShots,"C");

header('Content-Type: image/jpeg');
imagejpeg($finalimage, '',100);

?>

 

 

 

http://www.the-rota.com/pstag/rota_tag.php?wID=137 <-- piemers kads izskatas

Edited by courage
Link to comment
Share on other sites

×
×
  • Create New...