Drezard Posted March 24, 2007 Share Posted March 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/44095-skill-system-mmorpg/ Share on other sites More sharing options...
mattd8752 Posted March 24, 2007 Share Posted March 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/44095-skill-system-mmorpg/#findComment-214405 Share on other sites More sharing options...
Nameless12 Posted March 25, 2007 Share Posted March 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/44095-skill-system-mmorpg/#findComment-214566 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.