LemonInflux Posted August 29, 2007 Share Posted August 29, 2007 //calculate base combat if ($prayer & 1) { $prayer = ($prayer - 1)*50; } else { $prayer = $prayer*50; } $base_combat = ($defence*100 + $hitpoints*100 + $prayer)/400; //calculate personal class combats for melee, ranged and mage if ($range & 1){ $range = $range*195-65; } else { $range = $range*195; } if ($magic & 1){ $magic = $magic*195-65; } else { $magic = $magic*195; } $melee_combat = ($attack*130 + $strength*130)/400; $range_combat = $range/400; $mage_combat = $magic/400; //calculate final class combat (get max personal combat) if ($melee_combat >= $range_combat & $melee_combat >= $mage_combat) { $class_combat = $melee_combat; } elseif ($range_combat >= $melee_combat & $range_combat >= $mage_combat) { $class_combat = $range_combat; } else $class_combat = $mage_combat; //finalize combat level $combat_level = $class_combat + $base_combat; ?> This script works out RuneScape combat levels (not 100% accurate). The problem is, it doesn't seem to work. When I type <?PHP echo $combat_level ?>, absolutely nothing shows on the page. I'm guessing this is a math script error, but I didn't put it in the math section just in case. Any ideas, anyone? Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/ Share on other sites More sharing options...
Ken2k7 Posted August 29, 2007 Share Posted August 29, 2007 1. I have no idea why you would say if ($prayer && 1) because the 1 will always be true 2. You need two && Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337067 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 didn't work :\ Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337093 Share on other sites More sharing options...
Ken2k7 Posted August 29, 2007 Share Posted August 29, 2007 Could you post your newly updated code? Also please use the <?php to initialize php in the code box. Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337101 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 <?php $username = $_POST['username']; $website = file_get_contents('http://hiscore.runescape.com/index_lite.ws?player='.$username); $stats = explode("\n", $website); $overall = explode(",", $stats[0]); $attack = explode(",", $stats[1]); $defence = explode(",", $stats[2]); $strength = explode(",", $stats[3]); $hitpoints = explode(",", $stats[4]); $range = explode(",", $stats[5]); $prayer = explode(",", $stats[6]); $magic = explode(",", $stats[7]); $cooking = explode(",", $stats[8]); $woodcutting = explode(",", $stats[9]); $fletching = explode(",", $stats[10]); $fishing = explode(",", $stats[11]); $firemaking = explode(",", $stats[12]); $crafting = explode(",", $stats[13]); $smithing = explode(",", $stats[14]); $mining = explode(",", $stats[15]); $herblore = explode(",", $stats[16]); $agility = explode(",", $stats[17]); $thieving = explode(",", $stats[18]); $slayer = explode(",", $stats[19]); $farming = explode(",", $stats[20]); $runecrafting = explode(",", $stats[21]); $hunting = explode(",", $stats[22]); $construction = explode(",", $stats[23]); //calculate base combat if ($prayer && 1) { $prayer = ($prayer - 1)*50; } else { $prayer = $prayer*50; } $base_combat = ($defence*100 + $hitpoints*100 + $prayer)/400; //calculate personal class combats for melee, ranged and mage if ($range && 1){ $range = $range*195-65; } else { $range = $range*195; } if ($magic && 1){ $magic = $magic*195-65; } else { $magic = $magic*195; } $melee_combat = ($attack*130 + $strength*130)/400; $range_combat = $range/400; $mage_combat = $magic/400; //calculate final class combat (get max personal combat) if ($melee_combat >= $range_combat & $melee_combat >= $mage_combat) { $class_combat = $melee_combat; } elseif ($range_combat >= $melee_combat & $range_combat >= $mage_combat) { $class_combat = $range_combat; } else $class_combat = $mage_combat; //finalize combat level $combat_level = $class_combat + $base_combat; ?> <?php echo $combat_level; ?> Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337104 Share on other sites More sharing options...
Ken2k7 Posted August 29, 2007 Share Posted August 29, 2007 When you explode() something, it's normally in the form of an array so I'm not sure what your data contains Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337110 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 http://hiscore.runescape.com/index_lite.ws?player=zezima for example. the second, fifth, eighth, eleventh etc. number is what is being shown. Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337113 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 Wait, I showed you the wrong code >_> <?php //calculate base combat if ($prayer && 1) { $prayer = ($prayer - 1)*50; } else { $prayer = $prayer*50; } $base_combat = ($defence*100 + $hitpoints*100 + $prayer)/400; //calculate personal class combats for melee, ranged and mage if ($range && 1){ $range = $range*195-65; } else { $range = $range*195; } if ($magic && 1){ $magic = $magic*195-65; } else { $magic = $magic*195; } $melee_combat = ($attack*130 + $strength*130)/400; $range_combat = $range/400; $mage_combat = $magic/400; //calculate final class combat (get max personal combat) if ($melee_combat >= $range_combat & $melee_combat >= $mage_combat) { $class_combat = $melee_combat; } elseif ($range_combat >= $melee_combat & $range_combat >= $mage_combat) { $class_combat = $range_combat; } else $class_combat = $mage_combat; //finalize combat level $combat_level = $class_combat + $base_combat; $username = $_REQUEST['username']; $username = strtolower($username); $username = ucwords($username); $website = file_get_contents('http://hiscore.runescape.com/index_lite.ws?player=' . $username); $stats = explode("\n", $website); $overall = explode(",", $stats[0]); $stat['att'] = explode(",", $stats[1]); $stat['def'] = explode(",", $stats[2]); $stat['str'] = explode(",", $stats[3]); $stat['hp'] = explode(",", $stats[4]); $stat['rng'] = explode(",", $stats[5]); $stat['pry'] = explode(",", $stats[6]); $stat['mag'] = explode(",", $stats[7]); $stat['ck'] = explode(",", $stats[8]); $stat['wc'] = explode(",", $stats[9]); $stat['fsh'] = explode(",", $stats[11]); $stat['fm'] = explode(",", $stats[12]); $stat['cra'] = explode(",", $stats[13]); $stat['smi'] = explode(",", $stats[14]); $stat['min'] = explode(",", $stats[15]); $stat['rc'] = explode(",", $stats[21]); $image_link = 'http://reflexprojects.net/Assets/Images/stats/sigbg/sig8.png'; $image = imagecreatefrompng($image_link); //this is the font. You must include the filetype $font = 'arial.ttf'; $font_colour = imagecolorallocate($image, 255, 255, 255); $font_size = 12; // x axis //first number is x position for column 1 //second number is x position for cloumn 2 //third number is x position for column 3 //fourth number is x position for column 4 //fifth number is x position for column 5 $x = array('30', '82', '135', '187'); // y axis //first number is y position for row 1 //second number is y position for row 2 //third number is y position for row 3 //fourth number is y position for row 4 //fifth number is y position for row 5 $y = array('49', '74', '99', '124', '149'); $i = '0'; $a = '0'; foreach($stat as $s_key => $value){ imagettftext($image, $font_size, 0, $x[$a], $y[$i], $font_colour, $font , $value[1]); $i++; if($i == '5'){ $i = '0'; $a++; } } imagettftext($image, $font_size, 0, '208', '53', $font_colour, $font , ' ' . $combat_level); imagettftext($image, $font_size, 0, '200', '24', $font_colour, $font , ' ' . $overall[1]); imagettftext($image, $font_size, 0, '40', '24', $font_colour, $font , $username); header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?> It writes to an image, but as you can see at the moment here: it writes it as '0', no matter what it is. Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337124 Share on other sites More sharing options...
sasa Posted August 29, 2007 Share Posted August 29, 2007 variable $prayer is array and you can not do some math with it in your example it is array( 146, 99, 14019128) try <?php $username = $_POST['username']; $website = file_get_contents('http://hiscore.runescape.com/index_lite.ws?player='.$username); $stats = explode("\n", $website); //print_r($stats); $overall = explode(",", $stats[0]); $attack = explode(",", $stats[1]); $defence = explode(",", $stats[2]); $strength = explode(",", $stats[3]); $hitpoints = explode(",", $stats[4]); $range = explode(",", $stats[5]); $prayer = explode(",", $stats[6]); $magic = explode(",", $stats[7]); $cooking = explode(",", $stats[8]); $woodcutting = explode(",", $stats[9]); $fletching = explode(",", $stats[10]); $fishing = explode(",", $stats[11]); $firemaking = explode(",", $stats[12]); $crafting = explode(",", $stats[13]); $smithing = explode(",", $stats[14]); $mining = explode(",", $stats[15]); $herblore = explode(",", $stats[16]); $agility = explode(",", $stats[17]); $thieving = explode(",", $stats[18]); $slayer = explode(",", $stats[19]); $farming = explode(",", $stats[20]); $runecrafting = explode(",", $stats[21]); $hunting = explode(",", $stats[22]); $construction = explode(",", $stats[23]); //calculate base combat if ($prayer[1] & 1) { $prayer[1] = ($prayer[1] - 1)*50; } else { $prayer[1] = $prayer[1]*50; } $base_combat = ($defence[1]*100 + $hitpoints[1]*100 + $prayer[1])/400; //calculate personal class combats for melee, ranged and mage if ($range[1] & 1){ $range[1] = $range[1]*195-65; } else { $range[1] = $range[1]*195; } if ($magic[1] & 1){ $magic[1] = $magic[1]*195-65; } else { $magic[1] = $magic[1]*195; } $melee_combat = ($attack[1]*130 + $strength[1]*130)/400; $range_combat = $range[1]/400; $mage_combat = $magic[1]/400; //calculate final class combat (get max personal combat) if ($melee_combat >= $range_combat & $melee_combat >= $mage_combat) { $class_combat = $melee_combat; } elseif ($range_combat >= $melee_combat & $range_combat >= $mage_combat) { $class_combat = $range_combat; } else $class_combat = $mage_combat; //finalize combat level $combat_level = $class_combat + $base_combat; echo $combat_level; ?> Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337141 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 It worked! Thanks ever so much sasa! Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337143 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 Wait, no >_< It echoes it, yes. But it won't write to the picture. Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337146 Share on other sites More sharing options...
xyn Posted August 29, 2007 Share Posted August 29, 2007 what line/variables wont write to the image? Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337154 Share on other sites More sharing options...
chocopi Posted August 29, 2007 Share Posted August 29, 2007 I believe it to be: $combat_level Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337163 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 Yeah. I want $combat_level to appear in the 'combat' box Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337166 Share on other sites More sharing options...
chocopi Posted August 29, 2007 Share Posted August 29, 2007 Hey Lemon can you show the code you are using to write the $combat_level onto the image please. Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337168 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 I've deleted it now. but uuuh...It was sasa's in <?php $username = $_REQUEST['username']; $username = strtolower($username); $username = ucwords($username); $website = file_get_contents('http://hiscore.runescape.com/index_lite.ws?player=' . $username); $stats = explode("\n", $website); $overall = explode(",", $stats[0]); $stat['att'] = explode(",", $stats[1]); $stat['def'] = explode(",", $stats[2]); $stat['str'] = explode(",", $stats[3]); $stat['hp'] = explode(",", $stats[4]); $stat['rng'] = explode(",", $stats[5]); $stat['pry'] = explode(",", $stats[6]); $stat['mag'] = explode(",", $stats[7]); $stat['ck'] = explode(",", $stats[8]); $stat['wc'] = explode(",", $stats[9]); $stat['fsh'] = explode(",", $stats[11]); $stat['fm'] = explode(",", $stats[12]); $stat['cra'] = explode(",", $stats[12]); $stat['smi'] = explode(",", $stats[14]); $stat['min'] = explode(",", $stats[15]); $stat['rc'] = explode(",", $stats[21]); $image_link = 'http://reflexprojects.net/Assets/Images/stats/sigbg/sig8.png'; $image = imagecreatefrompng($image_link); //this is the font. You must include the filetype $font = 'arial.ttf'; $font_colour = imagecolorallocate($image, 255, 255, 255); $font_size = 12; // x axis //first number is x position for column 1 //second number is x position for cloumn 2 //third number is x position for column 3 //fourth number is x position for column 4 //fifth number is x position for column 5 $x = array('30', '82', '135', '187'); // y axis //first number is y position for row 1 //second number is y position for row 2 //third number is y position for row 3 //fourth number is y position for row 4 //fifth number is y position for row 5 $y = array('49', '74', '99', '124', '149'); $i = '0'; $a = '0'; foreach($stat as $s_key => $value){ imagettftext($image, $font_size, 0, $x[$a], $y[$i], $font_colour, $font , $value[1]); $i++; if($i == '5'){ $i = '0'; $a++; } } imagettftext($image, $font_size, 0, '200', '124', $font_colour, $font , ' ' . $combat_level); imagettftext($image, $font_size, 0, '200', '24', $font_colour, $font , ' ' . $overall[1]); imagettftext($image, $font_size, 0, '40', '24', $font_colour, $font , $username); header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?> the first imagettftext co-ords were made up, though. They're not the ones I used. Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337213 Share on other sites More sharing options...
chocopi Posted August 29, 2007 Share Posted August 29, 2007 What do you mean, you deleted it ? Do you have new/different code from Sasa's ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337222 Share on other sites More sharing options...
LemonInflux Posted August 29, 2007 Author Share Posted August 29, 2007 I deleted it for the time being, because it messed up the whole code and nothing showed but an '0' for combat. I just took out the calculation is all. Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337225 Share on other sites More sharing options...
chocopi Posted August 29, 2007 Share Posted August 29, 2007 Well if you say echo-ing $combat_level works then it should also work on the image, so i don't know why it is writing 0 instead ??? How strange, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/67193-fairly-simple-problem/#findComment-337227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.