Jump to content

PHP Warning: "Division by zero"


Natloy90

Recommended Posts

Im running an online text based game and recently done some core edits. I've run into an error and can't seem to find the problem, the error im getting is:

 

PHP Warning: "Division by zero"

in /home/f/i/firestorms/public_html/modules/healthbar.php at 52.

Call Stack:

2: healthbar_dohook("charstats", Array(

 

    "available"=>10, "used"=>0

 

)) called from /home/f/i/firestorms/public_html/lib/modules.php on line 514

3: modulehook("charstats") called from /home/f/i/firestorms/public_html/lib/pageparts.php on line 692

4: charstats() called from /home/f/i/firestorms/public_html/lib/pageparts.php on line 124

5: page_footer() called from /home/f/i/firestorms/public_html/newday.php on line 323

 

My code is:

 

function healthbar_dohook($hookname,$args){

global $session;

switch($hookname){

case "charstats":

if ($session['user']['alive']) {

$cur = $session['user']['hitpoints'];

$realmax = $session['user']['maxhitpoints'];

$stat = "Hitpoints";

$cur_adjustment = check_temp_stat("hitpoints",1);

$max_adjustment = check_temp_stat("maxhitpoints",1);

} else {

$cur = $session['user']['soulpoints'];

$realmax = $session['user']['level'] * 5 + 50;

$stat = "Soulpoints";

$cur_adjustment = check_temp_stat("soulpoints",1);

$max_adjustment = "";

}

if ($cur > $realmax) $max = $cur;

else $max = $realmax;

 

$pct = round($cur / $max * 100, 0);

$nonpct = 100-$pct;

if ($pct > 100) {

$pct = 100;

$nonpct = 0;

}

if ($pct < 0) {

$pct = 0;

$nonpct = 100;

}

if ($pct > 60) {

if ($session['user']['alive']) $color = "#00ff00";

else $color = "#dddddd";

$ccode = "`@";

} elseif ($pct > 25) {

if ($session['user']['alive']) $color = "#ffff00";

else $color = "#666666";

$ccode = "`^";

} else {

if ($session['user']['alive']) $color = "#ff0000";

else $color = "#880000";

$ccode = "`$";

}

$hicode = "`&";

if (!$session['user']['alive']) {

$ccode = "`7";

}

 

The Bold piece of the code is the line of 'error' in /home/f/i/firestorms/public_html/modules/healthbar.php at 52.

Link to comment
https://forums.phpfreaks.com/topic/99693-php-warning-division-by-zero/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.