Text-Based MMORPG

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
copycat
Posts: 10
Joined: Wed Apr 16, 2014 12:49 pm

Text-Based MMORPG

Post by copycat »

Hi there,
As I said in the Introduction's, I found this forum while I was looking for PHP MMORPG tutorials on YouTube. I watched hallsofvallhalla's tutorial series and applied it but I was developing something different than hallsofvallhalla's game, I was building something like PokemonVortex (old PokemonCrater). What I managed to do so far;

1) Login/Register page,
Nothing to explain, its just login/register.

2) Page for searching Wild Pokemons,
For searching pokemons, I made a MySQL query which rolls the dices between 0-100 and after that, it pickes the pokemon type depending on number result. I have a table which is looks like this;
Table: PokemonSelection
1, NormalPokemons, 75
2, RarePokemons, 20
3, LegendaryPokemons, 3
4, RareLegendaryPokemons, 2

So lets say guesser picked number 61, query chooses the table "NormalPokemons". If guesser picks number 99, query chooses the table "RareLegendaryPokemons". I have 4 another tables, "NormalPokemons", "RarePokemons", "LegendaryPokemons", "RareLegendaryPokemons". After first query, another query follows it for picking random row from chosen table (It pickes "Pichu" from "NormalPokemons" table for example).

3) Wild Battle Page,
After wild pokemon selection, "Attack!" link appears below the pokemon information. When you click it, it redirects you to attack page. Attack page gets information from URL with $_GET (attack.php?pokemon=Pichu&level=1 for example). In this page, it shows you the pokemons you have for attacking the wild pokemon with it and there is "Attack with this pokemon!" link under the pokemons you have. Lets say you have Raichu which is level 2, if you click "Attack with this pokemon!" link, it redirects you to "attack2.php?attacker=Raichu&attackerlevel=2&defender=Pichu&defenderlevel=1"

So I make it through so far but I have a problem now. hallsofvallhalla made MySQL query which updates goblins health points when he hits the goblin and he deleted it from database when he killed the goblin but I cannot do that because that wild pokemon should stay there. So for example; if my Raichu kills the wild Pichu I found, it should not be deleted from SQL because I should be able to find wild Pichu again. I figured I could create another table and make a query for copying finded wild pokemons to there. So I can do what hallsofvallhalla do, change the copied pokemons hitpoints or delete it if it die. Doing that is fine in localhost but I believe there will be chaos if there will be tens or hundreds of players.

This was my first work but I'm stuck here. I learned a lot of things about PHP and MySQL though. I am still committed to this project but I need suggestions now. Am I should continue this work with this way? (with PHP & MySQL) If not, what should I use? What is your opinions? I really want to hear them. Thanks for your patience, I know this is too long to read but I appreciate who read all of it :)
Ever tried. Ever failed. No matter! Try again! Fail again! Fail better!
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Text-Based MMORPG

Post by hallsofvallhalla »

Sounds like you are coming along nicely.

I would have a table for all Pokemon and a Column labeled something like "Rarity". You can then put the rarity value there and not need all the different tables.
Create a table called PlayerPokemon or something. When a player finds one it adds that pokemon to that table. It is basically a copy of the Pokemon from the Pokemon table except this table will also have PlayerId as a column. You now have an instance of the Pokemon you can alter delete level up and so forth without affecting the original Pokemon.

you could also have some randomizers that maybe change the stats a little to make each instnace of finding the same pokemon different. So the first time you find Pikachu his power is 40 and HP is 20, but next week you find one and this ones power is 45 and HP is 30.
Basically when you find it you query the Pokemon table then have a function to add or take away some stats then present it to the user. If they want to keep it then you add that pokemon to the PlayerPokemon table and tag it with the player Id then when you battle with it you query that pokemon.

Hope that makes sense and is what you were asking.
User avatar
copycat
Posts: 10
Joined: Wed Apr 16, 2014 12:49 pm

Re: Text-Based MMORPG

Post by copycat »

Rarity column would not work for me. I'm using 4 different tables because first it chooses pokemons rarity, then it chooses pokemon. I dont know how to write query for both of it so I did it seperately. About wild pokemons, players should battle with pokemon first, then they should capture it. Not the moment they found ;)
Ever tried. Ever failed. No matter! Try again! Fail again! Fail better!
Klown
Posts: 90
Joined: Tue Feb 22, 2011 5:59 am

Re: Text-Based MMORPG

Post by Klown »

Hi copycat!

here is a suggestion:

As halls suggested - move all monsters into 1 table and name it: "monsterClass"

setup the table with something like: id, name, rarity, stat1, stat2, stat3, etc

now you can pick a random number like you have in the past:

Code: Select all

$rarity = mt_rand(0,100);

if ($rarity < 76){
   $type = "normal";
}elseif($rarity > 75 && < 96){
   $type = "rare";
}elseif($rarity > 95 && < 99){
   $type = "legendary";
}else{
   $type = "rarelegendary";
}

$qry = mysql_query( "SELECT * FROM monsterClass WHERE rarity = "$type" ORDER BY RAND() LIMIT 1" );
$row = mysql_fetch_assoc( $qry );
the query above uses "ORDER BY RAND()" to randomly select a monster that fits the "WHERE" clause of the rarity type you randomly selected from before. the "LIMIT 1" will return only 1 randomly selected result, instead of all possibly matches based on rarity.

