Jump to content

Recommended Posts

  • Replies 82
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

GOD VS. CatNCobra

Welcome to the Battle Arena.User HP:190

Enemy HP:0

Ā 

still, commented out, it still doesnt show the proper HP.

Ā 

i just turned enemy HP into 0, and it didnt echo the "your enemy is already dead" line

Ā 

instead it says

Ā 

GOD VS. CatNCobra

Welcome to the Battle Arena.User HP:190

Enemy HP:0

Ā 

OK lets check for errors in the SQL Part

Ā 

#commented out if called from header!
$usersql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); 
$user = @mysql_fetch_object($usersql) or die(mysql_error());
$enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); 
$enemy = @mysql_fetch_object($enemysql) or die(mysql_error());
print_r($enemy);

changed it, now the thing is, my page isnt loading up.

Ā 

i mean, it says loading, but nothing is really happening

Ā 

WOAH, hold on!

Ā 

in mysql, me and cat's hp has been updated:Ā  look at it!

Ā 

18446744073659623138-> my hp

18446744073357442826Ā  ->his hp

Ā 

thats the HP that we both have!

full updated code

Ā 

<?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.';
if ( $user->agility > $enemy->agility)
{
	$firstattack = '1';
}else{
	$firstattack = '2';
}
echo "UserĀ  HP:".$user->hp;
echo "<br>Enemy HP:".$enemy->hp;
while ($user->hp > 0 || $enemy->hp > 0)
{
	echo "attack<br>"; //add
	flush(); //add
	if ($firstattack == 1)
	{
		$dmg = ($user->attack) - ($enemy->defense);
		mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $enemy->ID");
		echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name";
	}
	if ($firstattack == 2)
	{
		$dmg = ($enemy->attack) - ($user->defense);
		mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID");
		echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name";
	}
	if ($firstattack != 1)
	{
		$dmg = ($user->attack) - ($enemy->defense);
		mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $enemy->ID");
		echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name";
	}
	if ($firstattack != 2)
	{
		$dmg = ($enemy->attack) - ($user->defense);
		mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $user->ID");
		echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name";
	}

	//get new values
	$enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); 
	$enemy = @mysql_fetch_object($enemysql);
	$usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); 
	$user = @mysql_fetch_object($usersql);
}
}
include('inc/footer.php');
?>

how do u change it so it knows when only 1 dies, not both?

*EDIT*

i put in ur new code, and mroe errors:

Ā 

CatNCobra VS.

Your Enemy Is Already Dead!

Ā 

he isnt dead, and why is HE attacking noone? its supposed to be GOD vs catncobra

Ā 

fixed that part

Ā 

*edit#2*

Ā 

i plugged in ur code, the code isnt properly working, its changing bioth our HP toĀ  18446744073650332346

i assume you set the HP's back to a "normal" value

please note that the $dmg is set to the HP left and not the amount taken (just want to check its running ok)

Ā 

while update

echo "User Start HP:".$user->hp;
echo "<br>Enemy Start HP:".$enemy->hp;
while ($user->hp > 0 || $enemy->hp > 0)
{
	echo "attack<br>"; //add
	echo "UserĀ  HP:".$user->hp;
	echo "<br>Enemy HP:".$enemy->hp;
	flush(); //add
	if ($firstattack == 1)
	{
		$dmg = $enemy->hp - ($user->attack - $enemy->defense);
		mysql_query("UPDATE `users` SET hp = hp-($dmg) WHERE ID = $enemy->ID");
		echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name";
	}
	if ($firstattack == 2)
	{
		$dmg = $user->hp - ($enemy->attack - $user->defense);
		mysql_query("UPDATE `users` SET hp =($dmg) WHERE ID = $user->ID");
		echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name";
	}
	if ($firstattack != 1)
	{
		$dmg = $enemy->hp - ($user->attack) - ($enemy->defense);
		mysql_query("UPDATE `users` SET hp = ($dmg) WHERE ID = $enemy->ID");
		echo "$user->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$enemy->display_name";
	}
	if ($firstattack != 2)
	{
		$dmg = $user->hp - ($enemy->attack) - ($user->defense);
		mysql_query("UPDATE `users` SET hp = ($dmg) WHERE ID = $user->ID");
		echo "$enemy->display_name"; echo' has done '; echo "$dmg"; echo ' damage against '; echo "$user->display_name";
	}

	//get new values
	$enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); 
	$enemy = @mysql_fetch_object($enemysql);
	$usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); 
	$user = @mysql_fetch_object($usersql);
}

