supanoob Posted January 12, 2007 Share Posted January 12, 2007 [quote]<?php include_once('top_html.php');?> <TD bgcolor=#000000 style="border: 1px solid #363636"> <?php //NPC Battle if ($step == 'npc') { //NPC Battle if ($action == 'normal') { //Query For NPC Stats $query2="select npc_name, npc_power, npc_level, npc_speed, npc_dexterity, npc_health, npc_max_health, npc_gold from npcs where npc_id='$search'"; $result2=mysql_query($query2); if (!$result2) { die (mysql_error()); } $num_rows=mysql_num_rows($result2); $row=mysql_fetch_array($result2); $npc_name=($row['npc_name']); $npc_power=($row['npc_power']); $npc_speed=($row['npc_speed']); $npc_dexterity=($row['npc_dexterity']); $npc_health=($row['npc_health']); $npc_max_health=($row['npc_max_health']); $npc_gold=($row['npc_gold']); $npc_level=($row['npc_level']); //Query For NPC Stats End //information for the battle formula //power is determined by *ing it by 5 then taking it away from dex. //dexterity is determined by *inf it by a random number. //the random number is between 1 and 10 and then divided by 10. //both players will have a chance to attack randomly throughout the battle //this is determined by their speed. //that will be divided by the oponents dexterity and then *sed by 100 to give a percent. //that percent will be the chance they have of hitting more often. //however they will never have more than 80% chance of hitting more. //if the npc class is Necromancer they will have a chance of a skeleton attacking. //this will be determined by overall level of npc that will be turned into a percent. //if npc class is Mage they will have a chance of casting a spell. //if class fire mage - fire ball, frost mage - ice blast, white mage - heal, black mage - destruction. //the chance of casting magic will be determined by overall level //if class is thief they will have a chance of stealing extra gold during the battle. //if class is warrior they will have the chance of doing battle charge during battle and hitting for extra damage. //THIS IS NOT THE ACTUAL BATTLE, THESE WILL NEED PLACING IN THE WHILE LOOP. //NPC's Formula //$npc_power_1 = ($npc_power*2); //$npc_rand_1 = rand(1,10); //$npc_rand_2 = ($npc_rand_1/10); //$npc_dexterity_1 = ($npc_dexterity*$rand_2); ////$npc_speed_1 = (($npc_speed/$npc_dexterity)*100); //$npc_damage = ($npc_dexterit_1-$npc_power_1); //if ($npc_damage < '0') {$npc_damage = '0';} //Necro Class random numbers //$npc_necro_rand = rand(1,100); //mage class random numbers //$npc_mage_rand = rand(1,100); //thief class random numbers //$npc_thief_rand = rand(1,100); //warrior class random numbers //$npc_warrior_rand = rand(1,100); //end NPC formula //Player's Formula //$player_power_1 = ($power*5); //$player_rand_1 = rand(1,10); //$player_rand_2 = ($player_rand_1/10); //$player_dexterity_1 = ($dexterit/$rand_2); //$player_speed_1 = (($speed/$dexterity)*100); //$player_damage = ($player_dexterit_1-$player_power_1); //if ($player_damage < '0') {$player_damage = '0';} //Necro Class random numbers //$player_necro_rand = rand(1,100); //mage class random numbers //$player_mage_rand = rand(1,100); //thief class random numbers //$player_thief_rand = rand(1,100); //warrior class random numbers //$player_warrior_rand = rand(1,100); //end Players formula //If Win and check if level. //if ($npc_health < '1') //{ //$gold_gain = rand(10,25); //$exp_gain_rand = rand(90,100); //$level_difference = ($npc_level-$level); //if ($level_difference < 0){$level_difference = '0';} //$exp_gain = ($exp_gain_rand*$level_difference); //$sql2="UPDATE accounts SET gold=gold+$gold_gain, level_exp=level_exp+$exp_gain, npc_wins=npc_wins+1 WHERE char_id='$char_id'"; //if(mysql_query($sql2)) //echo "You won $npc_name. You gain $gold_gain gold and $exp_gain exp.<br>"; //if ($level_exp > $level_exp_need) //{ //$sql2="UPDATE accounts SET exp='0', level_exp_need=$exp_need_1, battle_points=battle_points+3, level=level+1 WHERE char_id='$char_id'"; //if(mysql_query($sql2)) //echo "You also gained a level. You recieve 3 Battle points."; // } //die(include_once('bottom_html.php')); //} //End If Win //If Lose //if ($npc_health < '1') //{ //$gold_lose = rand(10,25); //$sql2="UPDATE accounts SET gold=gold+$gold_lose, npc_wins=npc_wins-1 WHERE char_id='$char_id'"; //if(mysql_query($sql2)) //echo "You lost to $npc_name. You lose $gold_lose gold..<br>"; //die(include_once('bottom_html.php')); //} //End If Lose //END ALL NOTES. //THIS IS THE BATTLE. while ($health > 0 AND $npc_health > 0) { //Formula's In The Loop //NPC's Formula $npc_power_1 = ($npc_power*2); $npc_rand_1 = rand(1,10); $npc_rand_2 = ($npc_rand_1/10); $npc_dexterity_1 = ($npc_dexterity*$npc_rand_2); $npc_speed_1 = (($npc_speed/$dexterity)*100); $npc_damage = ($npc_power_1-$player_dexterity_1); $npc_damage = round($npc_damage); if ($npc_damage < '0') {$npc_damage = '0';} //Necro Class random numbers $npc_necro_rand = rand(1,100); //mage class random numbers $npc_mage_rand = rand(1,100); //thief class random numbers $npc_thief_rand = rand(1,100); //warrior class random numbers $npc_warrior_rand = rand(1,100); //end NPC formula //Player's Formula $player_power_1 = ($power*2); $player_rand_1 = rand(1,10); $player_rand_2 = ($player_rand_1/10); $player_dexterity_1 = ($dexterity/$player_rand_2); $player_speed_1 = (($speed/$npc_dexterity)*100); $player_damage = ($player_power_1-$npc_dexterity_1); $player_damage = round($player_damage); if ($player_damage < '0') {$player_damage = '0';} //Necro Class random numbers $player_necro_rand = rand(1,100); //mage class random numbers $player_mage_rand = rand(1,100); //thief class random numbers $player_thief_rand = rand(1,100); //warrior class random numbers $player_warrior_rand = rand(1,100); //end Playersformula //End In Loop Formula's //determine who strikes first using the speed. if($player_speed_1 > $npc_speed_1) { $sql2="UPDATE npcs SET npc_health=npc_health-$player_damage WHERE npc_id='$search'"; if(mysql_query($sql2)) echo "<font color=\"Green\">You Attacked $npc_name for $player_damage life.</font><br>"; $npc_health_1=($npc_health-$player_damage); if($npc_health_1 < 1) { $gold_gain = rand(10,25); $exp_gain_rand = rand(90,100); $level_difference = ($npc_level-$level); if ($level_difference < 0){$level_difference = '0';} $exp_gain = ($exp_gain_rand*$level_difference); $sql2="UPDATE accounts SET gold=gold+$gold_gain, level_exp=level_exp+$exp_gain, npc_wins=npc_wins+1 WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You won $npc_name. You gain $gold_gain gold and $exp_gain exp.<br>"; if ($level_exp > $level_exp_need) { $sql2="UPDATE accounts SET exp='0', level_exp_need=$exp_need_1, battle_points=battle_points+3, level=level+1 WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You also gained a level. You recieve 3 Battle points."; } die(include_once('bottom_html.php')); } } //End the first attack. //into the battle //Player gets first hit echo "<font color=\"Green\">You Attacked $npc_name for $player_damage life.</font><br>"; //update npc life $sql2="UPDATE npcs SET npc_health=npc_health-$player_damage WHERE npc_id='$search'"; if(mysql_query($sql2)) //if npc dead update player wins etc. $npc_health_1=($npc_health-$player_damage); if ($npc_health_1 < 1) { $gold_gain = rand(10,25); $exp_gain_rand = rand(90,100); $level_difference = ($npc_level-$level); if ($level_difference < 0){$level_difference = '0';} $exp_gain = ($exp_gain_rand*$level_difference); $sql2="UPDATE accounts SET gold=gold+$gold_gain, level_exp=level_exp+$exp_gain, npc_wins=npc_wins+1 WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You won $npc_name. You gain $gold_gain gold and $exp_gain exp.<br>"; if ($level_exp > $level_exp_need) { $sql2="UPDATE accounts SET exp='0', level_exp_need=$exp_need_1, battle_points=battle_points+3, level=level+1 WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You also gained a level. You recieve 3 Battle points."; } die(include_once('bottom_html.php')); } echo "<font color=\"Red\">$npc_name attacked you for $npc_damage life.</font><br>"; //update player health. $sql2="UPDATE accounts SET health=health-$npc_damage WHERE char_id='$char_id'"; if(mysql_query($sql2)) $health_1=($health-$npc_damage); //If Lose if ($health_1 < 1) { $gold_lose = rand(10,25); $sql2="UPDATE accounts SET gold=gold-$gold_lose, npc_losses=npc_losses+1, health='0' WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You lost to $npc_name. You lose $gold_lose gold.<br>"; die(include_once('bottom_html.php')); } //End If Lose } } //NPC Battle End //quest NPC Battle //Normal NPC Battle End //NPC Battles End //PVP Battle //PVP Battle End ?> </TD><?php include_once('bottom_html.php'); ?>[/quote]thats the code i am using[quote]Parse error: syntax error, unexpected $end in /home/twottk/public_html/battle.php on line 315[/quote]and thats the error i am gettin, i have checked all my {}'s and i dont know what else to look for. Link to comment https://forums.phpfreaks.com/topic/33898-parse-errors/ Share on other sites More sharing options...
play_ Posted January 12, 2007 Share Posted January 12, 2007 [code] $sql2="UPDATE accounts SET gold=gold-$gold_lose, npc_losses=npc_losses+1, health='0' WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You lost to $npc_name. You lose $gold_lose gold."; die(include_once('bottom_html.php')); } //End If Lose } } //NPC Battle End //quest NPC Battle //Normal NPC Battle End //NPC Battles End //PVP Battle //PVP Battle End ?> </TD><?phpinclude_once('bottom_html.php');[/code]I think you're missing a { after the first if edit::nevermind. you only have one statement after that Link to comment https://forums.phpfreaks.com/topic/33898-parse-errors/#findComment-159128 Share on other sites More sharing options...
redbullmarky Posted January 12, 2007 Share Posted January 12, 2007 try indending your code a little better and checking again. i had a little go but got lost very easily....when the code enclosed between two brackets is quite long, i always find it useful to put a comment after the closing bracket, such as "// end for" or "// end if" etc, sometimes even more descriptive so i know exactly what for/if/while, etc, i'm closing. in this case, it'd help you out alot.i've never come across that error before, other than a missing bracket. Link to comment https://forums.phpfreaks.com/topic/33898-parse-errors/#findComment-159131 Share on other sites More sharing options...
taith Posted January 12, 2007 Share Posted January 12, 2007 your missing a } at the very very end...[code]<?php include_once('top_html.php');?><TD bgcolor=#000000 style="border: 1px solid #363636"><?php if($step == 'npc'){ //NPC Battle if($action == 'normal'){ //Query For NPC Stats $query2="select npc_name, npc_power, npc_level, npc_speed, npc_dexterity, npc_health, npc_max_health, npc_gold from npcs where npc_id='$search'"; $result2=mysql_query($query2) or die (mysql_error()); $num_rows=mysql_num_rows($result2); $row=mysql_fetch_array($result2); $npc_name=($row['npc_name']); $npc_power=($row['npc_power']); $npc_speed=($row['npc_speed']); $npc_dexterity=($row['npc_dexterity']); $npc_health=($row['npc_health']); $npc_max_health=($row['npc_max_health']); $npc_gold=($row['npc_gold']); $npc_level=($row['npc_level']); //Query For NPC Stats End //information for the battle formula //power is determined by *ing it by 5 then taking it away from dex. //dexterity is determined by *inf it by a random number. //the random number is between 1 and 10 and then divided by 10. //both players will have a chance to attack randomly throughout the battle //this is determined by their speed. //that will be divided by the oponents dexterity and then *sed by 100 to give a percent. //that percent will be the chance they have of hitting more often. //however they will never have more than 80% chance of hitting more. //if the npc class is Necromancer they will have a chance of a skeleton attacking. //this will be determined by overall level of npc that will be turned into a percent. //if npc class is Mage they will have a chance of casting a spell. //if class fire mage - fire ball, frost mage - ice blast, white mage - heal, black mage - destruction. //the chance of casting magic will be determined by overall level //if class is thief they will have a chance of stealing extra gold during the battle. //if class is warrior they will have the chance of doing battle charge during battle and hitting for extra damage. //THIS IS NOT THE ACTUAL BATTLE, THESE WILL NEED PLACING IN THE WHILE LOOP. //NPC's Formula //$npc_power_1 = ($npc_power*2); //$npc_rand_1 = rand(1,10); //$npc_rand_2 = ($npc_rand_1/10); //$npc_dexterity_1 = ($npc_dexterity*$rand_2); //$npc_speed_1 = (($npc_speed/$npc_dexterity)*100); //$npc_damage = ($npc_dexterit_1-$npc_power_1); //if ($npc_damage < '0') {$npc_damage = '0';} //Necro Class random numbers //$npc_necro_rand = rand(1,100); //mage class random numbers //$npc_mage_rand = rand(1,100); //thief class random numbers //$npc_thief_rand = rand(1,100); //warrior class random numbers //$npc_warrior_rand = rand(1,100); //end NPC formula //Player's Formula //$player_power_1 = ($power*5); //$player_rand_1 = rand(1,10); //$player_rand_2 = ($player_rand_1/10); //$player_dexterity_1 = ($dexterit/$rand_2); //$player_speed_1 = (($speed/$dexterity)*100); //$player_damage = ($player_dexterit_1-$player_power_1); //if ($player_damage < '0') {$player_damage = '0';} //Necro Class random numbers //$player_necro_rand = rand(1,100); //mage class random numbers //$player_mage_rand = rand(1,100); //thief class random numbers //$player_thief_rand = rand(1,100); //warrior class random numbers //$player_warrior_rand = rand(1,100); //end Players formula //If Win and check if level. //if ($npc_health < '1') //{ //$gold_gain = rand(10,25); //$exp_gain_rand = rand(90,100); //$level_difference = ($npc_level-$level); //if ($level_difference < 0){$level_difference = '0';} //$exp_gain = ($exp_gain_rand*$level_difference); //$sql2="UPDATE accounts SET gold=gold+$gold_gain, level_exp=level_exp+$exp_gain, npc_wins=npc_wins+1 WHERE char_id='$char_id'"; //if(mysql_query($sql2)) //echo "You won $npc_name. You gain $gold_gain gold and $exp_gain exp."; //if ($level_exp > $level_exp_need) //{ //$sql2="UPDATE accounts SET exp='0', level_exp_need=$exp_need_1, battle_points=battle_points+3, level=level+1 WHERE char_id='$char_id'"; //if(mysql_query($sql2)) //echo "You also gained a level. You recieve 3 Battle points."; // } //die(include_once('bottom_html.php')); //} //End If Win //If Lose //if ($npc_health < '1') //{ //$gold_lose = rand(10,25); //$sql2="UPDATE accounts SET gold=gold+$gold_lose, npc_wins=npc_wins-1 WHERE char_id='$char_id'"; //if(mysql_query($sql2)) //echo "You lost to $npc_name. You lose $gold_lose gold.."; //die(include_once('bottom_html.php')); //} //End If Lose //END ALL NOTES. //THIS IS THE BATTLE. while($health>0 && $npc_health>0){ //Formula's In The Loop //NPC's Formula $npc_power_1 = ($npc_power*2); $npc_rand_1 = rand(1,10); $npc_rand_2 = ($npc_rand_1/10); $npc_dexterity_1 = ($npc_dexterity*$npc_rand_2); $npc_speed_1 = (($npc_speed/$dexterity)*100); $npc_damage = ($npc_power_1-$player_dexterity_1); $npc_damage = round($npc_damage); if($npc_damage < '0'){ $npc_damage='0'; } //Necro Class random numbers $npc_necro_rand = rand(1,100); //mage class random numbers $npc_mage_rand = rand(1,100); //thief class random numbers $npc_thief_rand = rand(1,100); //warrior class random numbers $npc_warrior_rand = rand(1,100); //end NPC formula //Player's Formula $player_power_1 = ($power*2); $player_rand_1 = rand(1,10); $player_rand_2 = ($player_rand_1/10); $player_dexterity_1 = ($dexterity/$player_rand_2); $player_speed_1 = (($speed/$npc_dexterity)*100); $player_damage = ($player_power_1-$npc_dexterity_1); $player_damage = round($player_damage); if($player_damage<'0'){ $player_damage='0'; } //Necro Class random numbers $player_necro_rand = rand(1,100); //mage class random numbers $player_mage_rand = rand(1,100); //thief class random numbers $player_thief_rand = rand(1,100); //warrior class random numbers $player_warrior_rand = rand(1,100); //end Playersformula //End In Loop Formula's //determine who strikes first using the speed. if($player_speed_1 > $npc_speed_1){ $sql2="UPDATE npcs SET npc_health=npc_health-$player_damage WHERE npc_id='$search'"; if(mysql_query($sql2)) echo "<font color=\"Green\">You Attacked $npc_name for $player_damage life.</font>"; $npc_health_1=($npc_health-$player_damage); if($npc_health_1 < 1){ $gold_gain = rand(10,25); $exp_gain_rand = rand(90,100); $level_difference = ($npc_level-$level); if($level_difference<0){ $level_difference='0'; } $exp_gain = ($exp_gain_rand*$level_difference); $sql2="UPDATE accounts SET gold=gold+$gold_gain, level_exp=level_exp+$exp_gain, npc_wins=npc_wins+1 WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You won $npc_name. You gain $gold_gain gold and $exp_gain exp."; if($level_exp > $level_exp_need){ $sql2="UPDATE accounts SET exp='0', level_exp_need=$exp_need_1, battle_points=battle_points+3, level=level+1 WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You also gained a level. You recieve 3 Battle points."; } die(include_once('bottom_html.php')); } } //End the first attack. //into the battle //Player gets first hit echo "<font color=\"Green\">You Attacked $npc_name for $player_damage life.</font>"; //update npc life $sql2="UPDATE npcs SET npc_health=npc_health-$player_damage WHERE npc_id='$search'"; if(mysql_query($sql2)) $npc_health_1=($npc_health-$player_damage); if($npc_health_1 < 1){ $gold_gain = rand(10,25); $exp_gain_rand = rand(90,100); $level_difference = ($npc_level-$level); if($level_difference<0){ $level_difference='0'; } $exp_gain = ($exp_gain_rand*$level_difference); $sql2="UPDATE accounts SET gold=gold+$gold_gain, level_exp=level_exp+$exp_gain, npc_wins=npc_wins+1 WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You won $npc_name. You gain $gold_gain gold and $exp_gain exp."; if($level_exp > $level_exp_need){ $sql2="UPDATE accounts SET exp='0', level_exp_need=$exp_need_1, battle_points=battle_points+3, level=level+1 WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You also gained a level. You recieve 3 Battle points."; } die(include_once('bottom_html.php')); } echo "<font color=\"Red\">$npc_name attacked you for $npc_damage life.</font>"; //update player health. $sql2="UPDATE accounts SET health=health-$npc_damage WHERE char_id='$char_id'"; if(mysql_query($sql2)) $health_1=($health-$npc_damage); //If Lose if($health_1<1){ $gold_lose = rand(10,25); $sql2="UPDATE accounts SET gold=gold-$gold_lose, npc_losses=npc_losses+1, health='0' WHERE char_id='$char_id'"; if(mysql_query($sql2)) echo "You lost to $npc_name. You lose $gold_lose gold."; die(include_once('bottom_html.php')); } //End If Lose } }}?></TD><?php include_once('bottom_html.php'); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/33898-parse-errors/#findComment-159138 Share on other sites More sharing options...
supanoob Posted January 12, 2007 Author Share Posted January 12, 2007 nice that fixed that now my loop doesnt end :P it just keeps going on and on and on Link to comment https://forums.phpfreaks.com/topic/33898-parse-errors/#findComment-159521 Share on other sites More sharing options...
play_ Posted January 12, 2007 Share Posted January 12, 2007 if this is the loop: while($health>0 && $npc_health>0){you need to make sure, at some point, $health and $npc_health is <=0. Link to comment https://forums.phpfreaks.com/topic/33898-parse-errors/#findComment-159527 Share on other sites More sharing options...
supanoob Posted January 13, 2007 Author Share Posted January 13, 2007 i check that at several point, always after they have been hit for some damage.[code]<?php $npc_health_1=($npc_health-$player_damage); if($npc_health_1 < 1){} $npc_health_1=($npc_health-$player_damage); if($npc_health_1 < 1){} $health_1=($health-$npc_damage); if($health_1<1){} ?>[/code]they are the three times i check and each time there is a DIE(); in there somewhere. Link to comment https://forums.phpfreaks.com/topic/33898-parse-errors/#findComment-159847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.