now you can pull the stat values from that randomly selected creature and store them into a new table, lets call that one "myMonsters"

it can be setup like : id, player, status, stat1, stat2, stat3
where player is the player who is battling that monster or captured him, and status is something like: alive, wounded, captured, etc,

Code: Select all

$qry = mysql_query( "INSERT INTO myMonsters VALUES('NULL','$playerName','battle','{$row['stat1']}','{$row['stat2']}','{$row['stat3']}')" );
now you can use this new monsters unique id to pull his information and change it as you wish, and if you kill the monster, you can now delete him from the table, or set his status to "dead" if you wanted the ability to reference him later on and revive him or something like that.

This is by no means a complete solution - but hopefully it gives you some ideas on how to perfect your game the way you envision it working.

Good luck and have fun!
if( $myGames != "Crap" ) {
  • please_donate( $money );
} else {
  • just_enjoy();
}
User avatar
copycat
Posts: 10
Joined: Wed Apr 16, 2014 12:49 pm

Re: Text-Based MMORPG

Post by copycat »

Hi Klown, I liked your advise and thank you very much for that. This queries can do the work but I have a question. In the far away future which this game have hundreds of players, will copying every wild pokemon which found by players to another table overload the MySQL and cause problems?
Ever tried. Ever failed. No matter! Try again! Fail again! Fail better!
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Text-Based MMORPG

Post by Jackolantern »

copycat wrote:Hi Klown, I liked your advise and thank you very much for that. This queries can do the work but I have a question. In the far away future which this game have hundreds of players, will copying every wild pokemon which found by players to another table overload the MySQL and cause problems?
MySQL has been stress-tested into the dozens of millions of records and works fine. You won't have any problems with MySQL breaking down from too many records :)

copycat wrote:3) Wild Battle Page,
After wild pokemon selection, "Attack!" link appears below the pokemon information. When you click it, it redirects you to attack page. Attack page gets information from URL with $_GET (attack.php?pokemon=Pichu&level=1 for example). In this page, it shows you the pokemons you have for attacking the wild pokemon with it and there is "Attack with this pokemon!" link under the pokemons you have. Lets say you have Raichu which is level 2, if you click "Attack with this pokemon!" link, it redirects you to "attack2.php?attacker=Raichu&attackerlevel=2&defender=Pichu&defenderlevel=1"
I thought I should also point out while you are still early in development that this is a problem. Anyone can alter the URL, so you don't want to use query strings for any game logic. If your script is actually pulling up and starting the battle based on what is in the query string, then you just allowed everyone to battle any Pokemon at any level they want to.

A better method would be to use a combination of sessions and your database to persist battle info and start combat. Probably at the point in your script where you are making the normal/rare/legendary/etc roll and determine what Pokemon they are going to fight would be a good place to store that into sessions or the database. Then when a battle request comes in from the client, you use sessions to determine who the player is and what they are fighting.
The indelible lord of tl;dr
User avatar
copycat
Posts: 10
Joined: Wed Apr 16, 2014 12:49 pm

Re: Text-Based MMORPG

Post by copycat »

I think about that before, I know I got this problem but I thought if I use ajax for this players can not figure out how to do it. But sessions makes much more sense, where should I start for learning how to do it? Is there any good video tutorial or something like that you know?
Ever tried. Ever failed. No matter! Try again! Fail again! Fail better!
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Text-Based MMORPG

Post by Jackolantern »

Read the tutorial I linked above :)

Also, a good rule of thumb to remember is this: never trust the browser. You can't hide anything. It isn't that hard to make your own AJAX requests to any server you want, without a browser needing to even have the page open. So remember that any request you receive can be a complete forgery, so it is up to your server to validate everything.
The indelible lord of tl;dr
User avatar
copycat
Posts: 10
Joined: Wed Apr 16, 2014 12:49 pm

Re: Text-Based MMORPG

Post by copycat »

Oh didnt see that, sorry but its getting late here and im little sleepy :P Thanks for advices, I'll look into it tomorrow.
Ever tried. Ever failed. No matter! Try again! Fail again! Fail better!
User avatar
copycat
Posts: 10
Joined: Wed Apr 16, 2014 12:49 pm

Re: Text-Based MMORPG

Post by copycat »

Klown wrote:$qry = mysql_query( "SELECT * FROM monsterClass WHERE rarity = "$type" ORDER BY RAND() LIMIT 1" );
$row = mysql_fetch_assoc( $qry );
[/code]
I was keep getting error from this query and couldnt figure it out till now, rarity = "$type" should be rarity = '$type' :P

I got another question about this;

Code: Select all

if ($rarity = "Normal")
 {
 echo 'this is a normal pokemon';
 }
else
 {
 echo 'this is rare, legendary or rare legendary pokemon';
 }
Where do I making mistake in this codes?

Edit: Got it, looks like if ($rarity = "Normal") should be if ($rarity == "Normal")

Now I am little bit confused about sessions, I've read the article from that link and understood the basis of sessions but couldnt figure out how to create unique session id's for each wild pokemon which is found by players. Thing is finding wild pokemon from database is easy, copying that pokemon to another table is easy too, real deal is giving that pokemon a unique identify for battle and making players attack it depending on that id by clicking to "Attack!" button. Thats where I got confused. Searched internet for examples of it but nothing came across yet, I will continue digging :shock:
Ever tried. Ever failed. No matter! Try again! Fail again! Fail better!
Post Reply

Return to “Beginner Help and Support”