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
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;
?>

Link to comment
Share on other sites

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;
?>  

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.