Hi, I need a little assistance with a blueprint. The basic principle of it is the same for games like Escape From Tarkov. You have ammo in your inventory, you drag the ammo to the magazine, it loads the ammo, then drag the magazine in the weapon. When you reload it takes another mag out of your inventory and equips it to the weapon, takes the current mag in the weapon and places it back into the inventory, and if there is one mag that is full and one that is half empty it takes the full one first. I’m pretty new to programming so I’m having a difficult time trying to put this together and any help would be much appreciated.
Ok this is a little bit to unpack, but let’s take it one step at a time:
- You need at least three different blueprint/C++ classes: an ammo class, a magazine class and a gun class.
- The ammo has an amount (integer) associated with it, and so does the magazine., while the gun has a magazine associated with it.
- When you drag ammo into a magazine, you add the amount of that ammo to that magazine (the magazine should also have a max amount of ammo it can carry)
- When you drag a magazine to a gun, you associate that magazine to the gun, and whenever you fire, the gun removes 1 ammo from the magazine
- When the player reloads, you have to search all the magazines in the inventory to find the fullest one, using the integer amount associated with it
- I assume you’re doing this in the UI, in which case i recommend you look up “Drag and Drop Inventory” tutorials on youtube. You’ll basically have to have an inventory, which is an array of ItemSlots (class i just made up), and all those three classes i just mentioned inherit from this class, so that you can differentiate items in your inventory. When you’re looking for all the mags, for instance, you simply traverse the entire inventory, and cast to the Magazine class everytime, if the cast is successful, that item is a magazine
Note: you might need help along the way, and i’m not on my PC right now, so i can’t show you practical examples, but i’ll see what i can do later during the day. If you need anything else, let me know.
Much appreciated, I’m definitely going to need some help along the way for something like this lol.
This is not bad way. I think better start from inventory system, weapon and ammo will be one of items with own class.
But back to your #1 - it not need additional class for ammo. Just use stacks for magazine. My every magazine have variable ammo[integer] and when ammo is used it just remove one ammo. With magazine you can have variables for caliber, damage and what you need. Then when bullet is spawned, you can set it velocity and damage depending on ammo type, but this is stored in magazine variable still. I have over 100 items and creating additional not need class can make a mess.
If he wants to drag ammo into magazine, for example, 5 bullets into a magazine, i believe he will need a separate class for ammo, how else will he be able to represent that?
No problem when you stumble against a wall, just reply to this answer and i’ll do my best to help you! Make sure to mark the answer as answered if you’re satisfied with the answer.
Well, you can create single class, nothing wrong. I have for single ammo, like sniper or gauge, rockets - magazine type with one ammo only that can be added to other magazine. I don’t think is good idea to have additional instances for single bullets/ammo, where will be thousands in world. Everything is possible ofc.
Well i simply mentioned that because he said he wanted to drag ammo into the magazine couldn’t really find any other way to do it…