Samurai Legend Posted February 28 Share Posted February 28 Error - Fatal error: Uncaught TypeError: Unsupported operand types: string + int in /Users/shahed/Projects/samuraiconflict/attack.php:98 Stack trace: #0 /Users/shahed/.composer/vendor/laravel/valet/server.php(235): require() #1 {main} thrown in /Users/shahed/Projects/samuraiconflict/attack.php on line 98 Line - $ns = !isset($_GET['nextstep']) ? 1 : $_GET['nextstep'] + 2; Tried searching for the fix but I couldn't seem to get anywhere, please help! Quote Link to comment Share on other sites More sharing options...
Uridium Posted March 1 Share Posted March 1 (edited) Post or send me your attack.php Just because the line says its line 98 doesn't always mean its that line that is the cause ?? However $ns = !isset($_GET['nextstep']) ? 1 : $_GET['nextstep'] + 2; depending on whats above that line you could change to if ( !$_GET['nextstep'] ) { $ns = 1; } else { $ns = $_GET['nextstep'] + 2; } or if(!$_GET['nextstep']) { $ns=1; } else { $ns=$_GET['nextstep']+2; } But im just shooting in the dark here without seeing whats above or below Edited March 1 by Uridium fat fingers Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted March 1 Author Share Posted March 1 (edited) Still the same error, I have posted my full attack script Quote <?php define('PAGE_HEADER', 'Attacking'); $atkpage = 1; require('globals.php'); $rounds = 25; ?><h3><u>Attacking</u></h3><?php $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : ''; $prohibited = array(1); //Add player IDs to this array that you don't want to get attacks. if(in_array($_GET['ID'], $prohibited)) { ?>You cannot attack this player.<a href = 'viewuser.php?u=<?php echo $_GET['ID']; ?>'>> Go Back</a><a href = 'index.php'>> Go Home</a><?php exit($h->endpage()); } if(!$_GET['ID']) { cancelAttack('Invalid ID.'); } if($_GET['ID'] == $userid) { cancelAttack('You can\'t attack yourself.'); } if($ir['hp'] <= 1) { cancelAttack('You\'re unconcious therefore you can\'t attack.'); } if(isset($_SESSION['attacklost']) && $_SESSION['attacklost'] == 1) { $_SESSION['attacklost'] = 0; cancelAttack('Only the losers of all their EXP attack when they\'ve already lost.'); } $youdata = $ir; $odata_sql = <<<SQL SELECT `u`.`userid`, `hp`, `hospital`, `prison`, `equip_armor`, `username`, `equip_primary`, `equip_secondary`, `clan`, `location`, `maxhp`, `guard`, `agility`, `strength`, `gender`, `display_pic`, `attacks_won` FROM `users` AS `u` INNER JOIN `userstats` AS `us` ON `u`.`userid` = `us`.`userid` WHERE `u`.`userid` = {$_GET['ID']} LIMIT 1 SQL; $q = $db->query($odata_sql); if($db->num_rows($q) == 0) { cancelAttack('That user does not exist.'); } $odata = $db->fetch_row($q); $db->free_result($q); $myabbr = ($ir['gender'] == 'Male') ? 'his' : 'her'; $oabbr = ($odata['gender'] == 'Male') ? 'his' : 'her'; if($ir['attacking'] && $ir['attacking'] != $_GET['ID']) { $_SESSION['attacklost'] = 0; cancelAttack('Something went wrong.'); } if($odata['hp'] == 1) { cancelAttack('This player is unconscious.'); } if($odata['hospital']) { cancelAttack('This player is in hospital.'); } if($ir['hospital']) { cancelAttack('While in hospital you can\'t attack.'); } if($odata['prison']) { cancelAttack('This player is in prison.'); } if($ir['prison']) { cancelAttack('While in prison you can\'t attack.'); } if($odata['hp'] < 5) { cancelAttack('You can only attack those who have health.'); } else if($ir['clan'] == $odata['clan'] && $ir['clan'] > 0) { cancelAttack("You are in the same clan as {$odata['username']}!"); } else if($youdata['energy'] < $youdata['maxenergy'] / 2) { cancelAttack('You can only attack someone when you have 50% energy.'); } else if($youdata['location'] != $odata['location']) { cancelAttack('You can only attack someone in the same location!'); } $userdp = ($ir['display_pic']) ? '<img src = "' . $ir['display_pic'] . '" width = "150px" height = "150px" alt = "User Display Pic" title = "User Display Pic" />' : '<img src = "images/default_dp.png" width = "150px" height = "150px" alt = "No Avatar" title = "No Avatar" />'; $odp = ($odata['display_pic']) ? '<img src = "' . $odata['display_pic'] . '" width = "150px" height = "150px" alt = "User Display Pic" title = "User Display Pic" />' : '<img src = "images/default_dp.png" width = "150px" height = "150px" alt = "No Avatar" title = "No Avatar" />'; ?><hr width = '100%'> <table width = '100%' cellpadding = '1' cellspacing = '1' class = 'table'> <tr> <th width = '33%'><?php echo $ir['username']; ?></th> <th width = '33%'>VS</th> <th width = '33%'><?php echo username($odata['userid']); ?></th> </tr> <tr> <th width = '33%'><?php echo $userdp; ?><br/>Attacks Won: <?php echo $ir['attacks_won']; ?></th> <th width = '33%'><?php $mw = $db->query("SELECT `itmid`,`itmname` FROM `items` WHERE `itmid` IN({$ir['equip_primary']}, {$ir['equip_secondary']})"); ?>Attack with:<br /><?php if($db->num_rows($mw) > 0) { while($r = $db->fetch_row($mw)) { $ns = !isset($_GET['nextstep']) ? 1 : $_GET['nextstep'] + 2; if($r['itmid'] == $ir['equip_primary']) { ?><b>Primary Weapon:</b><?php ?><a href='attack.php?nextstep=$ns&ID=<?php echo $_GET['ID']; ?>&wepid=<?php echo $r['itmid']; ?>'> <?php echo $r['itmname']; ?></a><br /><?php } if($r['itmid'] == $ir['equip_secondary']) { ?><b>Secondary Weapon:</b><?php ?><a href='attack.php?nextstep=$ns&ID=<?php echo $_GET['ID']; ?>&wepid=<?php echo $r['itmid']; ?>'> <?php echo $r['itmname']; ?></a><br /><?php } } } else { ?>You have nothing to fight with.<?php } $db->free_result($mw); $vars['hpperc'] = round($youdata['hp'] / $youdata['maxhp'] * 100); $vars['hpopp'] = 100 - $vars['hpperc']; $vars2['hpperc'] = round($odata['hp'] / $odata['maxhp'] * 100); $vars2['hpopp'] = 100 - $vars2['hpperc']; ?></th> <th width = '33%'><?php echo $odp; ?><br/>Attacks Won: <?php echo $odata['attacks_won']; ?></th> </tr> <tr> <th width = '33%'> <img src = 'images/greenbar.gif' width = '<?php echo $vars['hpperc']; ?>' height = '10'> <img src= 'images/greybar.gif' width = '<?php echo $vars['hpopp']; ?>' height = '10'></th> <th> </th> <th width = '33%'> <img src = 'images/greenbar.gif' width = '<?php echo $vars2['hpperc']; ?>' height = '10'> <img src = 'images/greybar.gif' width = '<?php echo $vars2['hpopp']; ?>' height = '10'></th> </tr> <tr> <td colspan = '3' align = 'center'> <?php $_GET['wepid'] = (isset($_GET['wepid']) && is_numeric($_GET['wepid'])) ? abs(intval($_GET['wepid'])) : ''; if($_GET['wepid']) { $_GET['nextstep'] = (isset($_GET['nextstep']) && is_numeric($_GET['nextstep'])) ? abs(intval($_GET['nextstep'])) : 1; if($_SESSION['attacking'] == 0 && $ir['attacking'] == 0) { if($youdata['energy'] >= $youdata['maxenergy'] / 2) { $youdata['energy'] -= floor($youdata['maxenergy'] / 2); $cost = floor($youdata['maxenergy'] / 2); $db->query("UPDATE `users` SET `energy` = `energy` - {$cost} " . "WHERE `userid` = {$userid}"); $_SESSION['attacklog'] = ''; $_SESSION['attackdmg'] = 0; } else { cancelAttack("You can only attack someone when you have 50% energy."); } } $_SESSION['attacking'] = 1; $ir['attacking'] = $odata['userid']; $db->query("UPDATE `users` SET `attacking` = {$ir['attacking']} WHERE `userid` = {$userid}"); $_GET['nextstep'] = (isset($_GET['nextstep']) && is_numeric($_GET['nextstep'])) ? abs(intval($_GET['nextstep'])) : ''; if($_GET['wepid'] != $ir['equip_primary'] && $_GET['wepid'] != $ir['equip_secondary']) { $db->query("UPDATE `users` SET `exp` = 0 WHERE `userid` = {$userid}"); cancelAttack("Stop trying to abuse a game bug."); } $qo = $db->query("SELECT `itmname`, `weapon` FROM `items` WHERE `itmid` = {$_GET['wepid']} LIMIT 1"); if($db->num_rows($qo) == 0) { cancelAttack("That weapon doesn not exist."); } $r1 = $db->fetch_row($qo); $db->free_result($qo); $mydamage = (int) (($r1['weapon'] * $youdata['strength'] / ($odata['guard'] / 1.5)) * (rand(8000, 12000) / 10000)); $hitratio = max(10, min(60 * $ir['agility'] / $odata['agility'], 95)); if(rand(1, 100) <= $hitratio) { if($odata['equip_armor'] > 0) { $q3 = $db->query("SELECT `armor` FROM `items` WHERE `itmid` = {$odata['equip_armor']} LIMIT 1"); if($db->num_rows($q3) > 0) $mydamage -= $db->fetch_single($q3); $db->free_result($q3); } if($mydamage < -100000) $mydamage = abs($mydamage); else if($mydamage < 1) $mydamage = 1; $crit = rand(1, 40); if($crit == 17) $mydamage *= rand(20, 40) / 10; else if($crit == 25 OR $crit == 8) $mydamage /= (rand(20, 40) / 10); $mydamage = round($mydamage); $odata['hp'] -= $mydamage; if($odata['hp'] == 1) { $odata['hp'] = 0; $mydamage += 1; } $db->query("UPDATE `users` SET `hp` = `hp` - $mydamage WHERE `userid` = {$_GET['ID']}"); echo "<font color = 'red'>{$_GET['nextstep']}. Using your {$r1['itmname']} you hit {$odata['username']} doing $mydamage damage ({$odata['hp']})</font><br />\n"; $_SESSION['attackdmg'] += $mydamage; $_SESSION['attacklog'] .= "<font color = 'red'>{$_GET['nextstep']}. Using {$myabbr} {$r1['itmname']} {$ir['username']} hit {$odata['username']} doing $mydamage damage ({$odata['hp']})</font><br />\n"; } else { echo "<font color=red>{$_GET['nextstep']}. You tried to hit {$odata['username']} but missed ({$odata['hp']})</font><br />\n"; $_SESSION['attacklog'] .= "<font color = 'red'>{$_GET['nextstep']}. {$ir['username']} tried to hit {$odata['username']} but missed ({$odata['hp']})</font><br />\n"; } if($odata['hp'] <= 0) { $odata['hp'] = 0; $_SESSION['attackwon'] = $_GET['ID']; $db->query("UPDATE `users` SET `hp` = 0 WHERE `userid` = {$_GET['ID']}"); $db->query("UPDATE `users` SET `LWID` = {$_GET['ID']} WHERE `userid` = {$ir['userid']}"); echo "<br /> <b>What do you want to do with {$odata['username']} now?</b><br /> <form action='attackwon.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Mug Them' /></form> <form action='attackbeat.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Hospitalize Them' /></form> <form action='attacktake.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Leave Them' /></form>"; } else { $eq = $db->query("SELECT `itmname`,`weapon` FROM `items` WHERE `itmid` IN({$odata['equip_primary']}, {$odata['equip_secondary']})"); if($db->num_rows($eq) == 0) { $wep = "Fists"; $dam = (int) ((((int) ($odata['strength'] / $ir['guard'] / 100)) + 1) * (rand(8000, 12000) / 10000)); } else { $cnt = 0; while($r = $db->fetch_row($eq)) { $enweps[] = $r; ++$cnt; } $db->free_result($eq); $weptouse = rand(0, $cnt - 1); $wep = $enweps[$weptouse]['itmname']; $dam = (int) (($enweps[$weptouse]['weapon'] * $odata['strength'] / ($youdata['guard'] / 1.5)) * (rand(8000, 12000) / 10000)); } $hitratio = max(10, min(60 * $odata['agility'] / $ir['agility'], 95)); if(rand(1, 100) <= $hitratio) { if($ir['equip_armor'] > 0) { $q3 = $db->query("SELECT `armor` FROM `items` WHERE `itmid` = {$ir['equip_armor']} LIMIT 1"); if($db->num_rows($q3) > 0) $dam -= $db->fetch_single($q3); $db->free_result($q3); } if($dam < -100000) $dam = abs($dam); else if($dam < 1) $dam = 1; $crit = rand(1, 40); if($crit == 17) $dam *= rand(20, 40) / 10; else if($crit == 25 OR $crit == 8) $dam /= (rand(20, 40) / 10); $dam = round($dam); $youdata['hp'] -= $dam; if($youdata['hp'] == 1) { $dam += 1; $youdata['hp'] = 0; } $db->query("UPDATE `users` SET `hp` = `hp` - $dam WHERE `userid` = $userid"); $ns = $_GET['nextstep'] + 1; echo "<font color = 'blue'>{$ns}. Using $oabbr $wep {$odata['username']} hit you doing $dam damage ({$youdata['hp']})</font><br />\n"; $_SESSION['attacklog'] .= "<font color = 'blue'>{$ns}. Using $oabbr $wep {$odata['username']} hit {$ir['username']} doing $dam damage ({$youdata['hp']})</font><br />\n"; } else { $ns = $_GET['nextstep'] + 1; echo "<font color = 'red'>{$ns}. {$odata['username']} tried to hit you but missed ({$youdata['hp']})</font><br />\n"; $_SESSION['attacklog'] .= "<font color = 'blue'>{$ns}. {$odata['username']} tried to hit {$ir['username']} but missed ({$youdata['hp']})</font><br />\n"; } if($youdata['hp'] <= 0) { $youdata['hp'] = 0; $_SESSION['attacklost'] = 1; $db->query("UPDATE `users` SET `hp` = 0 WHERE `userid` = $userid"); echo "<form action='attacklost.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Continue' />"; } } } echo '</td></tr></table>'; $h->endpage(); @Uridium - Thank you for helping me out 10 hours ago, Uridium said: Post or send me your attack.php Just because the line says its line 98 doesn't always mean its that line that is the cause ?? However $ns = !isset($_GET['nextstep']) ? 1 : $_GET['nextstep'] + 2; $ns = !isset($_GET['nextstep']) ? 1 : $_GET['nextstep'] + 2; depending on whats above that line you could change to if ( !$_GET['nextstep'] ) { $ns = 1; } else { $ns = $_GET['nextstep'] + 2; } if ( !$_GET['nextstep'] ) { $ns = 1; } else { $ns = $_GET['nextstep'] + 2; } or if(!$_GET['nextstep']) { $ns=1; } else { $ns=$_GET['nextstep']+2; } if(!$_GET['nextstep']) { $ns=1; } else { $ns=$_GET['nextstep']+2; } But im just shooting in the dark here without seeing whats above or below Edited March 1 by Samurai Legend Quote Link to comment Share on other sites More sharing options...
Uridium Posted March 1 Share Posted March 1 have you tried without the ISSET ? Quote Link to comment Share on other sites More sharing options...
URBANZ Posted March 1 Share Posted March 1 (edited) it says the error within Unsupported operand types: string + int you need to make sure you are not mixing types and also wrap your operators correctly as could play a part in your errors. this part is clearly the error, you could try using abs and intval to correct this. $_GET['nextstep'] + 2 Edited March 1 by URBANZ Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted March 3 Author Share Posted March 3 (edited) Hello, I have fixed the issue. I forgot to echo out two statements on the links when attacking which was causing the error. However, now I am receiving the error only when the attacker is weaker than the person they are attacking. Can someone help me out on this as I have no clue on why it is throwing the error. Fatal error: Uncaught DivisionByZeroError: Division by zero in /attack.php:237 Stack trace: #0 /.composer/vendor/laravel/valet/server.php(235): require() #1 {main} thrown in /attack.php on line 237 Line 235 - 237 $dam = (int) (($enweps[$weptouse]['weapon'] * $odata['strength'] / ($youdata['guard'] / 1.5)) * (rand(8000, 12000) / 10000)); <?php define('PAGE_HEADER', 'Attacking'); $atkpage = 1; require('globals.php'); $rounds = 250; ?><h3><u>Attacking</u></h3><?php $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : ''; $_GET['nextstep'] = (isset($_GET['nextstep']) && is_numeric($_GET['nextstep'])) ? abs(intval($_GET['nextstep'])) : '0'; $prohibited = array(1); //Add player IDs to this array that you don't want to get attacks. if(in_array($_GET['ID'], $prohibited)) { ?>You cannot attack this player.<br/> <a href = 'viewuser.php?u=<?php echo $_GET['ID']; ?>'>> Go Back</a><br/> <a href = 'index.php'>> Go Home</a><?php exit($h->endpage()); } if(!$_GET['ID']) { cancelAttack('Invalid ID.'); } if($_GET['ID'] == $userid) { cancelAttack('You can\'t attack yourself.'); } if($ir['hp'] <= 1) { cancelAttack('You\'re unconcious therefore you can\'t attack.'); } if(isset($_SESSION['attacklost']) && $_SESSION['attacklost'] == 1) { $_SESSION['attacklost'] = 0; cancelAttack('Only the losers of all their EXP attack when they\'ve already lost.'); } $youdata = $ir; $odata_sql = <<<SQL SELECT `u`.`userid`, `hp`, `hospital`, `prison`, `equip_armor`, `username`, `equip_primary`, `equip_secondary`, `clan`, `location`, `maxhp`, `guard`, `agility`, `strength`, `gender`, `display_pic`, `attacks_won` FROM `users` AS `u` INNER JOIN `userstats` AS `us` ON `u`.`userid` = `us`.`userid` WHERE `u`.`userid` = {$_GET['ID']} LIMIT 1 SQL; $q = $db->query($odata_sql); if($db->num_rows($q) == 0) { cancelAttack('That user does not exist.'); } $odata = $db->fetch_row($q); $db->free_result($q); $myabbr = ($ir['gender'] == 'Male') ? 'his' : 'her'; $oabbr = ($odata['gender'] == 'Male') ? 'his' : 'her'; if($ir['attacking'] && $ir['attacking'] != $_GET['ID']) { $_SESSION['attacklost'] = 0; cancelAttack('Something went wrong.'); } if($odata['hp'] == 1) { cancelAttack('This player is unconscious.'); } if($odata['hospital']) { cancelAttack('This player is in hospital.'); } if($ir['hospital']) { cancelAttack('While in hospital you can\'t attack.'); } if($odata['prison']) { cancelAttack('This player is in prison.'); } if($ir['prison']) { cancelAttack('While in prison you can\'t attack.'); } if($odata['hp'] < 5) { cancelAttack('You can only attack those who have health.'); } else if($ir['clan'] == $odata['clan'] && $ir['clan'] > 0) { cancelAttack("You are in the same clan as {$odata['username']}!"); } else if($youdata['energy'] < $youdata['maxenergy'] / 2) { cancelAttack('You can only attack someone when you have 50% energy.'); } else if($youdata['location'] != $odata['location']) { cancelAttack('You can only attack someone in the same location!'); } if($_GET['nextstep'] > $rounds) { cancelAttack('You both have become tired and called it a draw. You have been sent home.'); } $userdp = ($ir['display_pic']) ? '<img src = "' . $ir['display_pic'] . '" width = "150px" height = "150px" alt = "User Display Pic" title = "User Display Pic" />' : '<img src = "images/default_dp.png" width = "150px" height = "150px" alt = "No Avatar" title = "No Avatar" />'; $odp = ($odata['display_pic']) ? '<img src = "' . $odata['display_pic'] . '" width = "150px" height = "150px" alt = "User Display Pic" title = "User Display Pic" />' : '<img src = "images/default_dp.png" width = "150px" height = "150px" alt = "No Avatar" title = "No Avatar" />'; ?><hr width = '100%'> <table width = '100%' cellpadding = '1' cellspacing = '1' class = 'table'> <tr> <th width = '33%'><?php echo $ir['username']; ?></th> <th width = '33%'>VS</th> <th width = '33%'><?php echo username($odata['userid']); ?></th> </tr> <tr> <th width = '33%'><?php echo $userdp; ?><br/>Attacks Won: <?php echo $ir['attacks_won']; ?></th> <th width = '33%'><?php $mw = $db->query("SELECT `itmid`,`itmname` FROM `items` WHERE `itmid` IN({$ir['equip_primary']}, {$ir['equip_secondary']})"); ?>Attack with:<br /><?php if($db->num_rows($mw) > 0) { while($r = $db->fetch_row($mw)) { $ns = !isset($_GET['nextstep']) ? 1 : $_GET['nextstep'] + 2; if($r['itmid'] == $ir['equip_primary']) { ?><b>Primary Weapon:</b><?php ?><a href='attack.php?nextstep=<?php echo $ns; ?>&ID=<?php echo $_GET['ID']; ?>&wepid=<?php echo $r['itmid']; ?>'> <?php echo $r['itmname']; ?></a><br /><?php } if($r['itmid'] == $ir['equip_secondary']) { ?><b>Secondary Weapon:</b><?php ?><a href='attack.php?nextstep=<?php echo $ns; ?>&ID=<?php echo $_GET['ID']; ?>&wepid=<?php echo $r['itmid']; ?>'> <?php echo $r['itmname']; ?></a><br /><?php } } } else { ?>You have nothing to fight with.<?php } $db->free_result($mw); $vars['hpperc'] = round($youdata['hp'] / $youdata['maxhp'] * 100); $vars['hpopp'] = 100 - $vars['hpperc']; $vars2['hpperc'] = round($odata['hp'] / $odata['maxhp'] * 100); $vars2['hpopp'] = 100 - $vars2['hpperc']; ?></th> <th width = '33%'><?php echo $odp; ?><br/>Attacks Won: <?php echo $odata['attacks_won']; ?></th> </tr> <tr> <th width = '33%'> <img src = 'images/greenbar.gif' width = '<?php echo $vars['hpperc']; ?>' height = '10'> <img src= 'images/greybar.gif' width = '<?php echo $vars['hpopp']; ?>' height = '10'></th> <th> </th> <th width = '33%'> <img src = 'images/greenbar.gif' width = '<?php echo $vars2['hpperc']; ?>' height = '10'> <img src = 'images/greybar.gif' width = '<?php echo $vars2['hpopp']; ?>' height = '10'></th> </tr> <tr> <td colspan = '3' align = 'center'> <?php $_GET['wepid'] = (isset($_GET['wepid']) && is_numeric($_GET['wepid'])) ? abs(intval($_GET['wepid'])) : ''; if($_GET['wepid']) { $_GET['nextstep'] = (isset($_GET['nextstep']) && is_numeric($_GET['nextstep'])) ? abs(intval($_GET['nextstep'])) : 1; if($_SESSION['attacking'] == 0 && $ir['attacking'] == 0) { if($youdata['energy'] >= $youdata['maxenergy'] / 2) { $youdata['energy'] -= floor($youdata['maxenergy'] / 2); $cost = floor($youdata['maxenergy'] / 2); $db->query("UPDATE `users` SET `energy` = `energy` - {$cost} " . "WHERE `userid` = {$userid}"); $_SESSION['attacklog'] = ''; $_SESSION['attackdmg'] = 0; } else { cancelAttack("You can only attack someone when you have 50% energy."); } } $_SESSION['attacking'] = 1; $ir['attacking'] = $odata['userid']; $db->query("UPDATE `users` SET `attacking` = {$ir['attacking']} WHERE `userid` = {$userid}"); $_GET['nextstep'] = (isset($_GET['nextstep']) && is_numeric($_GET['nextstep'])) ? abs(intval($_GET['nextstep'])) : ''; if($_GET['wepid'] != $ir['equip_primary'] && $_GET['wepid'] != $ir['equip_secondary']) { $db->query("UPDATE `users` SET `exp` = 0 WHERE `userid` = {$userid}"); cancelAttack("Stop trying to abuse a game bug."); } $qo = $db->query("SELECT `itmname`, `weapon` FROM `items` WHERE `itmid` = {$_GET['wepid']} LIMIT 1"); if($db->num_rows($qo) == 0) { cancelAttack("That weapon doesn not exist."); } $r1 = $db->fetch_row($qo); $db->free_result($qo); $mydamage = (int) (($r1['weapon'] * $youdata['strength'] / ($odata['guard'] / 1.5)) * (rand(8000, 12000) / 10000)); $hitratio = max(10, min(60 * $ir['agility'] / $odata['agility'], 95)); if(rand(1, 100) <= $hitratio) { if($odata['equip_armor'] > 0) { $q3 = $db->query("SELECT `armor` FROM `items` WHERE `itmid` = {$odata['equip_armor']} LIMIT 1"); if($db->num_rows($q3) > 0) $mydamage -= $db->fetch_single($q3); $db->free_result($q3); } if($mydamage < -100000) $mydamage = abs($mydamage); else if($mydamage < 1) $mydamage = 1; $crit = rand(1, 40); if($crit == 17) $mydamage *= rand(20, 40) / 10; else if($crit == 25 OR $crit == 8) $mydamage /= (rand(20, 40) / 10); $mydamage = round($mydamage); $odata['hp'] -= $mydamage; if($odata['hp'] == 1) { $odata['hp'] = 0; $mydamage += 1; } $db->query("UPDATE `users` SET `hp` = `hp` - $mydamage WHERE `userid` = {$_GET['ID']}"); ?> <span style='color: red;'><?php echo $_GET['nextstep']; ?>. Using your <?php echo $r1['itmname']; ?> you hit <?php echo $odata['username']; ?> doing <?php echo $mydamage; ?> damage (<?php echo $odata['hp']; ?>)</span><br /><?php $_SESSION['attackdmg'] += $mydamage; $_SESSION['attacklog'] .= "<span style='color: red;'>{$_GET['nextstep']}. Using {$myabbr} {$r1['itmname']} {$ir['username']} hit {$odata['username']} doing $mydamage damage ({$odata['hp']})</span><br />"; } else { ?><span style='color: red;'><?php echo $_GET['nextstep']; ?>. You tried to hit <?php echo $odata['username']; ?> but missed (<?php echo $odata['hp']; ?>)</span><br /><?php $_SESSION['attacklog'] .= "<span style='color: red;'>{$_GET['nextstep']}. {$ir['username']} tried to hit {$odata['username']} but missed ({$odata['hp']})</span><br />"; } if($odata['hp'] <= 0) { $odata['hp'] = 0; $_SESSION['attackwon'] = $_GET['ID']; $db->query("UPDATE `users` SET `hp` = 0 WHERE `userid` = {$_GET['ID']}"); $db->query("UPDATE `users` SET `LWID` = {$_GET['ID']} WHERE `userid` = {$ir['userid']}"); ?><br /> <b>What do you want to do with <?php echo $odata['username']; ?> now?</b><br /> <form action='attackwon.php?ID=<?php echo $_GET['ID']; ?>' method='post'><input type='submit' value='Mug Them' /></form> <form action='attackbeat.php?ID=<?php echo $_GET['ID']; ?>' method='post'><input type='submit' value='Hospitalize Them' /></form> <form action='attacktake.php?ID=<?php echo $_GET['ID']; ?>' method='post'><input type='submit' value='Leave Them' /></form><?php } else { $eq = $db->query("SELECT `itmname`,`weapon` FROM `items` WHERE `itmid` IN({$odata['equip_primary']}, {$odata['equip_secondary']})"); if($db->num_rows($eq) == 0) { $wep = "Fists"; $dam = (int) ((((int) ($odata['strength'] / $ir['guard'] / 100)) + 1) * (rand(8000, 12000) / 10000)); } else { $cnt = 0; while($r = $db->fetch_row($eq)) { $enweps[] = $r; ++$cnt; } $db->free_result($eq); $weptouse = rand(0, $cnt - 1); $wep = $enweps[$weptouse]['itmname']; $dam = (int) (($enweps[$weptouse]['weapon'] * $odata['strength'] / ($youdata['guard'] / 1.5)) * (rand(8000, 12000) / 10000)); } $hitratio = max(10, min(60 * $odata['agility'] / $ir['agility'], 95)); if(rand(1, 100) <= $hitratio) { if($ir['equip_armor'] > 0) { $q3 = $db->query("SELECT `armor` FROM `items` WHERE `itmid` = {$ir['equip_armor']} LIMIT 1"); if($db->num_rows($q3) > 0) $dam -= $db->fetch_single($q3); $db->free_result($q3); } if($dam < -100000) $dam = abs($dam); else if($dam < 1) $dam = 1; $crit = rand(1, 40); if($crit == 17) $dam *= rand(20, 40) / 10; else if($crit == 25 OR $crit == 8) $dam /= (rand(20, 40) / 10); $dam = round($dam); $youdata['hp'] -= $dam; if($youdata['hp'] == 1) { $dam += 1; $youdata['hp'] = 0; } $db->query("UPDATE `users` SET `hp` = `hp` - $dam WHERE `userid` = $userid"); $ns = $_GET['nextstep'] + 1; ?><span style='color: blue;'><?php echo $ns; ?>. Using <?php echo $oabbr; ?> <?php echo $wep; ?> <?php echo $odata['username']; ?> hit you doing <?php echo $dam; ?> damage (<?php echo $youdata['hp']; ?>)</span><br /><?php $_SESSION['attacklog'] .= "<span style='color: blue;'>{$ns}. Using $oabbr $wep {$odata['username']} hit {$ir['username']} doing $dam damage ({$youdata['hp']})</span><br />"; } else { $ns = $_GET['nextstep'] + 1; ?><span style='color: blue;'><?php echo $ns; ?>. <?php echo $odata['username']; ?> tried to hit you but missed (<?php echo $youdata['hp']; ?>)</span><br /><?php $_SESSION['attacklog'] .= "<span style='color: blue;'>{$ns}. {$odata['username']} tried to hit {$ir['username']} but missed ({$youdata['hp']})</span><br />"; } if($youdata['hp'] <= 0) { $youdata['hp'] = 0; $_SESSION['attacklost'] = 1; $db->query("UPDATE `users` SET `hp` = 0 WHERE `userid` = $userid"); ?><form action='attacklost.php?ID=<?php echo $_GET['ID']; ?>' method='post'><input type='submit' value='Continue' /><?php } } } ?></td></tr></table><?php $h->endpage(); Edited March 3 by Samurai Legend Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted March 9 Share Posted March 9 Check that the result of the guard / 1.5 is above 0 before using it as part of the equation <?php // Check that the user's guard is above 0 and get the guard division result, otherwise it's 0 $guardResult = $youdata['guard'] > 0 ? $youdata['guard'] / 1.5 : 0; // Begin the damage calculation $dam = $enweps[$weptouse]['weapon'] * $odata['strength']; // If we've got something to divide by .. if ($guardResult > 0) { // .. divide it $dam /= $guardResult; } // Add the randomisation back in $dam *= rand(8000, 12000) / 10000; // And cast it to an integer $dam = (int)$dam; /** * Original line for reference * $dam = (int) (($enweps[$weptouse]['weapon'] * $odata['strength'] / ($youdata['guard'] / 1.5)) * (rand(8000, 12000) / 10000)); */ 1 Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted March 14 Author Share Posted March 14 Yeah I've realised it was the value of the guard. Thanks @Magictallguy! 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.