Dark Nonique Posted June 28, 2007 Share Posted June 28, 2007 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. >.< Quote Link to comment Share on other sites More sharing options...
corbin Posted June 28, 2007 Share Posted June 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 28, 2007 Share Posted June 28, 2007 $hp = 40; $damage = 10; $new_hp = $hp-$damage; Do you mean something like that ? Quote Link to comment Share on other sites More sharing options...
chigley Posted June 28, 2007 Share Posted June 28, 2007 <?php $opponenthealth = 8000; /* Attack One */ echo "You hit for 3400HP!<br />"; $opponenthealth -= 3400; /* Attack Two */ echo "You hit for 4000HP!<br />; $opponenthealth -= 4000; echo "Your opponent has {$opponenthealth}HP."; ?> Simple form, untested. Quote Link to comment Share on other sites More sharing options...
Dark Nonique Posted June 28, 2007 Author Share Posted June 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 28, 2007 Share Posted June 28, 2007 you could just have current hp under the enemy hp $EnemyHP = 8000; $Current_EnemyHP = 8000; Then just take everything away from $Current_EnemyHP instead of $EnemyHP ~ Chocopi Quote Link to comment Share on other sites More sharing options...
Dark Nonique Posted June 28, 2007 Author Share Posted June 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 28, 2007 Share Posted June 28, 2007 <?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 Quote Link to comment Share on other sites More sharing options...
Dark Nonique Posted June 28, 2007 Author Share Posted June 28, 2007 Yes! I believe that will work for me. lol. I'll run it through and test it now. Thank you so much. *feels like a noob* Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.