MadTechie Posted August 13, 2007 Share Posted August 13, 2007 ok lets see if its just taking too long will only loop 10 times (test) <?php include('inc/header.php'); $eID = $enemy->ID; $uID = (int)$_GET['ID']; if ($uID > 0) { #if called from header! $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $user = @mysql_fetch_object($usersql); echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; }else{ die("error"); } if ($enemy->ID == $user->ID) { echo' You cant attack yourself!'; } elseif ($user->hp <= 0) { echo ' You are in NO condition to do battle'; } elseif ($enemy->hp == 0) { echo ' Your Enemy Is Already Dead!'; } elseif ($user->energy <= 4) { echo ' Not enough energy!'; } elseif ($user->attack < $enemy->defense) { echo ' You look at your opponent, and wet your pants at his/her strength. You lose the battle.<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$user->ID'"); } elseif ($user->defense > $enemy->attack) { echo' Your opponent takes one look at you, and dies in fear<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$enemy->ID'"); } else { echo' Welcome to the Battle Arena.'; echo "User Start HP:".$user->hp; echo "<br>Enemy Start HP:".$enemy->hp; $attacker = ($user->agility > $enemy->agility); $uHP = $user->hp; $eHP = $enemy->hp; //temp values $edmg = 1; $udmg = 1; $count = 10; while ( $uHP > 0 && $eHP > 0 && ($edmg > 0 || $udmg > 0) && $count>0 ) { $count = $count - 1; echo "User HP:".$uHP; echo "<br>Enemy HP:".$eHP; $edmg = 0; $udmg = 0; if($attacker) { $edmg = (int)($user->attack - $enemy->defense); $eHP = (int)($eHP - edmg); echo $user->display_name." has done $edmg damage against ".$enemy->display_name."<br>"; }else{ $udmg = (int)($enemy->attack - $user->defense); $uHP = (int)($uHP - udmg); echo $enemy->display_name." has done $udmg damage against ".$user->display_name."<br>"; } $attacker = !$attacker; flush(); //add } if( $uHP == 0) { echo $enemy->display_name." Wins"; }else{ echo $user->display_name." Wins"; } mysql_query("UPDATE `users` SET hp =($eHP) WHERE ID = $enemy->ID"); mysql_query("UPDATE `users` SET hp =($uHP) WHERE ID = $user->ID"); } include('inc/footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/4/#findComment-322528 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 GOD VS. CatNCobra Welcome to the Battle Arena.User Start HP:100 Enemy Start HP:100User HP:100 Enemy HP:100CatNCobra has done 1890 damage against GOD User HP:100 Enemy HP:100GOD has done 268 damage against CatNCobra User HP:100 Enemy HP:100CatNCobra has done 1890 damage against GOD User HP:100 Enemy HP:100GOD has done 268 damage against CatNCobra User HP:100 Enemy HP:100CatNCobra has done 1890 damage against GOD User HP:100 Enemy HP:100GOD has done 268 damage against CatNCobra User HP:100 Enemy HP:100CatNCobra has done 1890 damage against GOD User HP:100 Enemy HP:100GOD has done 268 damage against CatNCobra User HP:100 Enemy HP:100CatNCobra has done 1890 damage against GOD User HP:100 Enemy HP:100GOD has done 268 damage against CatNCobra GOD WinsThis page took 0.000061 seconds to load. the HP's arent lowering, why? Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/4/#findComment-322530 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 aahhhh ahah <?php include('inc/header.php'); $eID = $enemy->ID; $uID = (int)$_GET['ID']; if ($uID > 0) { #if called from header! $enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); $enemy = @mysql_fetch_object($enemysql); $usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); $user = @mysql_fetch_object($usersql); echo "$user->display_name"; echo ' VS. ';echo "$enemy->display_name<br>"; }else{ die("error"); } if ($enemy->ID == $user->ID) { echo' You cant attack yourself!'; } elseif ($user->hp <= 0) { echo ' You are in NO condition to do battle'; } elseif ($enemy->hp == 0) { echo ' Your Enemy Is Already Dead!'; } elseif ($user->energy <= 4) { echo ' Not enough energy!'; } elseif ($user->attack < $enemy->defense) { echo ' You look at your opponent, and wet your pants at his/her strength. You lose the battle.<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$user->ID'"); } elseif ($user->defense > $enemy->attack) { echo' Your opponent takes one look at you, and dies in fear<br><br><br><br><br><br><br><br><br>'; mysql_query("UPDATE `users` SET hp = 0 WHERE ID = '$enemy->ID'"); } else { echo' Welcome to the Battle Arena.'; echo "User Start HP:".$user->hp; echo "<br>Enemy Start HP:".$enemy->hp; $attacker = ($user->agility > $enemy->agility); $uHP = $user->hp; $eHP = $enemy->hp; //temp values $edmg = 1; $udmg = 1; while ( $uHP > 0 && $eHP > 0 && ($edmg > 0 || $udmg > 0) ) { echo "User HP:".$uHP; echo "<br>Enemy HP:".$eHP; $edmg = 0; $udmg = 0; if($attacker) { $edmg = (int)($user->attack - $enemy->defense); $eHP = (int)($eHP - $edmg); echo $user->display_name." has done $edmg damage against ".$enemy->display_name."<br>"; }else{ $udmg = (int)($enemy->attack - $user->defense); $uHP = (int)($uHP - $udmg); echo $enemy->display_name." has done $udmg damage against ".$user->display_name."<br>"; } $attacker = !$attacker; flush(); //add } if( $uHP == 0) { echo $enemy->display_name." Wins"; }else{ echo $user->display_name." Wins"; } mysql_query("UPDATE `users` SET hp =($eHP) WHERE ID = $enemy->ID"); mysql_query("UPDATE `users` SET hp =($uHP) WHERE ID = $user->ID"); } include('inc/footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/4/#findComment-322533 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 Welcome to the Battle Arena.User Start HP:100 Enemy Start HP:100User HP:100 Enemy HP:100CatNCobra has done 1890 damage against GOD GOD WinsThis page took 0.000057 seconds to load. why did I win, when i got hit for 18x my HP? Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/4/#findComment-322535 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/4/#findComment-322542 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 update if( $uHP == 0) { echo $enemy->display_name." Wins"; }else{ echo $user->display_name." Wins"; } to if( $uHP == 0) { echo $enemy->display_name." Wins"; }elseif( $eHP == 0){ echo $enemy->display_name." Wins"; }else{ //neither did any damage (stops inf. loop) echo "Attack was unsuccesful"; } Also PLEASE don't bump your post unless an hour has passed.. Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/4/#findComment-322545 Share on other sites More sharing options...
uwannadonkey Posted August 13, 2007 Author Share Posted August 13, 2007 oops! my bad, lol(bout the bump!) the code, IT WORKS! thanks SO much for your time and like 40 posts. now all i got left is the ranking page( which isnt working well for me) and my crons(no idea!) Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/4/#findComment-322553 Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 Great and its my home time.. oh remember to click solved (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/64649-solved-weird-while-problem/page/4/#findComment-322558 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.