Weapon Inventory and how to script weapons.

Hey guys so this post is going to be a long one so if you don't have to time for it or aren't interested I would suggest skipping! Thanks for any help and your time spent trying to help!

So I want to make a gun/weapon system I am a complete beginner trying to understand C# and the best practices with it. The weapon system should have an inventory to work with like an primary and a secondary type not really an inventory I tried to do that following an brackeys video it worked but didin't really fit the way I want the system to be. What I want is a system where you can pick your weapon at the start and then in the game you can pickup ammo types for weapons like rifle ammo for all rifle type guns and pistol ammo for all pistols and etc. I want to also add multiple weapon types easy to make if I wanted to make a shotgun I could use a base weapon script and add whatever that needs to be added to make a shotgun I just don't know where to start. Would I start with an inventory or a weapon base class or what I've read a lot of forums but not a lot of results. Thank you guys so much for your time and I would be very glad if you can explain so that I can learn instead of copy and pasting a code or something like that, have a great rest of your day!

This sounds like an inventory that supports stacking. Look around for tutorials that do this, or else take an existing tutorial's code and add the notion of quantity of each item.

Remember, you will NEVER be able to pound such a system out all in one go. That's not how engineering works.

Instead, start from an existing functional inventory that does some part of what you want and iterate additional features onto it.

Sounds g

Sounds great man thanks for the advice, the problem when I started to develop games was just trying to make big game elements like when I was still learning and trying to make a system that was so hard for me to do instead of starting small any how I will try that I watched tutorials but It just doesn't give me a framework for say I can understand the way they do it but not have to implant it if that makes any sense thanks for your reply though!

You're welcome of course.

One thing you could try to really get a "feel" for what happens in this case is make a simple script that is just one cell of your inventory. Put this into a script that you can access through an "inventory API" that does certain things to a cell.

These functions might be:

"Set the type of item"
"Query the type and quantity of item in this cell"
"Add 1 item to this cell."
"Add N number of items to this cell."
"Remove N item from this cell."

Then you can have properties in the cell that say "I can hold only 1 item" or "I can hold up to 30 items" inside a particular cell.

Make some test buttons on a screen to do the above items, and also print out what's in the cell.

If you get that going you have done a huge amount of the work.

After that you need the aggregate collection of these things. That would have its own API, perhaps things that say:

"Give me a blank cell, I have something for you" (you get a cell, you call the above set type, set quantity)
"Find me a cell with N number of items of type X"

That's breaking the problem down into steps.

1 Like

That sounds great I will try to make something like that and let you know once I put it all together once again thanks for the ideas!

1 Like

I've been working on the inventory API and its going great got multiple void functions to get cell information to check if it is occupied or which item id is in said slot. Now I got the thinking about how to make the weapon do you have any ideas I can easily make a weapon system but just haven't thought about the framework do you have any ideas on that?

Not really specifically but I would go about it the same way... components and parts go into a weapon. Think about the last X games you have played that had a weapon system you liked, and think about what the API might have been for those games. That's how to digest it really.