Attack Turns [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Attack Turns [Resolved]

Post by Epiales »

Okay, me again. I have setup the following code so that when a character is attacked, that it randomly chooses the amount of turns that is used that round. It echo's how many turns are used each round as well. I have it setup, but it's only deducting the very LAST turn amount used instead of all of the turns accumulated for that fight. How can I fix this?

Code: Select all

/////////////////////////////////ADDED/////////////////////////////
$turnsused = rand(1,5);
$currentturns = $stats['turns'];
$newturns = $currentturns - $turnsused;
/////////////////////////////////ADDED/////////////////////////////


echo $user['username'] . "'s Attack is " . $stats['attack'] . "<br>";
echo $characters . "'s defense is " . $charactersdefense. "<br>";

if ($stats['attack'] > $charactersdefense) {

    echo $user['username'] . " hits! <br>";
    $playersdamage = rand(1,6);
    $newcharactershp = $charactershp - $playersdamage;
    echo "For " . $playersdamage . " points of damage. <br><br>";

/////////////////////////////////ADDED/////////////////////////////
    echo "You used " . $turnsused . " turns this round. <br><br>";
/////////////////////////////////ADDED/////////////////////////////

    if ($newcharactershp < 1) {
    
    echo "The " . $characters . " has been killed. ";

$isgold = rand(0,$charactersgold);
    $isloot = rand(0,100);

    echo " You loot " . $isgold . " gold pieces.<br>";

    $updateplayer="update stats set gold=gold+'$isgold', turns = '$newturns' where id='$id'";
  mysql_query($updateplayer) or die("Could not update player");
 
Last edited by Epiales on Tue Aug 27, 2013 3:22 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Attack Turns

Post by vitinho444 »

I can't really understand the problem.
But for what i understand i think you are only querying the new turns if the enemy dies. You need to do that after the attack.

I hope that it works.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Attack Turns

Post by Epiales »

vitinho444 wrote:I can't really understand the problem.
But for what i understand i think you are only querying the new turns if the enemy dies. You need to do that after the attack.

I hope that it works.
It is after each attack. It shows how many turns it took with each hit. The problem is getting ALL the turns to add together, instead of the very last hit, that kills the character; it shows how many turns it took to kill them on the last hit, but only adds that one turn, not all the previous turns that were used in order to bring their health down and kill them.

Example...you attack and hit them. It took 3 turns on that attack, but they aren't dead. So you have to attack again....then it takes 2 turns on that hit...but they aren't dead....then on the 3rd hit, you finally kill them for 3 turns on that attack. It only puts the last 3 turns into the database instead of having a total of 8 turns for the entire battle. There must be a way to add those.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Attack Turns

Post by vitinho444 »

Hum i see

Instead of this:

Code: Select all

$updateplayer="update stats set gold=gold+'$isgold', turns = '$newturns' where id='$id'";
put this:

Code: Select all

$finalturns = $stats['turns'] + $newturns;
$updateplayer="update stats set gold=gold+'$isgold', turns =  '$finalturns' where id='$id'";
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Attack Turns

Post by Epiales »

vitinho444 wrote:Hum i see

Instead of this:

Code: Select all

$updateplayer="update stats set gold=gold+'$isgold', turns = '$newturns' where id='$id'";
put this:

Code: Select all

$finalturns = $stats['turns'] + $newturns;
$updateplayer="update stats set gold=gold+'$isgold', turns =  '$finalturns' where id='$id'";
It does the exact same thing. Only add the last random turn, instead of all of them combined. Thanks for trying to help.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Attack Turns

Post by vitinho444 »

Then add a database field and keep adding the new turns to the database

like
$newturns = random(...);
$newturns = $old_database_turns + $newturns;
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Attack Turns

Post by Epiales »

vitinho444 wrote:Then add a database field and keep adding the new turns to the database

like
$newturns = random(...);
$newturns = $old_database_turns + $newturns;
I'll try something like that after while. See if I can't get it working. I'll keep all posted in here. I'm doing about 100 things at once LOL. :) Thank you!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Attack Turns

Post by vitinho444 »

Take easy on yourself :P
Good luck
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Attack Turns

Post by hallsofvallhalla »

you could eitehr store it in a cookie, pass it in a post variable or like vint said put it in a DB column to retrieve later. Just remember to reset to 0 after battle.
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Attack Turns

Post by Epiales »

Okay, have it working. In the end I put this:

Code: Select all

$turnsused = rand(1,5);

$currentturns = $stats['turns'];
$newturns = $currentturns - $turnsused;

$updateplayer="update stats set turns = '$newturns' where id='$id'";
  mysql_query($updateplayer) or die("Could not update player"); 
Problem was that I wasn't updating the database after each round. I only updated at the end of the battle. So by updating it after my formula's, it seems to have solved that problem.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”