Inventories over Network

Not quite sure if this is the right section for this, but it’s about Networking & Multiplayer so i guess? :slight_smile:

Okay so I got some little RPG game and for now I think it needs some Inventory System, Saved and Handled on the Server Side.
By the Way I’m using KryoNet for the Network Stuff :slight_smile:

What I want to do: some 6x4 Inventory System:
[][][][][][]
[][][][][][]
[][][][][][]
[][][][][][]
And maybe some Slots for Armor and a Weapon but that’ll come Later.
I think of Storing this in an Item[24] Array (Slots are x+y*6 for that to access it like a 2 Dimensional Array when i just have a 1 Dimensional Array right?)
The problems I have are:

  • I’m not sure on how to send and Array of Objects (registering the Object and send a Single one works but sending an Array of it somehow doesn’t?)
  • I don’t know how often the Inventory should be send to the Player (guess just every time it changes and send it via TCP?)
  • I don’t know how to handle when the Client wants to move Objects in his Inventory, In Minecraft, does the Inventory contain some extra slot for the item the Player has Dragged with the Mouse?

For example picking up these Ores, change them to Stone works but well i don’t have an Inventory System now:

I wouldn’t send the entire object over the network, that would be silly and a waste of bandwidth. Just send over the item type and whatever characteristics you need. I have a feeling I read your question wrong though!

I could send it to the Player when he opens his inventory once and send it to the server when he closes his inventory once, that wouldn’t be much loss in the bandwidth if i send the entire object no? and with that i wouldn’t need an Item Slot for “in his hand” (i think that’s what minecraft does when you drag an item). So i could just send the Item[24] Array, which is my main Problem: How do i send an Array? i registered Item.class, and i can send Objects from the Type Item but i just can’t send the Array? :-\

Minecraft does it like this (for release 1.7.X):
When the player connects, his inventory is sent from the server to the client, who stores it for this (and only this) session.
When the player drags a item into another slot, the client sends a ‘Drag Item Into Other Slot’-packet to the server, which then verifies the action, and sends the (now changed) inventory back to the client, who then updates its local inventory copy.

Thats how you can do it, and its actually very easy to do.

Have a nice day!

  • Longor1996

Okay, that will work too but I still don’t know how to send the whole Inventory cause it’s an Array of Objects and I don’t know how to send an Array? :x

Array is an object itself.

Okay, just checked it, registering Item[].class works, didn’t know that though :o Thanks

I don’t even know what I’m talking about myself. I just thought that arrays might be objects and I posted it :smiley:

silently The lucky help…

I think of it this way (not sure if it is most efficient or most smart way though):

When the player joins the game for the first time, he/she has a blank inventory, right?
So when he/she plays for a bit, gains stuff, and then logs out, you take the items that (preferably objects/entitles) he/she got and sterilize them. Then when the player logs back on, the server searches for the players’ inventory file, and does the opposite, changing them back to objects/entitles that the player can use.