game - adding items with high customization possibilities

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arukomp
Forum Contributor
Posts: 113
Joined: Sun Sep 24, 2006 4:22 am

game - adding items with high customization possibilities

Post by arukomp »

Hello,

I'm creating an browser based RPG game. I think you've played them at least once and you know there are things like spells, sometimes various abilities and professions. Here's my problem:

I'm going to create lots of spells and all of them will do something different than others. I want to make them very flexible. I've decided to write a block of PHP code about what each spell will have to do and put these block into MySQL database, so it's easier to edit them later in Admin panel of the game (won't have to edit php files and upload them, saves lots of time). Now what I need to do is to take that code block from mysql database and execute it so it does what's written in the block. How can I do that?

If I add more than 100 spells (many classes to choose from with lots of spells) to a php file with code blocks for each spell, the file would be huge and I want to add a spell I would need to edit that file and then upload it.

I just want to make my script flexible so that spells, professions and abilities could be customizable by php language. You're very welcome to offer any ideas how can I do that even if it's not like I thought. Maybe making a big file with functions for each spell is a better idea, I don't know... I don't have much experience with PHP (about a half a year) so I'm asking for your help.

Thanks for any suggestions!
arukomp
Forum Contributor
Posts: 113
Joined: Sun Sep 24, 2006 4:22 am

Post by arukomp »

No one knows? :( Please, at least point me to the right direction...
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Well lets say your a member picks a HP-Boost potion (like what is going to be in my online RPG game ), then you'd simply select it from the database (using MySQL SELECT Query) then add a MySQL UPDATE Query in the equation too. For example:

Code: Select all

<?php
$sql = "SELECT * FROM items WHERE item = 'HPBoost'";
$result = mysql_query($sql, $conn) or die(mysql_error());

while($it = mysql_fetch_array($result)) {
$sql1 = "UPDATE members SET hp = hp + '$it[upup]' WHERE userid = '$_COOKIE[userid]'";
$result1 = mysql_query($sql1, $conn) or die(mysql_error());
}
?>
Something like that. :)


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
arukomp
Forum Contributor
Posts: 113
Joined: Sun Sep 24, 2006 4:22 am

Post by arukomp »

Yes, I know that. But not all spells and items action will be to add or remove some health, mana or other statistics. Some spells will be to do something temporarily in fight on a player or a monster. And I want to edit those spells easily without having to edit them in php file and then upload it.
Post Reply