Merge pull request #109 from tanuki-billie/fix-low-ammo-indicator

Improved logic in HUD_AmmoString()
This commit is contained in:
cypress 2025-02-11 19:22:35 -08:00 committed by GitHub
commit 768c8fd3f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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