Twysted Posted November 9, 2006 Share Posted November 9, 2006 ok what i want to do on this is make it where if attacker is success, loser loses defenive men. can someone show me how i would go about making it that way?[code]<?php$isadmin = "*";include( "../includes/inc-header.php" );if ( !$_GET['id'] && !$_POST['turns'] && !$_POST['id'] ) { $users_total = $db->fetch( $db->query( "SELECT count(*) FROM users" ) ); $pages = ceil( $users_total[0] / 25 ); if ( $_GET['p'] ) { $currentpage = round( $_GET['p'] ); } else { $currentpage = round( $_POST['page'] )-1; } if ( $currentpage < 1 ) { $currentpage = 0; } if ( $currentpage + 1 > $pages ) { $currentpage = $pages-1; } $lmin = $currentpage * 25; $lmax = $lmin + 25; if ( $_POST['find_username'] ) { $theuser = htmlentities( stripslashes( $_POST['username'] ) ); $whereclause = " WHERE uLogin LIKE \"%$theuser%\""; } ?> <form action="attack.php" method="post"> <table width="100%" border="0"> <tr> <td class="bodycell3" width="50%">Find By Page</td> <td class="bodycell3" width="50%">Find By Username</td> </tr> <tr> <td class="bodycell4" width="50%" align="center"> <br> <input name="page" size="5" maxlength="10" type="number"> / <?=$pages?><br><br> <input name="find_page" value="Submit" type="submit"><br><br> </td> <td class="bodycell4" width="50%" align="center"> <br> <input name="username" size="10" maxlength="30" type="text"><br><br> <input name="find_username" value="Submit" type="submit"><br><br> </td> </tr> </table> </form> <?php $x = $currentpage * 25; if ( $x < 0 ) { $x = 0; } $column1 .= "<b>Rank</b><br>"; $column2 .= "<b>Username</b><br>"; $column3 .= "<b>Gold</b><br>"; $column4 .= "<b>Army Size</b><br>"; $column5 .= "<b>Level</b><br>"; $thequery = "SELECT uID,uLogin,(uOffensiveMen+uDefensiveMen) AS uArmySize,uGold,uLevel FROM users$whereclause ORDER BY uEXP DESC LIMIT $lmin, 25"; $result = $db->query( $thequery ); while ( $themost = $db->fetch( $result ) ) { $x++; $column1 .= "<hr>$x<br>"; $column2 .= "<hr><a href=\"profile.php?id=" . $themost['uID'] . "\">" . $themost['uLogin'] . "</a> "; $isonline = $db->fetch( $db->query( "SELECT uID FROM users_online WHERE uTime>'$mintime15' AND uID='" . $themost['uID'] . "'" ) ); if ( $isonline ) { $column2 .= " [Online]<br>"; } else { $column2 .= "<br>"; } $column3 .= "<hr>" . $themost['uGold'] . "<br>"; $column4 .= "<hr>" . $themost['uArmySize'] . "<br>"; $column5 .= "<hr>" . $themost['uLevel'] . "<br>"; } ?> <table width="100%" border="0"> <tr> <td class="bodycell3">Attack</td> </tr> <tr> <td class="bodycell4"> <table width="90%" border="0" align="center"> <tr> <td align="left"> <?php if ( $currentpage > 0 ) { ?> <a href="attack.php?p=<?=$currentpage-1?>">Previous</a> <?php } else { echo "Previous"; } ?> </td> <td align="right"> <?php if ( $currentpage + 1 < $pages ) { ?> <a href="attack.php?p=<?=$currentpage + 1?>">Next</a> <?php } else { echo "Next"; } ?> </td> </tr> </table> </td> </tr> <tr> <td class="bodycell4"> <table width="100%" border="0"> <tr> <td width="10%" align="center"> <?=$column1?> </td> <td width="35%"> <?=$column2?> </td> <td width="25%" align="center"> <?=$column3?> </td> <td width="20%" align="center"> <?=$column4?> </td> <td width="10%" align="center"> <?=$column5?> </td> </tr> </table> </td> </tr> <tr> <td class="bodycell4"> <table width="90%" border="0" align="center"> <tr> <td align="left"> <?php if ( $currentpage > 0 ) { ?> <a href="attack.php?p=<?=$currentpage-1?>">Previous</a> <?php } else { echo "Previous"; } ?> </td> <td align="right"> <?php if ( $currentpage + 1 < $pages ) { ?> <a href="attack.php?p=<?=$currentpage + 1?>">Next</a> <?php } else { echo "Next"; } ?> </td> </tr> </table> </td> </tr> </table> <?php} elseif ( $_GET['id'] ) { $theid = round( $_GET['id'] ); $result = $db->query( "SELECT uID,uLogin FROM users WHERE uID=\"$theid\"" ); $enemy = $db->fetch( $result ); ?> <table width="100%" border="0"> <tr> <td class="bodycell3">Attack</td> </tr> <tr> <td class="bodycell4" align="center"> <?php if ( !$enemy ) { echo "This player does not exist."; } elseif ( $enemy['uID'] == $user['uID'] ) { echo "You can not attack yourself."; } else { echo "<form action=\"attack.php\" method=\"post\">"; echo "<br>You have " . $user['uAttackTurns'] . " attack turns available to use against " . $enemy['uLogin'] . ".<br><br>"; echo "<input name=\"id\" type=\"hidden\" value=\"" . $enemy['uID'] . "\">"; echo "<input name=\"turns\" type=\"text\" size=\"5\" maxlength=\"$theid\"> / " . $SETTINGS['max_atk_turns'] . "<br><br>"; echo "<input name=\"attack\" type=\"submit\" value=\"Attack\"><br>"; echo "</form>"; } ?> </td> </tr> </table> <?php} elseif ( $_POST['turns'] && $_POST['id'] ) { $turns = round( str_replace( "-", "", $_POST['turns'] ) ); $theid = round( $_POST['id'] ); $result = $db->query( "SELECT * FROM users WHERE uID=\"$theid\"" ); $enemy = $db->fetch( $result ); ?> <table width="100%" border="0"> <tr> <td class="bodycell3">Attack</td> </tr> <tr> <td class="bodycell4" align="center"> <?php $timeminus24 = time() - ( 60 * 60 * 24 ); $query = "SELECT count(*) FROM logs WHERE lOther='" . $enemy['uID'] . "' AND lYou='" . $user['uID'] . "' AND lType='2' AND lTime2>'$timeminus24'"; $timesbattled = $db->fetch( $db->query( $query ) ); if ( !$enemy ) { echo "This player does not exist."; } elseif ( $enemy['uID'] == $user['uID'] ) { echo "You can not attack yourself."; } elseif ( $turns < 1 || $turns > $SETTINGS['max_atk_turns'] ) { echo "You must enter a valid amount of attack turns to use."; } elseif ( $turns > $user['uAttackTurns'] ) { echo "You don't have enough turns."; } elseif ( $enemy['uLevel'] < $user['uLevel'] - $SETTINGS['lvls_below'] ) { echo "You can't battle someone more than " . $SETTINGS['lvls_below'] . " levels below you."; } elseif ( $enemy['uLevel'] > $user['uLevel'] + $SETTINGS['lvls_above'] ) { echo "You can't battle someone more than " . $SETTINGS['lvls_above'] . " levels above you."; } elseif ( $timesbattled[0] >= $SETTINGS['attacks_24'] ) { echo "You can't battle someone more than " . $SETTINGS['attacks_24'] . " times in 24 hours."; } else { $weaponz1 = explode( ";", $user['uWeapon1'] . ";" . $user['uWeapon2'] . ";" . $user['uWeapon3'] . ";" . $user['uWeapon4'] . ";" . $user['uWeapon5'] ); $weaponz2 = explode( ";", $SETTINGS['wp_1_dmg'] . ";" . $SETTINGS['wp_2_dmg'] . ";" . $SETTINGS['wp_3_dmg'] . ";" . $SETTINGS['wp_4_dmg'] . ";" . $SETTINGS['wp_5_dmg'] ); $menleft = $user['uOffensiveMen']; $offense = $user['uOffense'] + ( $menleft * 250 ); $x = 0; while ( $x < 5 && $menleft != 0 ) { if ( $weaponz1[$x] >= $menleft ) { $offense = $offense + ( $menleft * $weaponz2[$x] ); $menleft = 0; } else { $offense = $offense + ( $weaponz1[$x] * $weaponz2[$x] ); $menleft = $menleft - $weaponz1[$x]; } $x++; } $armourz1 = explode( ";", $enemy['uArmour1'] . ";" . $enemy['uArmour2'] . ";" . $enemy['uArmour3'] . ";" . $enemy['uArmour4'] . ";" . $enemy['uArmour5'] ); $armourz2 = explode( ";", $SETTINGS['ar_1_dmg'] . ";" . $SETTINGS['ar_2_dmg'] . ";" . $SETTINGS['ar_3_dmg'] . ";" . $SETTINGS['ar_4_dmg'] . ";" . $SETTINGS['ar_5_dmg'] ); $menleft = $enemy['uDefensiveMen']; $defense = $enemy['uDefense'] + ( $menleft * 250 ); $x = 0; while ( $x < 5 && $menleft != 0 ) { if ( $armourz1[$x] >= $menleft ) { $defense = $defense + ( $menleft * $armourz2[$x] ); $menleft = 0; } else { $defense = $defense + ( $armourz1[$x] * $armourz2[$x] ); $menleft = $menleft - $armourz1[$x]; } $x++; } if ( $offense == $defense ) { if ( rand( 1, 2 ) == 1 ) { $offense += 50 * rand( 1, 6 ); } else { $offense += 50 * rand( 1, 6 ); } } echo "<br>Your " . $user['uOffensiveMen'] . " offensive men attack for $offense offense.<br><br>"; echo $enemy['uLogin'] . " defends your attack with $defense defense.<br><br>"; $time = time(); if ( $offense > $defense ) { $gold_gained_work = $enemy['uGold'] / 20; $gold_gained = $gold_gained_work * $turns; $exp_gained_work = rand( 1000, 3500 ); $exp_gained_work2 = $exp_gained_work / 10; $exp_gained = $exp_gained_work2 * $turns; echo "You defeated " . $enemy['uLogin'] . ", you have gained $gold_gained gold and also $exp_gained exp.<br>"; $user['uEXP'] = $user['uEXP'] + $exp_gained; $db->query( "UPDATE users SET uGold=uGold+'$gold_gained',uEXP=uEXP+'$exp_gained',uWon=uWon+'1',uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" ); $db->query( "UPDATE users SET uGold=uGold-'$gold_gained',uLost=uLost+'1' WHERE uID='" . $enemy['uID'] . "'" ); $db->query( "INSERT INTO logs (`lType`,`lWinLose`,`lYou`,`lOther`,`lOtherLogin`,`lTurns`,`lGold`,`lEXP`,`lTime`,`lTime2`) VALUES ('2', '1', '" . $user['uID'] . "', '" . $enemy['uID'] . "', '" . $enemy['uLogin'] . "', '$turns', '$gold_gained', '$exp_gained', \"$gamedate\", '$time')" ); $db->query( "INSERT INTO logs (`lType`,`lWinLose`,`lYou`,`lOther`,`lOtherLogin`,`lTurns`,`lGold`,`lEXP`,`lTime`,`lTime2`) VALUES ('1', '2', '" . $enemy['uID'] . "', '" . $user['uID'] . "', '" . $user['uLogin'] . "', '$turns', '-$gold_gained', '0', \"$gamedate\", '$time')" ); if ( $user['uEXP'] > $user['uNextLevel'] ) { $at = $user['uNextLevel'] / 2; $add = $user['uNextLevel'] + $at; echo "<br>You have gained a level.<br>"; $db->query( "UPDATE users SET uLevel=uLevel+'1',uNextLevel=uNextLevel+'$add' WHERE uID='" . $user['uID'] . "'" ); } } elseif ( $offense < $defense ) { $gold_lost_work = $user['uGold'] / 40; $gold_lost = $gold_lost_work * $turns; $exp_gained_work = rand( 1000, 3500 ); $exp_gained_work2 = $exp_gained_work / 20; $exp_gained = $exp_gained_work2 * $turns; echo $enemy['uLogin'] . " defeated you, you have lost $gold_lost gold.<br>"; $enemy['uEXP'] = $enemy['uEXP'] + $exp_gained; $db->query( "UPDATE users SET uGold=uGold-'$gold_lost',uLost=uLost+'1',uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'" ); $db->query( "UPDATE users SET uGold=uGold+'$gold_lost',uWon=uWon+'1',uEXP=uEXP+'$exp_gained' WHERE uID='" . $enemy['uID'] . "'" ); $db->query( "INSERT INTO logs (`lType`,`lWinLose`,`lYou`,`lOther`,`lOtherLogin`,`lTurns`,`lGold`,`lEXP`,`lTime`,`lTime2`) VALUES ('2', '2', '" . $user['uID'] . "', '" . $enemy['uID'] . "', '" . $enemy['uLogin'] . "', '$turns', '-$gold_lost', '0', \"$gamedate\", '$time')" ); $db->query( "INSERT INTO logs (`lType`,`lWinLose`,`lYou`,`lOther`,`lOtherLogin`,`lTurns`,`lGold`,`lEXP`,`lTime`,`lTime2`) VALUES ('1', '1', '" . $enemy['uID'] . "', '" . $user['uID'] . "', '" . $user['uLogin'] . "', '$turns', '$gold_lost', '$exp_gained', \"$gamedate\", '$time')" ); if ( $enemy['uEXP'] > $enemy['uNextLevel'] ) { $at = $enemy['uNextLevel'] / 2; $add = $enemy['uNextLevel'] + $at; echo "<br>" . $enemy['uLogin'] . " has gained a level.<br>"; $db->query( "UPDATE users SET uLevel=uLevel+'1',uNextLevel=uNextLevel+'$add' WHERE uID='" . $enemy['uID'] . "'" ); } } echo "<br>"; } ?> </td> </tr> </table> <?php} include( "../includes/inc-footer.php" );?>[/code] Quote Link to comment Share on other sites More sharing options...
Solution Twysted Posted November 10, 2006 Author Solution Share Posted November 10, 2006 any help at all? 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.