KingSpud
(KingSpud)
March 29, 2019, 6:12pm
1
Hi,
Fairly new to C++ in UE but ive learnt a lot the past few weeks and im comfortable creating a simple shooter game.
Ive got my character setup as well as my weapon functionality such as shooting.
Im now struggling with the reload functionality and was hoping someone would be able to help.
From my understanding i would need to create a few variables such as: Current ammo in chamber, Maximum ammo the gun can hold etc etc.
Just a little confused as to how i would go about creating the functions to actually carry out the reload.
Thanks!
Marmot
(Marmot)
March 29, 2019, 8:39pm
2
In our game the reload function looks like this
void APickup_Weapon_base::Reload()
{
int16 SavedSpareAmmo = SpareAmmo;
if (SpareAmmo > 0)
{
if (MaxLoadedAmmo > 0)
{
if (LoadedAmmo < MaxLoadedAmmo)
{
if (LoadedAmmo + SpareAmmo > MaxLoadedAmmo)
{
if (SpareAmmo - (MaxLoadedAmmo - LoadedAmmo) >= 0)
{
SpareAmmo -= (MaxLoadedAmmo - LoadedAmmo);
}
else
{
SpareAmmo = 0;
}
LoadedAmmo = MaxLoadedAmmo;
}
else
{
if (SpareAmmo - (MaxLoadedAmmo - LoadedAmmo) >= 0)
{
SpareAmmo -= (MaxLoadedAmmo - LoadedAmmo);
}
else
{
SpareAmmo = 0;
}
LoadedAmmo += SavedSpareAmmo;
}
}
}
else
{
SpareAmmo = 0;
LoadedAmmo += SavedSpareAmmo;
}
}
}
KingSpud
(KingSpud)
March 30, 2019, 11:40am
3
Marmot:
In our game the reload function looks like this
void APickup_Weapon_base::Reload()
{
int16 SavedSpareAmmo = SpareAmmo;
if (SpareAmmo > 0)
{
if (MaxLoadedAmmo > 0)
{
if (LoadedAmmo < MaxLoadedAmmo)
{
if (LoadedAmmo + SpareAmmo > MaxLoadedAmmo)
{
if (SpareAmmo - (MaxLoadedAmmo - LoadedAmmo) >= 0)
{
SpareAmmo -= (MaxLoadedAmmo - LoadedAmmo);
}
else
{
SpareAmmo = 0;
}
LoadedAmmo = MaxLoadedAmmo;
}
else
{
if (SpareAmmo - (MaxLoadedAmmo - LoadedAmmo) >= 0)
{
SpareAmmo -= (MaxLoadedAmmo - LoadedAmmo);
}
else
{
SpareAmmo = 0;
}
LoadedAmmo += SavedSpareAmmo;
}
}
}
else
{
SpareAmmo = 0;
LoadedAmmo += SavedSpareAmmo;
}
}
}
Im just going to assume:
LoadedAmmo is whats in the current clip
MaxLoadedAmmo is the maximum amount that the clip can hold
SpareAmmo would be the difference when youre reloading?
Id just need to figure out when to call my StopFire() function