Characters changing [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

Characters changing [Resolved]

Post by Epiales »

It's me again :) YAY lol :mrgreen:

Okay, next issue! I'm having the issue of the characters changing when I refresh the page. I have included, in the database, a field where it records what character they have, or were fighting, but no matter what It try, it still changes characters upon refresh. Is there anyway to stop this from occurring? Below is code. Thank you...

Code: Select all

if (isset($_GET['characters']))
{
    $characters=$_GET['characters'];
    $charactersinfo = "SELECT * from stats where creature = '$creature'";
    $charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get the character you were fighting!");
    $charactersinfo3 = mysql_fetch_array($charactersinfo2);

} else {


    $areaninfo="SELECT * from locations where type='arena' AND location = '$stats[location]'";
    $areaninfo2=mysql_query($areaninfo) or die("could not get arena");
    $areaninfo3=mysql_fetch_array($areaninfo2);
    $arenalevel = $areaninfo3['level'];


    $charactersinfo = "SELECT * from characters where level = '$arenalevel' order by rand() limit 1";
    $charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get a character!");
    $charactersinfo3 = mysql_fetch_array($charactersinfo2);
    $id = $stats['id'];
    $cid = $charactersinfo3['id'];
    $updateplayer="update stats set creature='$cid' where id='$id'";
    mysql_query($updateplayer) or die("Could not update player");
Last edited by Epiales on Fri Sep 06, 2013 1:11 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Characters changing

Post by Callan S. »

Code: Select all

    $characters=$_GET['characters'];
    $charactersinfo = "SELECT * from stats where creature = '$creature'";
Should '$creature' actually be '$characters'?
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Characters changing

Post by Epiales »

Callan S. wrote:

Code: Select all

    $characters=$_GET['characters'];
    $charactersinfo = "SELECT * from stats where creature = '$creature'";
Should '$creature' actually be '$characters'?
No, the field in the stats table is creature. It's putting the creature in the database fine. It's just changing whom you fight with page refresh, which I can't figure out :(
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Characters changing

Post by Callan S. »

I don't understand - with your code, unless you ALWAYS pass on $_GET['characters'], it's going to use a random creature (as per your 'else' statement). One link that lacks it and bang, new random creature.

Code: Select all

$id = $stats['id'];
Where does $stats come from? Is it set up elsewhere in the code?
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Characters changing

Post by Epiales »

Callan S. wrote:I don't understand - with your code, unless you ALWAYS pass on $_GET['characters'], it's going to use a random creature (as per your 'else' statement). One link that lacks it and bang, new random creature.

Code: Select all

$id = $stats['id'];
Where does $stats come from? Is it set up elsewhere in the code?
Stats is the table that holds all the player information. Other than the username, id, and pass, and access levels. So when they start fighting a character, that characters id is placed in the stats table, under the field creature. And it knows to put the creature under the correct player, based on the stats id field. I know there has to be a way to do it, but don't see how. Maybe when they go to battle, have the database call what creature is in the database? I'll do some experimenting. I tried something like that earlier, but gave me a headache lol. I'll try again.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Characters changing

Post by Epiales »

Okay, I have it setup where, depending on what location you're at, you fight certain characters in that location. What I can't get, is for it to keep the same character upon page refresh. I have the character stored in the database, but when you call the creature from the database, it never changes to a different creature. I can't figure out how to make it where you can fight one creature, and have the database change creature numbers so that you get to fight a different creature. Ya just keep fighting the same one over and over :( *BORING* lol Below is my code.... If someone can give me a hint, or point me in the right direction, I would be happy :) Thanks...

Code: Select all

if (isset($_GET['characters']))
{
    $characters=$_GET['characters'];
    $charactersinfo = "SELECT * from characters where name = '$characters'";
    $charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get the character you were fighting!");
    $charactersinfo3 = mysql_fetch_array($charactersinfo2);

} else {


    $areaninfo="SELECT * from locations where type='arena' AND location = '$stats[location]'";
    $areaninfo2=mysql_query($areaninfo) or die("could not get arena");
    $areaninfo3=mysql_fetch_array($areaninfo2);
    $arenalevel = $areaninfo3['level'];


////// SELECTS THE ARENA LEVEL AND LOCATION OF THE PLAYER, THEN PULLS THE CREATURE ID IN PLAYER STATS  FROM DATABASE //////
    $creature = $stats['creature'];
    $charactersinfo = "SELECT * from characters where level = '$arenalevel' AND id = '$creature' order by rand() limit 1";
    $charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get a character!");
    $charactersinfo3 = mysql_fetch_array($charactersinfo2);
    $id = $stats['id'];
    $cid = $charactersinfo3['id'];
    $updateplayer="update stats set creature='$cid' where id='$id'";
      mysql_query($updateplayer) or die("Could not update player");
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
    $characters = $charactersinfo3['name'];
    $charactershp = $charactersinfo3['hpoints'];
    $charactersattack = $charactersinfo3['attack'];
    $charactersdefense = $charactersinfo3['defense'];
    $charactersgold = $charactersinfo3['gold'];
    $charactersloot = $charactersinfo3['loot'];
    $hasloot = $charactersinfo3['isloot'];
If I put this:

Code: Select all

    $charactersinfo = "SELECT * from characters where level = '$arenalevel' order by rand() limit 1"; 
Then it will allow users to refresh and get a new character :( :(
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: Characters changing

Post by MikuzA »

I would suggest the following:

Have this query exectued ONLY if the player doesn't have an enemy

Code: Select all

$charactersinfo = "SELECT * from characters where level = '$arenalevel' order by rand() limit 1";  
Otherwise just retrieve the enemy-information from the place where you store it's hp/stuff.

This way, on page refresh you check in following order:

1. Get Player information.
2. Check if Player has enemy.
3A. IF Player has enemy >> Retrieve enemy information.
3B. IF Player has no enemy >> Randomize a new enemy.
4. Ready.

If 3B is ran, it is stored to the database in players enemy details, therefore refreshing the page won't allow it to change the opponent at all.

Makes sense? :) Hope it helps.
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Characters changing

Post by Epiales »

MikuzA wrote:I would suggest the following:

Have this query exectued ONLY if the player doesn't have an enemy

Code: Select all

$charactersinfo = "SELECT * from characters where level = '$arenalevel' order by rand() limit 1";
Otherwise just retrieve the enemy-information from the place where you store it's hp/stuff.

This way, on page refresh you check in following order:

1. Get Player information.
2. Check if Player has enemy.
3A. IF Player has enemy >> Retrieve enemy information.
3B. IF Player has no enemy >> Randomize a new enemy.
4. Ready.

If 3B is ran, it is stored to the database in players enemy details, therefore refreshing the page won't allow it to change the opponent at all.

Makes sense? :) Hope it helps.
I tried the if the player has an enemy and it always pulled the id of the enemy in the database, which always remained the SAME enemy lol... It never changed. So I will jump back on it today and see what comes :) YAY
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: Characters changing

Post by MikuzA »

If that happened, you didn't update/change the enemy ID of the player when the enemy died.
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Characters changing

Post by Epiales »

MikuzA wrote:If that happened, you didn't update/change the enemy ID of the player when the enemy died.
Yeah, that's what I have the problem with. I don't know how to tell it to "CHANGE" to another character. It stores the characters ID in the database just fine, but it always chooses that same character ID because that is what's in the database. I know I have to update the player, but don't know how to command it to 'change' to a new character once the one they are fighting is dead.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”