Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Help with blueprint for ammo into magazines

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.

Product Version: UE 4.19
more ▼

asked Apr 24 '18 at 04:10 AM in Blueprint Scripting

avatar image

1 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Apr 24 '18 at 07:14 AM

avatar image

897 12 14 22

avatar image Kitav Apr 24 '18 at 06:17 PM

Much appreciated, I'm definitely going to need some help along the way for something like this lol.

avatar image Vaheva Apr 24 '18 at 06:32 PM

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.

avatar image goncasmage Apr 24 '18 at 06:56 PM

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?

avatar image Vaheva Apr 24 '18 at 07:07 PM

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.

avatar image goncasmage Apr 24 '18 at 07:26 PM

Well i simply mentioned that because he said he wanted to drag ammo into the magazine :p couldn't really find any other way to do it...

avatar image goncasmage Apr 24 '18 at 06:57 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question