You are not logged in.
#51 02 Aug 2006 1:57 pm
- Repent
- Member
- Registered: Aug 2006
- Posts: 9
Re: BF2 Rank
I've tried it every way, maybe it's my server. I'll keep trying.
Great idea by the way.
Offline
#53 02 Aug 2006 2:27 pm
- Repent
- Member
- Registered: Aug 2006
- Posts: 9
Re: BF2 Rank
I get text no matter what I do, and when I try to post it on my forum inside the [ img ] tags, nothing shows.
I didn't change anything in the zip, here is the index.php:
Code:
<?php /**********************************************************************/ /** Battlefield 2 Rank avatar **/ /** by: Steve Whitley (aka [OinK]_MadHatter) **/ /** Copyright © 2005 NullFX Software **/ /** **/ /** Licensed under the Creative Commons **/ /** Attribution-NonCommercial-ShareAlike License **/ /** **/ /** http://creativecommons.org/licenses/by-nc-sa/2.5/ **/ /** **/ /**********************************************************************/ $do_text = !isset($_GET['no_text']); $do_score = isset($_GET['score']); $who = "nick=NOTHING"; $delta = isset($_GET['delta']); $std = !isset($_GET['delta']); define('PERCENT', 100); define('PRIVATE', 0); define('PRIVATE_FIRST_CLASS', 1); define('LANCE_CORP', 2); define('CORPORAL', 3); define('SERGANT', 4); define('STAFF_SERGANT', 5); define('GUNNERY_SERGANT', 6); define('MASTER_SERGANT', 7); define('FIRST_SERGANT', 8); define('MASTER_GUNNERY_SERGANT', 9); define('SERGEANT_MAJOR', 10); define('SERGEANT_MAJOR_OF_CORPS', 11); define('SECOND_LIEUTENANT', 12); define('FIRST_LIEUTENANT', 13); define('CAPTAIN', 14); define('MAJOR', 15); define('LIEUTENANT_COLONEL', 16); define('COLONEL', 17); define('BRIGADIER_GENERAL', 18); define('MAJOR_GENERAL', 19); define('LIEUTENANT_GENERAL', 20); define('GENERAL', 21); $ranks = array( PRIVATE => 0, PRIVATE_FIRST_CLASS => 150, LANCE_CORP => 500, CORPORAL => 800, SERGANT => 2500, STAFF_SERGANT => 5000, GUNNERY_SERGANT => 8000, MASTER_SERGANT => 20000, FIRST_SERGANT => 20000, MASTER_GUNNERY_SERGANT => 50000, SERGEANT_MAJOR => 50000, SERGEANT_MAJOR_OF_CORPS => 50000, SECOND_LIEUTENANT => 60000, FIRST_LIEUTENANT => 75000, CAPTAIN => 90000, MAJOR => 115000, LIEUTENANT_COLONEL => 125000, COLONEL => 150000, BRIGADIER_GENERAL => 180000, MAJOR_GENERAL => 180000, LIEUTENANT_GENERAL => 200000, GENERAL => 200000 ); // web request stuff require_once("http.php"); $query = "nick=NOTHING"; if(isset($_GET['pid'])) { $query = "pid=".$_GET['pid']; }else if(isset($_GET['nick'])) { $query = "pid=".get_pid($_GET['nick']); } $req = new http_class(); $req->timeout = 0; $req->data_timeout = 0; $req->user_agent="GameSpyHTTP/1.0"; // this is overkill I know but as of November 8 2005, EA requires this // entire query. If all columns are not present, nothing is returned $url = "http://BF2Web.gamespy.com/ASP/getplayerinfo.aspx?".$query."&info=per*,cmb*,twsc,cpcp,cacp,dfcp,kila,heal,rviv,rsup,rpar,tgte,dkas,dsab,cdsc,rank,cmsc,kick,kill,deth,suic,ospm,klpm,klpr,dtpr,bksk,wdsk,bbrs,tcdr,ban,dtpm,lbtl,osaa,vrk,tsql,tsqm,tlwf,mvks,vmks,mvn*,vmr*,fkit,fmap,fveh,fwea,wtm-,wkl-,wdt-,wac-,wkd-,vtm-,vkl-,vdt-,vkd-,vkr-,atm-,awn-,alo-,abr-,ktm-,kkl-,kdt-,kkd-"; $args = null; $error = $req->GetRequestArguments($url, $args); if($error != "") { $img = imagecreatefromjpeg("./unavailable.jpg"); header("Content-type: image/jpeg"); imagejpeg($img); imagedestroy($img); die(); } $error = $req->Open($args); flush(); if($error != "") { $img = imagecreatefromjpeg("./unavailable.jpg"); header("Content-type: image/jpeg"); imagejpeg($img); imagedestroy($img); die(); } $req->SendRequest($args); flush(); $headers = array(); $req->ReadReplyHeaders($headers); if($req->response_status != "200") { $img = imagecreatefromjpeg("./unavailable.jpg"); header("Content-type: image/jpeg"); imagejpeg($img); imagedestroy($img); die(); } if($req->content_length_set && $req->content_length <= 0) { $img = imagecreatefromjpeg("./pid_change.jpg"); header("Content-type: image/jpeg"); imagejpeg($img); imagedestroy($img); die(); } // read the reply and parse the info out $score = 0; $rank_val = 0; $next = 0.0; do { $error=$req->ReadReplyBody($body, 4096); $lines = split("\n", $body); $get_data = false; for($i = 0; $i < count($lines); $i++) { $line = $lines[$i]; $pieces = split("\t", $line); for($j = 0; $j < count($pieces); $j++) { $part = $pieces[$j]; if($part == "H") { if($pieces[$j+1] != "asof") { $get_data = true; break; }else { $get_data = false; } } if($part == "D" && $get_data) { $score = $pieces[$j+3]; $rank_val = $pieces[$j+39]; break; } } } }while($error == "" && strlen($body) != 0); switch ($rank_val) { case PRIVATE: { if($score == 0) { $next = 0; }else { $next = ($score / $ranks[PRIVATE_FIRST_CLASS]) * PERCENT; } }break; case PRIVATE_FIRST_CLASS: { $next = $std?($score / $ranks[LANCE_CORP]) * PERCENT : ((($score - $ranks[PRIVATE_FIRST_CLASS]) / ($ranks[LANCE_CORP] - $ranks[PRIVATE_FIRST_CLASS])) * PERCENT); }break; case LANCE_CORP: { $next = $std?($score / $ranks[CORPORAL]) * PERCENT : ((($score - $ranks[LANCE_CORP]) / ($ranks[CORPORAL] - $ranks[LANCE_CORP])) * PERCENT); }break; case CORPORAL: { $next = $std?($score / $ranks[SERGANT]) * PERCENT : ((($score - $ranks[CORPORAL]) / ($ranks[SERGANT] - $ranks[CORPORAL])) * PERCENT); }break; case SERGANT: { $next = $std?($score / $ranks[STAFF_SERGANT]) * PERCENT : ((($score - $ranks[SERGANT]) / ($ranks[STAFF_SERGANT] - $ranks[SERGANT])) * PERCENT); }break; case STAFF_SERGANT: { $next = $std?($score / $ranks[GUNNERY_SERGANT]) * PERCENT : ((($score - $ranks[STAFF_SERGANT]) / ($ranks[GUNNERY_SERGANT] - $ranks[STAFF_SERGANT])) * PERCENT); }break; case GUNNERY_SERGANT: { $next = $std?($score / $ranks[MASTER_SERGANT]) * PERCENT : ((($score - $ranks[GUNNERY_SERGANT]) / ($ranks[MASTER_SERGANT] - $ranks[GUNNERY_SERGANT])) * PERCENT); }break; case MASTER_SERGANT: { $next = $std?($score / $ranks[MASTER_GUNNERY_SERGANT]) * PERCENT : ((($score - $ranks[MASTER_SERGANT]) / ($ranks[MASTER_GUNNERY_SERGANT] - $ranks[MASTER_SERGANT])) * PERCENT); }break; case FIRST_SERGANT: { $next = $std?($score / $ranks[MASTER_GUNNERY_SERGANT]) * PERCENT : ((($score - $ranks[FIRST_SERGANT]) / ($ranks[MASTER_GUNNERY_SERGANT] - $ranks[FIRST_SERGANT])) * PERCENT); }break; case MASTER_GUNNERY_SERGANT: { $next = $std?($score / $ranks[SECOND_LIEUTENANT]) * PERCENT : ((($score - $ranks[MASTER_GUNNERY_SERGANT]) / ($ranks[SECOND_LIEUTENANT] - $ranks[MASTER_GUNNERY_SERGANT])) * PERCENT); }break; case SERGEANT_MAJOR: { $next = $std?($score / $ranks[SECOND_LIEUTENANT]) * PERCENT : ((($score - $ranks[SERGEANT_MAJOR]) / ($ranks[SECOND_LIEUTENANT] - $ranks[SERGEANT_MAJOR])) * PERCENT); }break; case SERGEANT_MAJOR_OF_CORPS: { $next = $std?($score / $ranks[SECOND_LIEUTENANT]) * PERCENT : ((($score - $ranks[SERGEANT_MAJOR_OF_CORPS]) / ($ranks[SECOND_LIEUTENANT] - $ranks[SERGEANT_MAJOR_OF_CORPS])) * PERCENT); }break; case SECOND_LIEUTENANT: { $next = $std?($score / $ranks[FIRST_LIEUTENANT]) * PERCENT : ((($score - $ranks[SECOND_LIEUTENANT]) / ($ranks[FIRST_LIEUTENANT] - $ranks[SECOND_LIEUTENANT])) * PERCENT); }break; case FIRST_LIEUTENANT: { $next = $std?($score / $ranks[CAPTAIN]) * PERCENT : ((($score - $ranks[FIRST_LIEUTENANT]) / ($ranks[CAPTAIN] - $ranks[FIRST_LIEUTENANT])) * PERCENT); }break; case CAPTAIN: { $next = $std?($score / $ranks[MAJOR]) * PERCENT : ((($score - $ranks[CAPTAIN]) / ($ranks[MAJOR] - $ranks[CAPTAIN])) * PERCENT); }break; case MAJOR: { $next = $std?($score / $ranks[LIEUTENANT_COLONEL]) * PERCENT : ((($score - $ranks[MAJOR]) / ($ranks[LIEUTENANT_COLONEL] - $ranks[MAJOR])) * PERCENT); }break; case LIEUTENANT_COLONEL: { $next = $std?($score / $ranks[COLONEL]) * PERCENT : ((($score - $ranks[LIEUTENANT_COLONEL]) / ($ranks[COLONEL] - $ranks[LIEUTENANT_COLONEL])) * PERCENT); }break; case COLONEL: { $next = $std?($score / $ranks[BRIGADIER_GENERAL]) * PERCENT : ((($score - $ranks[COLONEL]) / ($ranks[BRIGADIER_GENERAL] - $ranks[COLONEL])) * PERCENT); }break; case BRIGADIER_GENERAL: { $next = $std?($score / $ranks[LIEUTENANT_GENERAL]) * PERCENT : ((($score - $ranks[BRIGADIER_GENERAL]) / ($ranks[LIEUTENANT_GENERAL] - $ranks[BRIGADIER_GENERAL])) * PERCENT); }break; case MAJOR_GENERAL: { $next = $std?($score / $ranks[LIEUTENANT_GENERAL]) * PERCENT : ((($score - $ranks[MAJOR_GENERAL]) / ($ranks[LIEUTENANT_GENERAL] - $ranks[MAJOR_GENERAL])) * PERCENT); }break; case LIEUTENANT_GENERAL: { $next = $std?($score / $ranks[GENERAL]) * PERCENT : ((($score - $ranks[LIEUTENANT_GENERAL]) / ($ranks[GENERAL] - $ranks[LIEUTENANT_GENERAL])) * PERCENT); }break; case GENERAL: { $next = 100; }break; default: $next = -1; break; } if($next > 100) $next = 100; $img_path = "./rank_".$rank_val.".jpg"; $img = imagecreatefromjpeg($img_path); imagealphablending($img, true); $width = (($next / 100) * 76); $border = imagecolorallocatealpha($img, 255, 255, 255, 45); $color = imagecolorallocatealpha($img, 1, 1, 1, 50); if($do_text || $do_score) { $txt_shadow = imagecolorallocatealpha($img, 0, 0, 0, 25); $txt_color = imagecolorallocatealpha($img, 255, 255, 255, 25); // if the no_text option hasnt been selected, draw the text if($do_text && $std) { imagettftext($img, 8.25, 0, 4, 57, $txt_shadow, "./ARIALBD.TTF", "Next"); imagettftext($img, 8.25, 0, 3, 56, $txt_color, "./ARIALBD.TTF", "Next"); imagettftext($img, 8.25, 0, 4, 68, $txt_shadow, "./ARIALBD.TTF", "Rank: ".round($next, 1)."%"); imagettftext($img, 8.25, 0, 3, 67, $txt_color, "./ARIALBD.TTF", "Rank: ".round($next, 1)."%"); } // if the no_text option hasnt been selected, draw the text if($do_text && !$std) { imagettftext($img, 8.25, 0, 4, 57, $txt_shadow, "./ARIALBD.TTF", "Rank"); imagettftext($img, 8.25, 0, 3, 56, $txt_color, "./ARIALBD.TTF", "Rank"); imagettftext($img, 8.25, 0, 4, 68, $txt_shadow, "./ARIALBD.TTF", "Delta: ".round($next, 1)."%"); imagettftext($img, 8.25, 0, 3, 67, $txt_color, "./ARIALBD.TTF", "Delta: ".round($next, 1)."%"); } // if score option is present, add the score to the avatar if($do_score) { $txt_color_s = imagecolorallocatealpha($img, 255, 255, 255, 30); imagettftext($img, 8, 0, 4, 12, $txt_shadow, "./ARIALBD.TTF", "Score ".number_format($score)); imagettftext($img, 8, 0, 3, 11, $txt_color_s, "./ARIALBD.TTF", "Score ".number_format($score)); } } $light_background = imagecolorallocatealpha($img, 255, 255, 255, 105); imagefilledrectangle($img, 2, 69, 77, 77, $light_background); imagerectangle($img, 1, 70, 78, 78, $border); imagefilledrectangle($img, 3, 72, $width, 76, $color); header("Content-type: image/jpeg"); imagejpeg($img); imagedestroy($img); $req->Close(); function get_pid($player_nick) { $search_request = new http_class(); $search_request->timeout = 0; $search_request->data_timeout = 0; $search_request->user_agent="GameSpyHTTP/1.0"; $url = "http://BF2Web.gamespy.com/ASP/searchforplayers.aspx?where=x&nick=".$player_nick; $args = null; $error = $search_request->GetRequestArguments($url, $args); if($error != "") { $search_request->Close(); return -1; } $error = $search_request->Open($args); flush(); if($error != "") { $search_request->Close(); return -1; } $search_request->SendRequest($args); flush(); $headers = array(); $search_request->ReadReplyHeaders($headers); if($search_request->response_status != "200") { $search_request->Close(); return -1; } if($search_request->content_length_set && $search_request->content_length <= 0) { $search_request->Close(); return -1; } // read the reply and parse the pid info out $score = 0; $rank_val = 0; $next = 0.0; do { $error=$search_request->ReadReplyBody($body, 4096); $lines = split("\n", $body); $get_data = false; for($i = 0; $i < count($lines); $i++) { $line = $lines[$i]; $pieces = split("\t", $line); for($j = 0; $j < count($pieces); $j++) { $part = $pieces[$j]; if($part == "H") { if($pieces[$j+2] == "pid") { $get_data = true; break; }else { $get_data = false; } } if($part == "D" && $get_data) { $search_request->Close(); return $pieces[$j+2]; }else if(part == "$" && $get_data) { $search_request->Close(); return -1; } } } }while($error == "" && strlen($body) != 0); $search_request->Close(); return -1; } ?>
Last edited by Repent (02 Aug 2006 2:28 pm)
Offline
#55 02 Aug 2006 2:46 pm
#57 02 Aug 2006 3:58 pm
- Repent
- Member
- Registered: Aug 2006
- Posts: 9
Re: BF2 Rank
My head hurts.
I ran these 2 test scripts to make sure my server (and GD) was capable of writing both PNG, and JPG.
And it is.
http://www.wwa-clan.com/bf2rank/test-png.php
Code:
<?php $im = @ ImageCreate(200, 100) or die ( "Cannot create a new GD image."); $background_color = ImageColorAllocate ($im, 100, 100, 100); $text_color = ImageColorAllocate ($im, 255, 255, 255); ImageString ($im, 1, 5, 5, "This is a PNG test! Is GD working?", $text_color ); header ("Content-type: image/png"); ImagePng ($im); ?>
http://www.wwa-clan.com/bf2rank/test-jpg.php
Code:
<?php $im = @ ImageCreate(200, 100) or die ( "Cannot create a new GD image."); $background_color = ImageColorAllocate ($im, 100, 100, 100); $text_color = ImageColorAllocate ($im, 255, 255, 255); ImageString ($im, 1, 5, 5, "This is a JPG test! Is GD working?", $text_color ); header ("Content-type: image/jpeg"); ImageJpeg ($im); ?>
I'm stumped (I stay that way) but I'm not giving up!
Offline
#58 02 Aug 2006 4:19 pm
Re: BF2 Rank
when I try it over here I get an exception saying you can't modify headers specified in line 1. the script doesnt set any headers anywhere but just before sending the image.
you may try adding the second parameter to the header function:
header("Content-type: image/jpeg", true);
I think true is default but you may try just in case.
Offline
#59 02 Aug 2006 4:32 pm
- Repent
- Member
- Registered: Aug 2006
- Posts: 9
Re: BF2 Rank
It must be my PHP enviroment, I'll look in the php.ini or check with my host, I'm starting to want to drink heavily.
I started with a fresh copy of everything, that's when the header error came up.
Last edited by Repent (02 Aug 2006 4:33 pm)
Offline
#61 02 Aug 2006 6:25 pm
- Repent
- Member
- Registered: Aug 2006
- Posts: 9
Re: BF2 Rank
Well, i hate to give up...but I'm stumped, and my eyes hurt o_O
I'll play around with it more at a later date, I'd really like to use the script, but something about it, my server doesn't like.
Offline
#63 07 Aug 2006 4:05 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: BF2 Rank
Ahh, guess there was a mistunderstanding there then, wanted it to show points left for next rankMadHatter :
20000 is the score needed to get master and first sergeant. 50000 is the score needed for master gunnery sergeant and sergeant major. 60000 for 2nd lieutenant, 75000 for 1st lieutenant.
http://www.bamboocommandos.com/prank/in … k=bash56ka doesnt show 20000 for next score. you can verify points here: http://ubar.bf2s.com/ranks.php
Offline
#65 07 Aug 2006 11:10 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: BF2 Rank
France was great, nice weather (not too hot), great food, many things to see and buy. Pretty girls, hehehe.
Now it works, great! Thanks again
Last edited by Butcher (07 Aug 2006 11:11 am)
Offline
#66 09 Aug 2006 5:10 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: BF2 Rank
Hmm, just out of curiosity, how is the RankProgress calculated on the scripty thingy? Atm, it says I'm at 94.39%, with 673 out of 20.000, seems wrong...
I divided 20.000 with 94.39% and got 18.878, and 20.000 - 18878 = 1122, so according to the percentage counter, I should have 1122 points to go, not 673...
Offline
#67 09 Aug 2006 7:10 am
Re: BF2 Rank
there are 2 methods of calculating progress. I like to use the overall progress (which is the default progress for the rank avatar) which is calculated:
"current score / "score for next rank"
however, the in game progress bar (like the one in your stats page) is the differential between your current rank, and your next rank, and is caclulated:
("current score" - "score for current rank") / ("score for next rank" - "score for current rank")
so that with every rank advancement, the progress bar starts back at 0. with the first calculation, it never gets reset to 0.
I havent put the logic into your pages rank calculation of some of the rank progress (because we're not pulling awards info to determine whether the player qualifies for the next rank), but some ranks have several ranks that require the same global score, so if you're a gunnery sergeant, you're next rank will either be master sergeant, or first sergeant depending on what awards you have (as they both have the same score requirements).
one thing I forgot to put in (thinking of that) is if the player has met the score req, but not other req's, the stats will report the rank correctly, but we dont take that into account
--[ open ]--
index.php
--[ find ]--
if($gs != 0) {
$progress = ((($gs - $rank_table[$rank]) / ($rank_table[$rank + 1] - $rank_table[$rank])) * PERCENT);
}
--[ after, add ]--
if($progress > 100) {
$progress = 100;
}
Offline
#68 09 Aug 2006 8:30 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: BF2 Rank
Done it, is there any way I can get it to show the other req's as well, without to much work? Just like, in pure text.
Offline
#69 09 Aug 2006 8:42 am
Re: BF2 Rank
the other requirements for rank advancement?
we'd have to pull the awards info, check to see if the awards at the levels required have been met, then print out whats needed. bf2s does this, but it is quite a bit of extra work.
Offline
#70 09 Aug 2006 10:08 am
#72 09 Aug 2006 1:56 pm
#73 08 Dec 2006 8:59 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: BF2 Rank
Did you guys find out anything about how to output the information onto a .jpg/.png, remember how I made that picture and we had it work too? The Clan Rank, still pondering on how to get those pictures out in a specific format so they can be used on a forum without making it a PHP forum.
Offline
#74 08 Dec 2006 9:18 am
Re: BF2 Rank
I dont really remember what you're talking about (short term memory failure). were you wanting to add other images to the one w/ the stats or something? you should be able to link to the one you already have.
Offline
#75 08 Dec 2006 4:46 pm
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: BF2 Rank
What I have are dynamic images, which are formatless (dont have a .jpg or .png to recognize them as images. For example, if I write
Code:
[img]http://www.bamboocommandos.net/prank/image.php?nick==[BC]=Butcher[/img]
in a default forum, it wont show the image, cause it doesnt have a filetype.
There is supposedly a way to transfer dynamic images into static images, but still allow them to update automatically, just cant remember how.
Offline