Battle and monsters

For discussions about game development that does not fit in any of the other topics.
Post Reply
Zykal
Posts: 31
Joined: Thu Nov 29, 2012 4:38 am

Battle and monsters

Post by Zykal »

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".
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Battle and monsters

Post by Jackolantern »

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. :)
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Battle and monsters

Post by Callan S. »

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!
User avatar
OoZI
Posts: 109
Joined: Mon Jan 02, 2012 4:22 pm

Re: Battle and monsters

Post by OoZI »

I was thinking you just put the monster's stats as variables... Something like this:

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...
-OoZI

My Blog
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Battle and monsters

Post by Jackolantern »

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
Zykal
Posts: 31
Joined: Thu Nov 29, 2012 4:38 am

Re: Battle and monsters

Post by Zykal »

will have to do that then :) thanks
Post Reply

Return to “General Development”