mardi 1 septembre 2015

Code give a black page [duplicate]

This question already has an answer here:

i just made a very simple and probobly not so balanced and not so good code. It works like this, user in my webpage page press button it take some amount of coins from him and then in exchange give a random item in random amount to user. All works just good but i have a problem that sometimes it gives a blank page and coins are still taken from users but they wont get any in exchange. Maybe too much rand functions ?

Maybe someone can give me sample how to make it more balanced and fix black page bug.

Thank you and sorry for my English.

Code::

function buyblackbox(){
global $USER, $PLANET, $LNG, $UNI, $CONF,$resource,$pricelist,$Message;
$blackbox = HTTP::_GP('blackbox', 0);
$price = 10000 * $blackbox;
$timer = time();
/////
$l = mt_rand(1,9);
$i = mt_rand(1,9);
$loli   = max($l,$i);
/////
$dmatter = mt_rand(145000,210000);
///
$o = mt_rand(1,15);
$n = mt_rand(1,15);
$oneal = min($o,$n);
///
/////
$x = mt_rand(110,300);
$y = mt_rand(110,300);
////
$m32 = min($x,$y);
$canyon = mt_rand(18,50);
$emiter = mt_rand(30,70);
//////
/////
$w = mt_rand(158,280);
$z = mt_rand(158,280);
$academy = min($w,$z);
////
$x = mt_rand(150,500);
$y = mt_rand(150,500);
$pexp = min($x,$y);
///////
$x = mt_rand(150,400);
$y = mt_rand(150,400);
$cexp = min($x,$y);
///
$userIdLocal=$USER['id'];
$userIdPlanet=$PLANET['id'];
if ($price < 0) {
$this->printMessage("Hack attempt.", true, array('game.php?page=premium', 2));
}
if($USER['antimatter'] < $price){
$this->printMessage("You do not have enough antimatter", true, array('game.php?page=premium', 2));
die();
}
elseif($blackbox < 0){
$this->printMessage("Hack attempt.", true, array('game.php?page=premium', 2));
die();
}else{
    $USER['antimatter'] -= $price;
$GLOBALS['DATABASE']->query("UPDATE ".USERS." SET `darkbox` = '".$loli."', `antimatter` = `antimatter` - '".$price."' WHERE `id` = ".$userIdLocal.";");
if($USER['darkbox'] == 9)
{
$GLOBALS['DATABASE']->query("Update ".USERS." SET  `experience_peace` = `experience_peace` + '".$pexp."' WHERE `id` = ".$USER['id']." ;
"); 
$this->printMessage("You have won ".$pexp." peace experiance points", true, array('game.php?page=premium', 2));
}
if($USER['darkbox'] == 8)
{
$GLOBALS['DATABASE']->query("Update ".USERS." SET  `experience_combat` = `experience_combat` + '".$cexp."' WHERE `id` = ".$USER['id']." ;
"); 
$this->printMessage("You have won ".$cexp." combat experiance points", true, array('game.php?page=premium', 2));
}
if($USER['darkbox'] == 2)
{
$USER['darkmatter'] += $dmatter;
$this->printMessage("You have won ".$dmatter." units of Dark Matter ", true, array('game.php?page=premium', 2));
}
if($USER['darkbox'] == 3)
{
$GLOBALS['DATABASE']->query("UPDATE ".PLANETS." SET  `M32` = `M32` + '".$m32."' WHERE `id` = ".$userIdPlanet.";");  
$this->printMessage("You have won ".$m32." units of M32 Heavy Class battle ships", true, array('game.php?page=premium', 2));
}
if($USER['darkbox'] == 4)
{
$GLOBALS['DATABASE']->query("UPDATE ".PLANETS." SET  `bs_class_oneil` = `bs_class_oneil` + '".$oneal."' WHERE `id` = ".$userIdPlanet.";");  
$this->printMessage("You have won ".$oneal." units of Battleship class ONill  ", true, array('game.php?page=premium', 2));
}
if($USER['darkbox'] == 5)
{
$GLOBALS['DATABASE']->query("UPDATE ".PLANETS." SET  `canyon` = `canyon` + '".$canyon."' WHERE `id` = ".$userIdPlanet.";");
$this->printMessage("You have won ".$canyon." units of Canyon defense ", true, array('game.php?page=premium', 2));
}
if($USER['darkbox'] == 6)
{
$GLOBALS['DATABASE']->query("UPDATE ".PLANETS." SET  `particle_emitter` = `particle_emitter` + '".$emiter."' WHERE `id` = ".$userIdPlanet.";");
$this->printMessage("You have won ".$emiter." units of Particle Emitter  ", true, array('game.php?page=premium', 2));
}
if($USER['darkbox'] == 7)
{
$GLOBALS['DATABASE']->query("UPDATE ".USERS." SET  `academy_p` = `academy_p` + '".$academy."' WHERE `id` = ".$userIdLocal.";");
$this->printMessage("You have won ".$academy." Academy points", true, array('game.php?page=premium', 2));
}
//////GRAND PRICE /////
if($USER['darkbox'] == 1)
{
$USER['antimatter'] += 80000;
SendSimpleMessage(1, '', $timer, 4, 'System', 'Grand Price', 'User have won grand price. <br> Grand Price user ID  '.$userIdLocal.' account.');
$this->printMessage("<h2>!!!YOU HAVE WON THE GRAND PRICE 80.000 ANTIMATTER!!!<h2>", true, array('game.php?page=premium', 2));
}
}
die();
}




Aucun commentaire:

Enregistrer un commentaire