Page 1 of 1
Stats Not Properly Working [Resolved]
Posted: Sun Sep 01, 2013 1:32 pm
by Epiales
Okay, the issue now is that when you are in a fight, you have, let's say, 2 hit points left. When you attack a creature/character, and they hit you for let's say, 5 hit points of damage, it doesn't take your 2 hitpoints down to 0, but still says your dead. So you always have those 2 hit points and can go right back and fight someone else over and over and over.
I tried adding something like this: if($newplayershp > 0){$newplayershp = 0;} , but it doesn't seem to be working.
I'm sure this is the code that I need to work with, but haven't figured anything out.
Code: Select all
if ($charactersattack > $playersdefense) {
echo $characters . " hits! <br>";
$charactersdamage = rand(1,6);
$newplayershp = $playershp - $charactersdamage;
echo "For " . $charactersdamage . " points of damage. <br>";
if ($newplayershp < 0) {
echo "The " . $user['username'] . " has been killed<br>";
echo "<a href='index.php'>Continue</a>";
exit;
}
$updateplayer = "update stats set hpoints='$newplayershp' where id='$id'";
mysql_query($updateplayer) or die("Could not update player");
Also, the same with their turns as well, except the turns go into a negative number
Re: Stats Not Properly Working
Posted: Sun Sep 01, 2013 6:57 pm
by MikuzA
you might want to add the update query also in if() where the player dies..
or just remove the exit;
depends on why you want to exit on that point.
Re: Stats Not Properly Working
Posted: Sun Sep 01, 2013 8:04 pm
by Epiales
MikuzA wrote:you might want to add the update query also in if() where the player dies..
or just remove the exit;
depends on why you want to exit on that point.
Okay, I added another update query, but still doesn't work:
Code: Select all
$charactershp = $charactersinfo3['hpoints'];
$charactersattack = rand(1,20) + $charactersattack;
$playersdefense = rand(1,20) + $playersdefense;
$charactersdamage = rand(1,6);
$playershp = $stats['hpoints'];
$newplayershp = $playershp - $charactersdamage;
if($newplayershp > 0){$newplayershp = 0;}
$updateplayer="update stats set hpoints=$newplayershp where id='$id'";
exit;
}
$updatecharacters = "update characters set hpoints='$newcharactershp' where name='$characters' limit 1";
mysql_query($updatecharacters) or die("Could not update character");
Re: Stats Not Properly Working
Posted: Sun Sep 01, 2013 8:11 pm
by Epiales
Actually I forgot:
Code: Select all
mysql_query($updateplayer) or die("Could not update character");
But now it sets stats to zero after each battle.
Re: Stats Not Properly Working
Posted: Sun Sep 01, 2013 8:32 pm
by Epiales
Okay, it's working now. I ended up with this code:
Code: Select all
$charactershp = $charactersinfo3['hpoints'];
$charactersattack = rand(1,20) + $charactersattack;
$playersdefense = rand(1,20) + $playersdefense;
$charactersdamage = rand(1,6);
$playershp = $stats['hpoints'];
$newplayershp = $playershp - $charactersdamage;
if($newplayershp > 0){$newplayershp = 0;}
if($newplayershp < 0){$newplayershp = 0;}
$updateplayer="update stats set hpoints=$newplayershp where id='$id'";
mysql_query($updateplayer) or die("Could not update player");
Thank you for directing me in the way I should go.

Re: Stats Not Properly Working [Resolved]
Posted: Mon Sep 02, 2013 5:35 am
by MikuzA
Code: Select all
if($newplayershp > 0){$newplayershp = 0;}
if($newplayershp < 0){$newplayershp = 0;}
Question: Why do you have them both?
If players hp is above zero, it goes to zero doesn't really make sense since the player lives
try something like
Code: Select all
$newplayershp = $playershp - $charactersdamage;
if($newplayershp > 0){ print "Good Lord! You manage to survive the mighty blast, now it's time to turn the tables!!"; }
if($newplayershp < 0){$newplayershp = 0; print "Did you just hear something crack? That was your skull, can you see the light? Game over."; }
$updateplayer="update stats set hpoints=$newplayershp where id='$id'";
mysql_query($updateplayer) or die("Could not update player");
Oh, I just wanted to write some lousy sentences to keep myself assumed on a monday morning

Re: Stats Not Properly Working [Resolved]
Posted: Mon Sep 02, 2013 6:01 am
by Epiales
MikuzA wrote:Code: Select all
if($newplayershp > 0){$newplayershp = 0;}
if($newplayershp < 0){$newplayershp = 0;}
Question: Why do you have them both?
If players hp is above zero, it goes to zero doesn't really make sense since the player lives
try something like
Code: Select all
$newplayershp = $playershp - $charactersdamage;
if($newplayershp > 0){ print "Good Lord! You manage to survive the mighty blast, now it's time to turn the tables!!"; }
if($newplayershp < 0){$newplayershp = 0; print "Did you just hear something crack? That was your skull, can you see the light? Game over."; }
$updateplayer="update stats set hpoints=$newplayershp where id='$id'";
mysql_query($updateplayer) or die("Could not update player");
Oh, I just wanted to write some lousy sentences to keep myself assumed on a monday morning

The reason I have if($newplayershp > 0){$newplayershp = 0;} is because if you have 2 hitpoints left, and you are hit for 5 hit points in damage, you don't lose those 2 hit points. It says you are dead, but you still have 2 hit points left. So you can just go right back and fight again with those 2 hit points left lol.
Re: Stats Not Properly Working [Resolved]
Posted: Mon Sep 02, 2013 6:32 am
by MikuzA
Epiales wrote:
The reason I have if($newplayershp > 0){$newplayershp = 0;} is because if you have 2 hitpoints left, and you are hit for 5 hit points in damage, you don't lose those 2 hit points. It says you are dead, but you still have 2 hit points left. So you can just go right back and fight again with those 2 hit points left lol.
But with your current code, let's say you have hitpoints at 10, you get hit with 5 dmg, it results your hp's at 0 due your IF there.
The problem why that happened was because you didn't have the mysql_update happening when you die.
But with the current setup of if-brackets it works fine.
Re: Stats Not Properly Working [Resolved]
Posted: Mon Sep 02, 2013 12:48 pm
by Epiales
MikuzA wrote:Epiales wrote:
The reason I have if($newplayershp > 0){$newplayershp = 0;} is because if you have 2 hitpoints left, and you are hit for 5 hit points in damage, you don't lose those 2 hit points. It says you are dead, but you still have 2 hit points left. So you can just go right back and fight again with those 2 hit points left lol.
But with your current code, let's say you have hitpoints at 10, you get hit with 5 dmg, it results your hp's at 0 due your IF there.
The problem why that happened was because you didn't have the mysql_update happening when you die.
But with the current setup of if-brackets it works fine.
Actually it works perfect the way I have it. It will take you all the way to 1 hitpoint, and if you get hit for 4 damage, it will put you at zero and say you have lost. So it keeps it from staying positive or going negative. Again, thanks for pointing out that I needed to update in a certain spot.
