When attacking a monster i pull a monster from the database at random and use it and update it during a battle.
However I believe if someone else were to select this monster 2 you'd have two people beating on it.
Problem is I do not want this.
I thought I'd add a busy field to the monster table, so i'd only pull monsters who are not busy ,but that means i'd have to make a ton of monsters so they were not busy all the time.
So how can I add 1 of each monster in the DB and use it in battle and not have other people be able to battle it also?
I guess basically what I'm asking for is "instanced monsters".
Battle and monsters
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Battle and monsters
Your last sentence basically hit the nail on the head. "Instanced monsters" is exactly what you need, which means you need templates to base those instances on. So you would create something like a "master_monsters". You would not need things like current HP in this table, but would need max HP. This table will essentially be read-only. When a battle starts, you copy the values from the master table into another table, for example maybe "instance_battles". Except you would not want to make direct copies, as this would be causing data duplication. Instead, you would want to turn these master values into instance values (for example, max_hp becomes just hp), and only copy over the ones that could theoretically change in battle. In this table you would also keep track of the player ID of the character fighting the monster, as well as the ID of the monster from the master_monsters table so you can reference any non-changing info, such as their name or max_hp.
This way, when the monster is killed it can simply be deleted from the instance_battles table, and only one player can be registered to fight a monster at the same time.
This way, when the monster is killed it can simply be deleted from the instance_battles table, and only one player can be registered to fight a monster at the same time.
The indelible lord of tl;dr
Re: Battle and monsters
You can make a space for the monster in the players own entry in the database - copy over the monster stats to the players entry. Now the player has their own discrete copy.
Though I actually really quite liked the early tutorial in how monsters just died!
I aught to think of some way of sustaining that...perhaps monster breeding patterns!
Though I actually really quite liked the early tutorial in how monsters just died!
I aught to think of some way of sustaining that...perhaps monster breeding patterns!
Re: Battle and monsters
I was thinking you just put the monster's stats as variables... Something like this:
And so on...
Code: Select all
$sql = "SELECT * FROM monsters WHERE monster='$monster'";
$send = mysql_query($sql);
$arr = mysql_fetch_assoc($send);
$monster = $arr['monster'];
$monst_att = $arr['attack'];
$monst_def = $arr['defend'];
And so on...
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Battle and monsters
The problem is that those variables will be lost on the first page change, which means you need to store them somewhere, and that is usually going to be the database 
The indelible lord of tl;dr
Re: Battle and monsters
will have to do that then
thanks