Jump to content

Skill System (MMORPG)


Drezard

Recommended Posts

Hello, I am making a Text based MMORPG and I have finished a combat system. I now need help with a skills system. Basically I want the user to have about 5 - 10 skills that they can swap around. So....

 

I have about 50 different skills for the player to choose from and they can have 10 maximum. Now i need to bring these skills back out in combat...

 

So heres my ideas....

 

A) I could have one database field with all the skills in it... So something like "Skill 1, Skill 2, Skill 3..." and then just use explode to get all the skills when i need them.

 

B) I could have 10 fields in the database and just store one skill in each field. This could be a problem though, when it comes to the user deleting and getting different skills because then fields 1, 2 and 8 might be empty, while all the rest are full.

 

What other ideas are there?

 

- Cheers, Daniel

Link to comment
Share on other sites

My first idea for something like this would be to setup the database very simple.

 

Skills could be a table.

 

This table would have 3 parts.

 

ID|name|folder

0|cooking|cooking

1|hunting|hunting

 

 

Now, in the cooking folder the leveling.txt file would look like this:

 

level|xpneeded

1|0

2|500

3|750

 

Now, in items.txt it would look like this:

 

id|item|level|xpgiven

0|Bread|1|10

1|Pizza|3|50

 

 

Now, you would use file() and explode() to use these files.  You would remove the first line from each since that is just explaining the file while you create/edit it.

 

 

 

Next we need to use MySQL.  We want to store the user's data.

 

We would store it like this:

 

Table: SkillsKnown

Fields: userID, skillID, XP

UserID|SkillID|XP

0|0|500

 

This would be programmed to calculate that their XP is 500, so lets check what level that is.  It is right on level 2.  So they would be able to make any level 2 or lower items.

Link to comment
Share on other sites

objects are your best bet here you can also store 32 values in a bit using the bitwise operators you only want to store 10 skills so you could easily assign them to a skills attribute of an object

<?php
class Player
{
private $_skill;

	public function addSkill($value)
{
    	      $this->_skill = $this->_skill | $value;
}

public function hasSkill($value)
{
    if ($this->_skill & $value)
        return true;
}
}

class Skill
{
const fist  = 1;
const sword = 2;
const bow   = 4;
}

$player = new Player();
$player->addSkill(Skill::fist);
$player->addSkill(Skill::sword);

var_dump($player->hasSkill(Skill::fist));
var_dump($player->hasSkill(Skill::sword));
var_dump($player->hasSkill(Skill::bow));
?>

 

the above is just a quick proof of concept for you the return values are

 

true

true

null

 

I think this kind of thing is best suited to objects but if you must use a database an active record pattern would come in handy here

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.