Jump to content

help getting sum of attack


grant09

Recommended Posts

Ok i have this attack.php but when i attack its giving me odd sums

 

when i attack someone it says am hitting with 20 damage

 

 

 

You are in a war Match with Deadly Viper .

You hit Deadly Viper for 20 damage using your Mini Gun.

 

i am trying to sum it out so

 

bob user 1

john  user 2

 

bob attacks john both of there health are 100% , bob looses and i want his health  to go to 0% and johns health to go down by 20%  but if he wins i want johns health to go to 0% and bobs health to go down by 20 %

 

here is my code hope you can help

 

<?
include 'header.php';
include '1min.php';

$error = ($user_class->energypercent < 25) ? "You need to have at least 25% of your energy if you want to attack someone." : $error;
$error = ($user_class->jail > 0) ? "You can't attack someone if you are in jail." : $error;
$error = ($user_class->hospital > 0) ? "You can't attack someone if you are in the hospital." : $error;
$error = ($_GET['attack'] == "") ? "You didn't choose someone to attack." : $error;
$error = ($_GET['attack'] == $user_class->id) ? "You can't attack yourself." : $error;
$attack_person = new User($_GET['attack']);
$error = ($attack_person->city != $user_class->city) ? "You must be in the same city as the person you are attacking. Duh." : $error;
$error = ($attack_person->username == "") ? "That person doesn't exist." : $error;
$error = ($attack_person->hospital > 0) ? "You can't attack someone that is in the hospital." : $error;
$error = ($attack_person->banned == 1) ? "You can't attack someone that is banned." : $error;
$error = ($attack_person->jail > 0) ? "You can't attack someone that is in jail." : $error;
$error = ($user_class->level > 101 && $attack_person->level < 1) ? "You can't attack someone that is level 100 or below because you are higher than level 100." : $error;

if (isset($error)){
echo Message($error);
include 'footer.php';
die();
}

$yourhp = $user_class->hp;
$theirhp = $attack_person->hp;
?>
<tr><td class="contenthead"></td></tr>
<tr><td class="contentcontent">You are in a war Match with <? echo $attack_person->formattedname ?>.</td></tr>
<tr><td class="contentcontent">
<?
$wait = ($user_class->strength > $attack_person->strength) ? 1 : 0;

