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.