beansandsausages Posted January 23, 2008 Share Posted January 23, 2008 Good morning freaks. I have this simple script : <? include("connect"); //this file will be all in php //if user did not select who to attack, we show him list of users if (!$_GET[attack]) { //we select id and username of everyone except us $battleQ = mysql_query("SELECT id,username FROM users WHERE id<>'$user[id]'"); while ($battle = mysql_fetch_array($battleQ)) { //we show all selected users as well as link to their "attack" subpage echo "$battle[username] => <a href=\"battle.php?attack=".$battle[id]."\">attack</a> <br>"; } } //if user selected link to attack player if ($_GET[attack]) { $attack_id = $_GET[attack]; //we check if ID submited is numerical if (!is_numeric($attack_id)) { die("Bad target ID!"); } //we select user with that ID $attackQ = mysql_query("SELECT * FROM users WHERE id='$user[id]' LIMIT 1"); $attackR = mysql_num_rows($attackQ); //we check that rows are 1. if there are zero rows this means user is modifying link so we close our script! if ($attackR <> 1) { die("Bad target ID!"); } //all is fine, we select attacked user $attack = mysql_fetch_array($attackQ); //now we divide weapons to our people if ($user[weapon3]<=$user[units]) { //if weapon3 is more or the same of all people, then all people have it $user_w3 = $user[units]; }else{ //only some users get weapon3 $user_w3 = $user[weapon3]; } if ($user[weapon2]<=($user[units]-$user_w3)) { //if weapon2 is more or the same of our people without any weapons, then they have it $user_w2 = $user[units]-$user_w3; }else{ //only some users get weapon3 $user_w2 = $user[weapon2]; } if ($user[weapon1]<=($user[units]-$user_w3-$user_w2)) { //if weapon1 is more or the same of our people without any weapons, then they have it $user_w1 = $user[units]-$user_w3-$user_w2; }else{ //only some users get weapon3 $user_w1 = $user[weapon1]; } //those are our people without weapons $user_w0 = $user[units]-$user_w3-$user_w2-$user_w1; //now we calculate our strength $user_strength = $user_w0*100 + $user_w1*200 + $user_w2*400 + $user_w3*800; //We do the same thing for attacked player //now we divide weapons to attacker if ($attack[weapon3]<=$attack[units]) { $target_w3 = $attack[units]; }else{ $target_w3 = $attack[weapon3]; } if ($attack[weapon2]<=($attack[units]-$target_w3)) { $target_w2 = $attack[units]-$target_w3; }else{ $target_w2 = $attack[weapon2]; } if ($attack[weapon1]<=($attack[units]-$target_w3-$target_w2)) { $target_w1 = $attack[units]-$target_w3-$target_w2; }else{ $target_w1 = $attack[weapon1]; } //those are people who we attacked without weapons $target_w0 = $attack[units]-$target_w3-$target_w2-$target_w1; //now we calculate defender strength $target_strength = $target_w0*100 + $target_w1*200 + $target_w2*400 + $target_w3*800; //now to calculate casualties; we would divide strength with four (4) and then check the percentage of troops died $att_cas = $target_strength/4; $def_cas = $user_strength/4; //we create formula but see that we have $target_w0 on both sides of / so we can use simple formula $target_w0_die = ($def_cas/$target_w0*100)*$target_w0; $target_w0_die = ($def_cas/100); //we cannot have more death people then we have if ($target_w0_die >) { $target_w0_die=$target_w0; } $target_w1_die = ($def_cas/200); if ($target_w1_die >) { $target_w1_die=$target_w1; } $target_w2_die = ($def_cas/400); if ($target_w2_die >) { $target_w2_die=$target_w2; } $target_w3_die = ($def_cas/800); if ($target_w3_die >) { $target_w3_die=$target_w3; } $target_killed = $target_w0_die+$target_w1_die+$target_w2_die+$target_w3_die; //the same for our troops $user_w0_die = ($att_cas/100); if ($user_w0_die >) { $user_w0_die=$user_w0; } $user_w1_die = ($att_cas/200); if ($user_w1_die >) { $user_w1_die=$user_w1; } $user_w2_die = ($att_cas/400); if ($user_w2_die >) { $user_w2_die=$user_w2; } $user_w3_die = ($att_cas/800); if ($user_w3_die >) { $user_w3_die=$user_w3; } $user_killed = $user_w0_die+$user_w1_die+$user_w2_die+$user_w3_die; //we have two options //attacker won if ($user_strength > $target_strength) { echo "Your troops won. You lost $user_killed units! You managed to plunder $attack[money] money."; //we update attacker and defender, add money to attacker mysql_query("UPDATE users SET money=money+'$attack[money]', units=units-'$user_killed' WHERE id='$user[id]'"); mysql_query("UPDATE users SET money='0', units=units-'$target_killed' WHERE id='$attack[id]'"); } //defender won if ($user_strength <= $target_strength) { echo "Enemy troops were too strong. You lost $user_killed units!"; //we update attacker and defender mysql_query("UPDATE users SET units=units-'$user_killed' WHERE id='$user[id]'"); mysql_query("UPDATE users SET units=units-'$target_killed' WHERE id='$attack[id]'"); } } ?> The proble is i am getting a error on line 93 and i cant seem to see it any were. The error is : Parse error: parse error in c:\phpdev\www\public\bored_stuff\battle.php on line 93 Line 93 is : if ($target_w0_die >) { $target_w0_die=$target_w0; } Just incase its not here ill post a few lines befor and after line 93 : $att_cas = $target_strength/4; $def_cas = $user_strength/4; //we create formula but see that we have $target_w0 on both sides of / so we can use simple formula $target_w0_die = ($def_cas/$target_w0*100)*$target_w0; $target_w0_die = ($def_cas/100); //we cannot have more death people then we have if ($target_w0_die >) { $target_w0_die=$target_w0; } $target_w1_die = ($def_cas/200); if ($target_w1_die >) { $target_w1_die=$target_w1; } $target_w2_die = ($def_cas/400); if ($target_w2_die >) { $target_w2_die=$target_w2; } $target_w3_die = ($def_cas/800); if ($target_w3_die >) { $target_w3_die=$target_w3; } $target_killed = $target_w0_die+$target_w1_die+$target_w2_die+$target_w3_die; Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/87341-simple-battle-script/ Share on other sites More sharing options...
Daniel0 Posted January 23, 2008 Share Posted January 23, 2008 In these lines: if ($target_w0_die >) { $target_w0_die=$target_w0; } $target_w1_die = ($def_cas/200); if ($target_w1_die >) { $target_w1_die=$target_w1; } $target_w2_die = ($def_cas/400); if ($target_w2_die >) { $target_w2_die=$target_w2; } $target_w3_die = ($def_cas/800); if ($target_w3_die >) { $target_w3_die=$target_w3; } there is no right side operand. Quote Link to comment https://forums.phpfreaks.com/topic/87341-simple-battle-script/#findComment-446719 Share on other sites More sharing options...
beansandsausages Posted January 23, 2008 Author Share Posted January 23, 2008 what you mean sorry its early my brain not working Quote Link to comment https://forums.phpfreaks.com/topic/87341-simple-battle-script/#findComment-446721 Share on other sites More sharing options...
Daniel0 Posted January 23, 2008 Share Posted January 23, 2008 Well, for instance you write $target_w0_die > You are checking to see if $target_w0_die is higher, but you do not specify what it should be higher than. You need something on the right side of the operator seeing as "greater than" is a binary operator and not a unary operator (like ! ("not") is for instance). Quote Link to comment https://forums.phpfreaks.com/topic/87341-simple-battle-script/#findComment-446728 Share on other sites More sharing options...
pdkv2 Posted January 23, 2008 Share Posted January 23, 2008 You are comparing $target_w0_die but the second variable is missing Quote Link to comment https://forums.phpfreaks.com/topic/87341-simple-battle-script/#findComment-446731 Share on other sites More sharing options...
Daniel0 Posted January 23, 2008 Share Posted January 23, 2008 Great job figuring that out. Especially seeing as I just said it Quote Link to comment https://forums.phpfreaks.com/topic/87341-simple-battle-script/#findComment-446734 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.