while($yourhp > 0 && $theirhp > 0){
$damage =  $hp = floor($attack_person->hp /10);
$damage = ($damage < 1) ? 1 : $damage;

if($wait == 0){
	$yourhp = $yourhp - $damage;
	echo $attack_person->formattedname . " hit you for " . $damage . " damage using their ".$attack_person->weaponname.". <br>";
} else {
	$wait = 0;
}

if($yourhp > 0) {
	$damage =  $hp = floor($attack_person->hp /10);
	$damage = ($damage < 1) ? 1 : $damage;
	$hp = $hp - $damage;
	echo "You hit " . $attack_person->formattedname . " for " . $damage . " damage using your ".$user_class->weaponname.". <br>";
}

if($theirhp <= 0){ // attacker won
	 $winner = $user_class->id;
	 $theirhp = 0;
	 $moneywon = floor($attack_person->money /10);
	 $hp = floor($attack_person->hp /10);
	 $battlewon = 1 + $user_class->battlewon;
	 $battlemoney = $moneywon + $user_class->battlemoney;
	 $expwon = 150 - (25 * ($user_class-> level - $attack_person->level));
	 $expwon = ($expwon < 200) ? 5 : $expwon;
	 $newexp = $expwon + $user_class->exp;
	 $newmoney = $user_class->money + $moneywon;
	 $result = mysql_query("UPDATE `grpgusers` SET `hp` = '".$hp."',`exp` = '".$newexp."', money = '".$newmoney."', `battlewon` = '".$battlewon."', `battlemoney` = '".$battlemoney."' WHERE `id`='".$_SESSION['id']."'");

	 $newmoney = $attack_person->money - $moneywon;
	 $battlelost = $user_class->battlelost + 1;
	 $battlemoney = $user_class->battlemoney - $moneywon;
	 $result = mysql_query("UPDATE `grpgusers` SET `money` = '".$newmoney."',`hp` = '".$hp."', `hwho` = '".$user_class->username."', `hhow` = 'wasattacked', `hwhen` = '".date(g.":".i.":".sa,time())."', `hospital` = '1200', `battlelost` = '".$battlelost."', `battlemoney` = '".$battlemoney."' WHERE `id`='".$attack_person->id."'");
	 Send_Event($attack_person->id, "You were hospitalized by ".$user_class->username." for 20 minutes.");
	 echo Message("You hospitalized " . $attack_person->formattedname . ". You gain $expwon exp and stole $".$moneywon." from " . $attack_person->formattedname . ".");

	 //give gang exp
	 if ($user_class->gang != 0) {
		 $gang = New Gang($user_class->gang);
		 $newgangexp = $gang->exp + $expwon;
		 $result = mysql_query("UPDATE `gangs` SET `exp` = '".$newgangexp."' WHERE `id`='".$gang->id."'");
	 }
}

if($yourhp <= 0){ // defender won
	 $winner = $attack_person->id;
	 $yourhp = 0;
	 $battlewon = 1 + $attack_person->battlewon;
		 $moneywon = floor($user_class->money /10);
	 $battlemoney = $moneywon + $attack_person->battlemoney;
	 $expwon = 100 - (25 * ($attack_person-> level - $user_class->level));
	 $expwon = ($expwon < 200) ? 5 : $expwon;
	 $newexp = $expwon + $attack_person->exp;
	 $newmoney = $attack_person->money + $moneywon;
	 $result = mysql_query("UPDATE `grpgusers` SET `exp` = '".$newexp."', money = '".$newmoney."', `battlewon` = '".$battlewon."', `battlemoney` = '".$battlemoney."' WHERE `id`='".$attack_person->id."'");

	 $newmoney = $user_class->money - $moneywon;
	 $battlelost = $user_class->battlelost + 1;
	 $battlemoney = $user_class->battlemoney - $moneywon;
	 $result = mysql_query("UPDATE `grpgusers` SET `money` = '".$newmoney."', `hwho` = '".$attack_person->username."', `hhow` = 'attacked', `hwhen` = '".date(g.":".i.":".sa,time())."', `hospital` = '1200', `battlelost` = '".$battlelost."', `battlemoney` = '".$battlemoney."' WHERE `id`='".$user_class->id."'");
	 echo Message($attack_person->formattedname . " Hospitalized you and stole $".$moneywon." from you.");

	 //give gang exp
	 if ($attack_user->gang != 0) {
		 $gang = New Gang($attack_user->gang);
		 $newgangexp = $gang->exp + $expwon;
		 $result = mysql_query("UPDATE `gangs` SET `exp` = '".$newgangexp."' WHERE `id`='".$gang->id."'");
	 }
}
}
//put defense log into gang
if ($attack_person->gang != 0) {
$time = time();
$result= mysql_query("INSERT INTO `ganglog` (`timestamp`, gangid, attacker, defender, winner)"."VALUES ('".$time."', '".$attack_person->gang."', '".$user_class->id."', '".$attack_person->id."', '".$winner."')");
}
//update users
$newenergy = $user_class->energy - floor($user_class->energy * .10);
$newhp = $attack_person->hp - floor($attack_person->hp * .5);
$newhp = $user_class->hp - floor($user_class->hp * .40);
$result = mysql_query("UPDATE `grpgusers` SET `hp` = '".$newhp."' WHERE `id`='".$attack_person->id."'");
$result = mysql_query("UPDATE `grpgusers` SET `hp` = '".$newhp."', `energy` = '".$newenergy."' WHERE `id`='".$user_class->id."'");
echo "</td></tr>";
include 'footer.php';
?>

Link to comment
Share on other sites

Are you sure this line is correct?

 

$error = ($user_class->level > 101 && $attack_person->level < 1) ? "You can't attack someone that is level 100 or below because you are higher than level 100." : $error;

 

I find the way your code is written a bit confusing.  I'm also not sure what you want here - can you give an example of what you expect a normal battle to go like?  And what is the $wait variable for?

Link to comment
Share on other sites

am not to sure what the $wait variable is for and am trying to get it so players health go down by 20% if get hit and if he wins the attackers health 0 av been at this code for 2 days now lol just cant get the sum of attack to take the users health down

 

Link to comment
Share on other sites

Ok.  In PHP that will be:

 

if ($user_class->strength > $attack_person->strength) {
  # Attacker wins
  $damage = $yourhp * 0.2; # Damage is 20% of current health?  Or of total health?
  $yourhp *= 0.8; # Set hp to 80% of old total
  $theirhp = 0;
} else {
  # Defender wins
  $damage = $theirhp * 0.2;
  $theirhp *= 0.8;
  $yourhp = 0;
}

 

And then you would use the other code you already have.  There is no need to use while() if the battle only has one round.

Link to comment
Share on other sites

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.