I'm creating my own text-based MMORPG, using PHP and MySQL. I've got quite a bit done, but I'm having problems creating weapons.
I want to be abble to allow users to buy weapons, then have them either equiped or in their inventory.
This is the shop (well, the bit you need to see):
PHP Code:
<h2>Gareths Weapon Shop</h2><br /><br /><br />Welcome to my weapon shop! Only the finest weapons are stocked here!<br />
Here are my wares:<br /><br />
<table cellspacing="0" cellpadding="0" border="0" align="center" width="95%">
<tr>
<td width="31%" height="30" align="left" valign="top">
<b>Name</b>
</td>
<td width="17%" align="left" valign="top"><b>Cost</b></td>
<td width="38%" height="30" align="center" valign="top">
<b>Strength needed</b>
</td>
<td width="14%" height="30" align="left" valign="top">
</td>
</tr>
<tr><td valign="top" align="left" height="20">Stick</td>
<td valign="top" align="center">100</td>
<td valign="top" align="center">5</td><td valign="top" align="left">[<a href="weapons_processor.php">Buy</a>]</td></tr><tr><td valign="top" align="left" height="20">Rusty Knife</td>
<td valign="top" align="center">250</td>
<td valign="top" align="center">10</td><td valign="top" align="left">[<a href="weapons_processor.php?aome=2">Buy</a>]</td></tr><tr>
<td valign="top" align="left" height="20">Wooden Club</td>
<td valign="top" align="center">500</td>
<td valign="top" align="center">15</td><td valign="top" align="left">[<a href="weapons_processor?name=3">Buy</a>]</td></tr><tr>
<td valign="top" align="left" height="20">Rusty Short Sword</td>
<td valign="top" align="center">1000</td>
<td valign="top" align="center">25</td>
<td valign="top" align="left">[<a href="weapons_processor.php?name=4">Buy</a>]</td></tr> <tr>
<td valign="top" align="left" colspan="6">
<br><br>
[<a href="village.php">Back</a>]
</td>
</tr>
</table>
So, this takes them to the weapons_processor.php page when they click a link. Then, it simply puts the weapon into the database, under their name, in unused_weapon1
I have a script that lets them "equip" this item, so that they can use it as their weapon:
PHP Code:
<?php $weapon_query = "UPDATE login SET weapon='$unused_weapon' WHERE email = '{$_SESSION['logname']}'" or die ("You suck");
mysql_query($weapon_query)or die ("Your weapon 2 not updated");
$weapon_query2 = "UPDATE login SET unused_weapon='' WHERE email = '{$_SESSION['logname']}'" or die ("You suck");
mysql_query($weapon_query2)or die ("Your weapon 2 not updated");
mysql_close();
echo "You've equiped your $unused_weapon";?>
However, I also need a script that allows them to un-equip this weapon. I made this
PHP Code:
<?php $weapon_query = "UPDATE login SET unused_weapon='$weapon' WHERE email = '{$_SESSION['logname']}'" or die ("You suck");
mysql_query($weapon_query)or die ("Your weapon 2 not updated");
$weapon_query2 = "UPDATE login SET weapon='' WHERE email = '{$_SESSION['logname']}'" or die ("You suck");
mysql_query($weapon_query2)or die ("Your weapon 2 not updated");
mysql_close();
echo "You've unequiped your $weapon";?>
However, if they click the wrong link, say they try to unequip nothing, then they lose their unequiped weapon. Is there a way to prevent this.
I also have the problem of multiple weapons. I want people to be able to have several weapons, but I've found problems. If they buy a weapon from the shop, then it places it into the unused_weapons1 column, but what if they want to buy two weapons? How can I make it so that it stores it into a different place?
I know it's complex, but that's why I need help. I need someone to make some of the code to point me in the right direction, and explain what it all does.
I'll be very grateful to anyone who can help me!