Jump to content

PHP not calculating properly?


GateGuardian

Recommended Posts

<?php
$userattack = $POST_['attack'];
$userstrength = $POST_['strength'];
$mobagility = $POST_['agility'];
$mobdefence = $POST_['defence'];

$userattacknum = Rand(1,1000);

$attackresult = ($userattacknum + $userattack) - ($mobagility * 3);
echo $attackresult;

if ($attackresult >= 950) {
    $attacktype = "crit";
} elseif ($attackresult <= 399 ) {
    $attacktype = "miss";
} elseif ($attackresult <= 949 || $attackresult >= 400) {
    $attacktype = "norm";
}
echo $attacktype;
$random1 = rand(1,50);
$random2 = rand(1,5);
$random3 = rand(1,5);

echo $random1;
echo $random2;
echo $random3;

switch ($attacktype){
case "miss":
	echo "You missed your target!";
	break;
case "norm":
        $attackdamage = (($random1 * $userstrength) - $mobdefence) * $random2;
        echo "You hit the target for: ".$attackdamage."!";
	break;
case "crit":
        $attackdamage = ((($random1 * $userstrength) - $mobdefence) * $random2) * $random3;
  		echo "You <b>CRITICALY</b> hit the target for: ".$attackdamage."!";
  		break;
}
echo $attackdamage;
?>

 

$attackdamage is always calculated to 0 and when the attacknumber is over 900 it don't regard it as a critical hit

 

help anyone?

Link to comment
https://forums.phpfreaks.com/topic/91196-php-not-calculating-properly/
Share on other sites

<?php
$userattack = $_POST['attack'];
$userstrength = $_POST['strength'];
$mobagility = $_POST['agility'];
$mobdefence = $_POST['defence'];

$userattacknum = Rand(1,1000);

$attackresult = ($userattacknum + $userattack) - ($mobagility * 3);
echo $attackresult;

if ($attackresult >= 950) {
    $attacktype = "crit";
} elseif ($attackresult <= 399 ) {
    $attacktype = "miss";
} elseif ($attackresult <= 949 || $attackresult >= 400) {
    $attacktype = "norm";
}
echo $attacktype;
$random1 = rand(1,50);
$random2 = rand(1,5);
$random3 = rand(1,5);

echo $random1;
echo $random2;
echo $random3;

switch ($attacktype){
case "miss":
	echo "You missed your target!";
	break;
case "norm":
        $attackdamage = (($random1 * $userstrength) - $mobdefence) * $random2;
        echo "You hit the target for: ".$attackdamage."!";
	break;
case "crit":
        $attackdamage = ((($random1 * $userstrength) - $mobdefence) * $random2) * $random3;
  		echo "You <b>CRITICALY</b> hit the target for: ".$attackdamage."!";
  		break;
}
echo $attackdamage;
?>

i would recomend Jedit or PHP Designer 2007

 

also your math is abit dodgy try:

 

<?php
$userattack = $_POST['attack'];
$userstrength = $_POST['strength'];
$mobagility = $_POST['agility'];
$mobdefence = $_POST['defence'];

$userattacknum = Rand(1,1000);

$attackresult = ($userattacknum + $userattack) - ($mobagility * 3);
echo $attackresult;

if ($attackresult >= 950) {
    $attacktype = "crit";
} elseif ($attackresult <= 399 ) {
    $attacktype = "miss";
} elseif ($attackresult <= 949 || $attackresult >= 400) {
    $attacktype = "norm";
}
echo $attacktype;
$random1 = rand(1,50);
$random2 = rand(1,5);
$random3 = rand(1,5);

echo $random1;
echo $random2;
echo $random3;

switch ($attacktype){
case "miss":
	echo "You missed your target!";
	break;
case "norm":
        $attackdamage = ($random1 * $userstrength - $mobdefence)* $random2;
        echo "You hit the target for: ".$attackdamage."!";
	break;
case "crit":
        $attackdamage =($random1 * $userstrength- $mobdefence) * ($random2 + $random3);
  		echo "You <b>CRITICALY</b> hit the target for: ".$attackdamage."!";
  		break;
}
echo $attackdamage;
?>  

I used phpdesigner - its good for the money, but I prefer zend. I like the autocompletion of php functions, and I like it that it logs variables and functions that you have written so that you can autocomplete with them as well.

 

I will have to check out DevPHP, I've never heard of or tried that one.

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.