ShooterGame - Pick up ammo for weapon the player doesn't have?

Hit a little snag in a project I’m working on, and am looking for some assistance. I’ve started the project using Shooter Game as a base. I’m pretty new to C++, but I’m learning.

By default, ShooterGame spawns the player with the 2 default weapons (WeapGun & WeapLauncher) and then has ammo pickups for each scattered throughout maps. I’ve modified this flow slightly by creating weapon pickups (to give the player the weapon with 1 clip) AND ammo pickups (to give 1 clip). This functionality is working fine for the most part, however I’m having 1 issue. The player is unable to pick up ammo for a weapon they do not yet have in their inventory.

Example: A map has a Pickup_Gun item, and a Pickup_Gun_Ammo item. The player is currently able to pick up the gun, then the ammo… but not the ammo, then the gun. I need the player to be able to pick up ammo pickups even before they have the gun for which the ammo is for in their inventory. (to just cache the ammo, so when they do pick up the gun, they have more ammo to use)

Can anyone point me in the right direction to solve this problem? I think I need to initialize all the weapons as inventory members on the player, but with 0 ammo, and stop the player from being able to switch to them until they pick them up (AddWeapon())… but I’m not sure where/how to begin that.

Below is the CanBePickedUp function from ShooterPickup_Ammo.cpp. I did try changing the first if statement to “if (bIsActive)” (which in my mind should allow the player to pick up the ammo pack, even if they don’t have the weapon), but then the game crashes when the player attempts to pick up the ammo pack.

bool AShooterPickup_Ammo::CanBePickedUp(AShooterCharacter* TestPawn) const
{
	AShooterWeapon* TestWeapon = (TestPawn ? TestPawn->FindWeapon(WeaponType) : NULL);
	if (bIsActive && TestWeapon)
	{
		return TestWeapon->GetCurrentAmmo() < TestWeapon->GetMaxAmmo();
	}

	return false;
}

I’m thankful for any help you can provide.

You could try something like this instead. At the else statement is where you would put your code for picking it up. Otherwise when you walk over the placeable it shouldn’t do anything. In this case I made HP instead of ammo – but it is still a pickup regardless which should give you the right idea.

So basically if you want them to be able to pick up everything all you need to do is just adjust your ammo value the moment they step over it. Just make sure you don’t have any checks that are preventing this from happening.

Remember, it’s just a simple actor. :), good luck buddy!

void APlaceables::OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if (CanIEnter == true && OtherActor == PlayerCharacter)
	{
		if (PlayerCharacter->HP == PlayerCharacter->MaxHP) // Checks to see if the player has full HP or not.
		{

		}
               else
              {

              }

         }
}