Game Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesGame Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old July 22nd, 2007, 07:54 PM
sockopen sockopen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 17 sockopen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 52 m 42 sec
Reputation Power: 0
Browser-Based MMO Inventory Problem

I am wondering how I would create an inventory for a player storing an infinite amount of predefined items. For example, lets say that I have the following items: Apple, Pear, and an Orange, each have pre-defined values (Apple has a Rating of 4 and a Price of 3, Pear has a Rating of 5 and a Price of 6, etc...) and I have a tonne of existing players who can have any amount of any of these items. I have no clue how to do this... currently I have a table called player which stores their session, username, amount of currency, etc... and I have a table called item which has the rating and sell price......

Any suggestions how to create this inventory for a player? I was considering limiting the amount of items a player could have and just literally adding x amount of fields for each inventory slot, but there has to be a significantly better way of doing this, particularly one that does not limit the amount of items each player can have.

Reply With Quote
  #2  
Old July 22nd, 2007, 08:06 PM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Posts: 1,210 MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 5 h 18 m 23 sec
Reputation Power: 316
you can create a third table that contain the user id, item id and a stock field which will hold the amount the user has of that item.

Reply With Quote
  #3  
Old July 22nd, 2007, 08:51 PM
sockopen sockopen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 17 sockopen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 52 m 42 sec
Reputation Power: 0
Still how would you hold different itemids? If I had a field called userid, itemid and amount... I can understand how that would work with an input like "username", "apple", "5", or something, but how would I store the amount of pears and oranges and bananas and anything else aswell in that table?

Reply With Quote
  #4  
Old July 22nd, 2007, 08:56 PM
gimp's Avatar
gimp gimp is offline
<?PHP user_title("gimp"); ?>
Click here for more information.
 
Join Date: Jan 2005
Location: Internet
Posts: 5,809 gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1555 Folding Title: Novice Folder
Time spent in forums: 2 Months 2 Weeks 4 Days 5 h 2 m 16 sec
Reputation Power: 1484
Send a message via AIM to gimp
...

I don't see the problem. You create a table with userid, itemid, amount (not necessary!) and itemname.
__________________
A work in progress: Card Game Platform (Status: Hard Drive Crash deleted project, rewrite planned) | Joke Thread
“Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was
its finest fruit.”

Reply With Quote
  #5  
Old July 22nd, 2007, 10:50 PM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Posts: 1,210 MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level)MrFujin User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 5 h 18 m 23 sec
Reputation Power: 316
Quote:
Originally Posted by sockopen
Still how would you hold different itemids? If I had a field called userid, itemid and amount... I can understand how that would work with an input like "username", "apple", "5", or something, but how would I store the amount of pears and oranges and bananas and anything else aswell in that table?



taking you example input then "username", "apple","5" is when the user have 5 apple. if a user have 10 orange then you will make an input like "username","orange","10".

"username" should more be a user_id that link to the user table (which contains session, username, amount of currency, etc... ).
Same goes with the item name, this should be a item_id that link to the item table (which store the rating and sell price etc).

hope this answer your questions.

Reply With Quote
  #6  
Old July 25th, 2007, 03:49 AM
TomGlenn TomGlenn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 57 TomGlenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 57 m 8 sec
Reputation Power: 5
Like these guys have already said:

User Table
==========================
UserID | Username | Password | Money... etc...
==========================

Item Table
==========================
ItemID | ItemName... etc...
==========================

Inventory Table
==========================
UserID | ItemID | Quantity
==========================
Only use quantity field if you want stackable items in set amounts... For example, a user can only have 20 oranges in one stack, before a new stack is made... (Think World Of Warcraft)

Otherwise, leave Quantity out and just do a record count to get the quantity of an item that the user has.

PHP Code:
 $query mysql_query("SELECT Count(*) FROM Inventory WHERE UserID=$userID AND ItemID=$itemID");

$quantity mysql_fetch_row($query);

echo 
$quantity[0]; 

Last edited by TomGlenn : July 25th, 2007 at 03:57 AM.

Reply With Quote
  #7  
Old July 25th, 2007, 10:32 PM
severeon severeon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 1 severeon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 57 sec
Reputation Power: 0
Couldn't you have each user have a userid, then make a separate table with the item info?

user info
=============================
userid | username | password | etc...
=============================

items

========================
userid | serialize array of items |
========================

First make a master array of all items:

$allitems = array();

Then make a web script to add something like this:

$item = array($itemname, $quantity);

Then add it to the bigger array like this:

array_push($allitems, $item);

Then serialize the big array like this:

serialize($allitems);

Then add it to the database...


When you want to get the info back, use this:

$allitems = unserialize(some_database_return_function());


Of course you would want to organize the items into weapons, healing items, keys, etc... just to make it a little faster to work with.

Reply With Quote
  #8  
Old July 26th, 2007, 09:57 AM
gimp's Avatar
gimp gimp is offline
<?PHP user_title("gimp"); ?>
Click here for more information.
 
Join Date: Jan 2005
Location: Internet
Posts: 5,809 gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)gimp User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1555 Folding Title: Novice Folder
Time spent in forums: 2 Months 2 Weeks 4 Days 5 h 2 m 16 sec
Reputation Power: 1484
Send a message via AIM to gimp
Having an array of items is a bad idea. What you usually want is an 'item' table: every single item in the game, itemid, user who owns it. That's what I'd do, personally. Makes finding items much easier.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesGame Development > Browser-Based MMO Inventory Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway