Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Multiplayer inventory system?

Discussion in 'Scripting' started by GameCode4878, Mar 18, 2016.

  1. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    I want to make a simple inventory system. Does not have to be anything too fancy. My question is, how can i create an inventory system that is an array limited to 9 slots? then how would I add key binding system to where if one of the 9 number keys 1-9 is pressed, a string "ItemInHand" is set to the value of the corresponding item in the player's inventory? Using C#, thanks for any help.
     
  2. Craig8726

    Craig8726

    Joined:
    Jul 5, 2013
    Posts:
    79
    Are the items a class you created or just strings. If they are strings you can create an array of 9 strings. Then use the Input class to use keys to activate them. Each Index in the array can correspond to an Input. eg keyCode.Keypad1 for itemArray[0].
     
  3. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    How do I limit the inventory to just 9 slots?
    Question, how would I make the items to where all their info, such as their model and the damage they deal upon striking something, is all stored in class files?
     
    Last edited: Mar 18, 2016
  4. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    How do you use class files to store an item's info? Then how would the inventory be used with them?
     
  5. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
  6. Austin-Gregory

    Austin-Gregory

    Joined:
    Sep 19, 2013
    Posts:
    78
    I have an Inventory System tutorial available on my Youtube channel. We use JSON to store the item data. Taking it and just limiting the slots to a certain amount wouldn't be an issue. And to setup the key binds you'll just need to know which key references which slot since each slot has a unique ID and each slot knows which item it contains.

    Should be pretty helpful for you, shamless plug or not. :)
     
  7. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    Is there a way to take that inventory system and add an "Equip" setting to where the player can equip an item as a weapon?
     
  8. ShokeR0

    ShokeR0

    Joined:
    Feb 24, 2016
    Posts:
    112
    You ask so many questions, just go learn c# by yourself we won't code everything for you.
    It seem to me you are trying to do something you have no clue how to do. First learn about OOP
     
    Lee7 likes this.
  9. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    If I have not made it clear before, If you do not have anything helpful to post in my threads, THEN DON'T POST IN MY THREADS. I can code everything else in the game, it is just that I am having trouble with a few specific areas.
     
  10. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    Question to ShokeR0, how did you learn how to use C#? probably from asking questions. If you took the time to learn ABSOLUTELY EVERYTHING yourself , you probably would have given up on coding games because you would never find out everything you need to know to create a game. Almost every single complex game like what I am building has something in common: The people who made them had help, and did not do it alone. I ask so many questions because if I did try to do this alone, I would never finish. Because I have no one to go to for help in my actual area, the only place I can go for help is in the forums.
     
  11. Austin-Gregory

    Austin-Gregory

    Joined:
    Sep 19, 2013
    Posts:
    78
    Just to make it clear, @ShokeR0 has a valid point. He's only suggesting that you learn the language you're using along with a very important programming concept before you jump into building complex systems. No one is saying to not ask for help, everyone asks for help. But his suggestion is a good suggestion.

    Just to be clear, we're not insulting you by suggesting you learn the concepts required to build the system you're building. OOP can be a daunting concept to grasp at first, but it is very important in many aspects of game development, even when using component based engines.

    You won't regret stepping back and learning C#, and specifically OOP, before building complex systems that you only have to scrap later. Asking how something can be stored in a class file indicates that you're not sure how to structure a basic program in C#. Again, not an insult, it just makes us think you should learn the important bits before you jump into multiplayer inventories.
     
  12. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    Just a question, if I do make a multiplayer game, do you think serialization would be a good way to store their inventory data? If it is, then I think I may have found a way to complete the inventory system...
     
  13. ShokeR0

    ShokeR0

    Joined:
    Feb 24, 2016
    Posts:
    112
    Read your entire post again, you asked more than 6 - 7 questions in three posts.
    Yes, I learned C# asking many questions, but asking questions isn't always the best thing to do.
    You have to learn and search for the answers for yourself, the internet is large enough and your answer is out there.
    Second, what I was saying is that you are trying to implement a system yet you ask simple questions that you should already know if you are planning to build an inventory system. we can guide you step by step but how is it going to be any good? you will learn nothing by that, instead you should do your own research and find a way by yourself.
    And one last advice, when asking questions, try to be more specific, a generic question like :
    Won't do. and always, when someone give you an advice, don't take it personal because if they took the time to write it, they are trying to help you.