Jump to content

Math Help...


Dark Nonique

Recommended Posts

Okay, this is a really simple question, and it's been bothering me that I can't remember...

 

But how do I get it to store a number after an equation, and use it again? It keeps pulling from the original number rather than the number outputted the first time.

 

Say for instance the opponent has 8000HP, and you deal 3400 in one hit. The code outputs that you did 3400 and then tells you how much HP remains using an HP bar as well. However, when you attack again, say you do 4000 damage (the damage ranges using a random code based between 85 and 100 for those who are curious as to the damage difference), it will say that the opponent has 4000HP remaining rather than the 600 that should be. I forgot how to set this up, and I'm feeling really stupid right now. Any one mind giving me a bit of help. >.<

Link to comment
https://forums.phpfreaks.com/topic/57598-math-help/
Share on other sites

You will have to store the HP for each character some where and then do something like this:

 

If your oppent was another human this would be a bit more tricky since you would have to send the changes to two browsers, but....

 

$_SESSION['hp'] -= $hit;

 

You would have to get $hit from some where, and of course you could use something besides a session, but I don't know how I would go about doing this lol

Link to comment
https://forums.phpfreaks.com/topic/57598-math-help/#findComment-285079
Share on other sites

Okay, well, currently...I have this. 

 

*NOTE* This is solely a BETA for the moment...

 

<?php

$EnemyHP = 8000;

 

function SpecialAttack($Level, $BasePower, $SpAtk, $SpDef, $Crit, $STAB, $Type1, $Type2){

    $damage = floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(2 + ($Level * 0.4)) * $BasePower * $SpAtk) / $SpDef) / 50) + 2) * $Crit) * (rand(85, 100)) / 100) * $STAB) * $Type1) * $Type2);

    return $damage;

}

 

 

function Attack($Level, $BasePower, $Atk, $Def, $Crit, $STAB, $Type1, $Type2){

    $damage = floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(2 + ($Level * 0.4)) * $BasePower * $Atk) / $Def) / 50) + 2) * $Crit) * (rand(85, 100)) / 100) * $STAB) * $Type1) * $Type2);

    return $damage;

}

 

 

 

$Damage1 = 0;

echo "Before the function, Damage = ". $Damage1 ."<br />";

$SpA = SpecialAttack(1000, 120, 2115, 2155, 1.5, 1.5, 1.5, 1);

echo "After the function, Special Attack Damage = " . $myNumber ."<br />";

 

 

$Atk = Attack(1000, 70, 2115, 2435, 1.5, 1.5, 1, 1);

echo "After the function, Attack Damage = " . $myNumber1 ."<br />";

 

$DamageDealt = $EnemyHP - $Atk;

echo "<br><br>".$DamageDealt."HP Remains";

 

$DamageDealt = $EnemyHP - $myNumber1;

echo "<br><br>".$DamageDealt."HP Remains";

?>

 

As you can see, it is obviously pulling from the fact that the HP is set to 8000. But, this is just beta testing it all before I connect it to MySQL. So, any suggestions? The algorithms and all will remain the same, but I'm not sure how to get it to take away from the current HP rather than the max. Btw, these are just the processes...lol

Link to comment
https://forums.phpfreaks.com/topic/57598-math-help/#findComment-285093
Share on other sites

Yes, but I need to know how to get it so that...erg. Like this.

 

Attack one:

Opponent has 1000 HP.

Opponent was attacked for 400 damage.

Opponent now has 600 HP.

 

Attack two:

Opponent has 600 HP.

Opponent was attacked for 500 damage.

Opponent now has 100 HP.

 

Attack three:

Opponent has 100 HP.

Opponent was attacked for 400 damage.

Opponent has been defeated.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/57598-math-help/#findComment-285108
Share on other sites

<?php

$enemyhp = 1000;

// attack1
echo "opponent has {$enemyhp}";
$damage = 50;
echo "Opponent was attacked for {$damage} damage.";
$new_enemyhp = $enemyhp-$damage;
echo "Opponent now has {$new_enemyhp} HP."
$enemyhp = new_enemyhp;

// attack2
echo "opponent has {$enemyhp}";
$damage = 50;
echo "Opponent was attacked for {$damage} damage.";
$new_enemyhp = $enemyhp-$damage;
echo "Opponent now has {$new_enemyhp} HP."
$enemyhp = new_enemyhp;

// attack3
echo "opponent has {$enemyhp}";
$damage = 50;
echo "Opponent was attacked for {$damage} damage.";
$new_enemyhp = $enemyhp-$damage;
echo "Opponent now has {$new_enemyhp} HP."
$enemyhp = new_enemyhp;

?>

 

Like that ?

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/57598-math-help/#findComment-285118
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.