the page is taking forever to load, and the HUGE HP number keeps reappearing

Ā 

*how do i make a battle system where theres 1 winner?Ā  thats what i wanted to make, anyway, cuz like, i thought if one part of the while is false, its all false, was i wrong?

Ā 

this showed up, its huge, so i put a code bracket around it:

GOD VS. CatNCobra
Welcome to the Battle Arena.User Start HP:100
Enemy Start HP:100attack
User HP:100
Enemy HP:100CatNCobra has done -1790 damage against GODGOD has done -178 damage against CatNCobraattack
User HP:18446744073709551438
Enemy HP:18446744073709549826GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744
Enemy HP:18446744073699999744GOD has done 1.84467440737E+19 damage against CatNCobraCatNCobra has done 1.84467440737E+19 damage against GODattack
User HP:18446744073699999744

ok i have re-written the while section

Ā 

echo "User Start HP:".$user->hp;
echo "<br>Enemy Start HP:".$enemy->hp;
$attacker = ($user->agility > $enemy->agility);

while ($user->hp > 0 && $enemy->hp > 0)
{
	echo "attack<br>"; //add
	echo "UserĀ  HP:".$user->hp;
	echo "<br>Enemy HP:".$enemy->hp;
	flush(); //add

	if($attacker)
	{
		$dmg = (int)($user->attack - $enemy->defense);
		$HPLeft = (int)($enemy->hp - dmg);
		mysql_query("UPDATE `users` SET hp = ($HPLeft) WHERE ID = $enemy->ID");
		echo "$user->display_nameĀ  has done $dmg damage against $enemy->display_name"; 
	}else{
		$dmg = (int)($enemy->attack - $user->defense);
		$HPLeft = (int)($user->hp - dmg);
		mysql_query("UPDATE `users` SET hp =($HPLeft) WHERE ID = $user->ID");
		echo "$enemy->display_name has done $dmg damage against $user->display_name";		

	$attacker = !$attacker;

	//get new values
	$enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); 
	$enemy = @mysql_fetch_object($enemysql);
	$usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); 
	$user = @mysql_fetch_object($usersql);
}
}

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Ā 

Please contact the server administrator, webmaster@donkeygame.1gig.biz and inform them of the time the error occurred, and anything you might have done that may have caused the error.

Ā 

More information about this error may be available in the server error log.

Ā 

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Ā 

Ā 

wth does that mean

indeed

forgot a }

while ($user->hp > 0 && $enemy->hp > 0)
{
	echo "attack<br>"; //add
	echo "UserĀ  HP:".$user->hp;
	echo "<br>Enemy HP:".$enemy->hp;
	flush(); //add

	if($attacker)
	{
		$dmg = (int)($user->attack - $enemy->defense);
		$HPLeft = (int)($enemy->hp - dmg);
		mysql_query("UPDATE `users` SET hp = ($HPLeft) WHERE ID = $enemy->ID");
		echo "$user->display_nameĀ  has done $dmg damage against $enemy->display_name"; 
	}else{
		$dmg = (int)($enemy->attack - $user->defense);
		$HPLeft = (int)($user->hp - dmg);
		mysql_query("UPDATE `users` SET hp =($HPLeft) WHERE ID = $user->ID");
		echo "$enemy->display_name has done $dmg damage against $user->display_name";		
	} //added <-****
	$attacker = !$attacker;

	//get new values
	$enemysql = @mysql_query("SELECT * FROM users WHERE ID = '$uID'"); 
	$enemy = @mysql_fetch_object($enemysql);
	$usersql = @mysql_query("SELECT * FROM users WHERE ID = '$eID'"); 
	$user = @mysql_fetch_object($usersql);
}

Ā 

this is much easier when you have it on your own server and don't have your boss walking around the office ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.