This commit is contained in:
MotoLegacy 2025-02-15 17:28:10 -08:00
commit 0f69c7f73d
2 changed files with 32 additions and 33 deletions

View file

@ -160,45 +160,38 @@ void() HUD_AmmoString =
vector textcolor = [1, 1, 1];
string message = "";
float reserve_is_low;
float reserve_is_empty;
float mag_is_low;
// Is the Reserve low?
if (W_IsLowAmmo(getstatf(STAT_ACTIVEWEAPON), getstatf(STAT_AMMO), false)) {
reserve_is_low = true;
} else {
reserve_is_low = false;
}
reserve_is_empty = getstatf(STAT_AMMO) <= 0;
// Is the Magazine low?
if (W_IsLowAmmo(getstatf(STAT_ACTIVEWEAPON), getstatf(STAT_CURRENTMAG), true)) {
mag_is_low = true;
} else {
mag_is_low = false;
}
mag_is_low = W_IsLowAmmo(getstatf(STAT_ACTIVEWEAPON), getstatf(STAT_CURRENTMAG), true);
// Nothing to do.
if (mag_is_low == false && reserve_is_low == false) {
// When the mag isn't low, there's nothing to do here.
if (mag_is_low == false) {
ammoopac = 1;
ammoloop = 0;
return;
} else {
// Display Reload text if the mag is low but reserve is not.
if (mag_is_low == true && reserve_is_low == false) {
message = "Reload";
textcolor = [1, 1, 1];
}
// Report NO AMMO if both are empty
else if (getstatf(STAT_CURRENTMAG) <= 0 && getstatf(STAT_AMMO) <= 0)
// Report NO AMMO if both current mag and reserve are empty
if (getstatf(STAT_CURRENTMAG) <= 0 && reserve_is_empty == true)
{
message = "NO AMMO";
textcolor = [215/255, 0, 0];
}
// Display LOW AMMO if mag is low and reserve is empty
else if (mag_is_low == true && getstatf(STAT_AMMO) <= 0)
else if (reserve_is_empty == true)
{
message = "LOW AMMO";
textcolor = [219/255, 203/255, 19/255];
textcolor = [219/255, 203/255, 19/255];
}
// Otherwise, just display reload text
else
{
message = "Reload";
textcolor = [1, 1, 1];
}
}

View file

@ -280,31 +280,37 @@ void(float side) W_Give_Ammo =
if (self.weapons[0].weapon_reserve == 0)
return;
float ammo_shot, max_mag, loadammo;
float ammo_needed, max_mag, loadammo;
max_mag = getWeaponMag(self.weapon);
// Determine how much ammo is needed to reload the selected side
if (side == S_LEFT) {
ammo_shot = max_mag - self.weapons[0].weapon_magazine_left;
ammo_needed = max_mag - self.weapons[0].weapon_magazine_left;
} else {
ammo_shot = max_mag - self.weapons[0].weapon_magazine;
ammo_needed = max_mag - self.weapons[0].weapon_magazine;
}
if (ammo_shot < self.weapons[0].weapon_reserve)
// Ensure we don't take more ammo than is in the reserve
if (ammo_needed > self.weapons[0].weapon_reserve)
{
self.weapons[0].weapon_reserve = self.weapons[0].weapon_reserve - ammo_shot;
loadammo = self.weapons[0].weapon_reserve;
loadammo = max_mag;
// Deplete reserve
self.weapons[0].weapon_reserve = 0;
}
else
{
loadammo = self.weapons[0].weapon_magazine + self.weapons[0].weapon_reserve;
self.weapons[0].weapon_reserve = 0;
// Load the ammo needed to fill the magazine, and subtract it from the reserve
loadammo = ammo_needed;
self.weapons[0].weapon_reserve -= ammo_needed;
}
// Apply ammo load to the correct side
if (side == S_LEFT) {
self.weapons[0].weapon_magazine_left = loadammo;
self.weapons[0].weapon_magazine_left += loadammo;
} else {
self.weapons[0].weapon_magazine = loadammo;
self.weapons[0].weapon_magazine += loadammo;
}
};
@ -2186,4 +2192,4 @@ void() WeaponCore_ClientLogic =
// Allow Melee to be pressed again
self.semi_actions &= ~SEMIACTION_MELEE;
}
};
};