x

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"

Best way for associating Weapon and Ammo?

Hello.

Currently, my Weapon system is like this:

each weapon-derived class has its own field called AMMO and its own enumeration called WeaponType used to identify that weapon in the game. This way, if I want to pickup some ammo for that weapon, I just need to do something like:

FindWeaponByType(EWeaponType::ELightingGun) -> AddAmmo(20);

That will cycle through my

AWeapon* Inventory

until it finds the weapon with that enumeration and, once found, gives it some ammo

I don't like this system. I find it unflexible.


I want AMMUNITIONS to be independent and for each weapon that I will introduce in the game, I should define which kinds of ammo it uses for its PrimaryFire and which ones for its SecondaryFire

Let's pretend I want to make a Lightning gun in Unreal Tournament style. Well, there will be ammunitions called, for example, "Electricity"

Now let's say I want to make another weapon, which uses Bullets for its PrimaryFire, but as secondary fire it uses Electricity ammunitions.


From this example, you see that Electricity and Bullet are two kinds of Ammunitions that don't really belong to a specific weapon. They're independent


How could I achieve this?

Product Version: Not Selected
Tags:
more ▼

asked Apr 17 '16 at 01:34 PM in C++ Programming

avatar image

gedamial
122 37 35 48

avatar image gedamial Apr 19 '16 at 03:16 PM

My idea is to give the players an Inventory of Ammunitions, each one with its own EAmmoType (enumeration) and CurrentAmmo (int32) properties.

So the Player has an inventory of Ammo and he can add ammo to it through an Inventory search by EAmmoType.

Is this a good idea?

avatar image ScottSpadea Apr 19 '16 at 06:21 PM

EAmmoType is an enum, so you don't have to search through an array of structs, you can convert the enum to a byte, and use that as an index into an array of integers. just set up the array in the same order as the Enum.

avatar image gedamial Apr 19 '16 at 08:01 PM

What if I have a particular weapon where it's secondary fire uses a kind of ammo which requires the weapon to change something like the way it traces?Should I make a C++ class for each of these 'particular' weapons?

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Enumerate ammo and specify primary and secondary types of compatible ammo for each weapon as fields. Add type field to ammo. Check compatible types of ammo and weapon before pickup.

more ▼

answered Apr 17 '16 at 09:45 PM

avatar image

v.s.
337 9 7 25

avatar image gedamial Apr 17 '16 at 09:49 PM

But where do I store information for each type of ammo?

Electricity 50

Bullets 130

Rockets 15

Each ammo type has its own ammount of projectiles and whatever weapon wants to use those, it just decreases that ammount.

avatar image v.s. Apr 17 '16 at 09:55 PM
 class AAmmo
 {
     EAmmo Ammo;
     int32 Count;
 };
 
 class AWeapon
 {
     EAmmo AmmoPrimary;
     int32 CountPrimary;
 
     EAmmo AmmoSecondary;
     int32 CountSecondary;
 };

Perhaps the rational use of StaticClass or DynamicClass (new feature) in this case as alternative to enumeraion of the ammo types.

  class AWeapon
  {
      TSubClassOf<AAmmo> AmmoPrimary;
      int32 CountPrimary;
  
      TSubClassOf<AAmmo> AmmoSecondary;
      int32 CountSecondary;
  };

avatar image gedamial Apr 17 '16 at 10:01 PM

You're creating the Ammo class but not using it

avatar image v.s. Apr 17 '16 at 10:09 PM
 bool Compatible = *(Weapon->AmmoPrimary) == Ammo->GetClass();

avatar image gedamial Apr 17 '16 at 10:12 PM

Why you use CountPrimary and CountSecondary when you have the subclasses?

avatar image v.s. Apr 17 '16 at 10:17 PM

This is just an example of the actual number of ammo. Ammunition can contain its own parameters.

 Weapon->CountPrimary = Ammo->Count;

avatar image Snoxx Jan 29 '18 at 12:26 PM

And now for blueprint form pls?

avatar image PLACENTA_EATER Mar 15 '18 at 02:10 AM

this is C++ buddy. You can create a wrapper for this C++ to call it from BP pretty easily. Its called google.

(comments are locked)
10|2000 characters needed characters left
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