BugfixedHL
BugfixedHL copied to clipboard
Add colors for ammo hud
Info
It will color ammo depending on how much you have.
- 0..20% ammo - red;
- 21..50% ammo - orange;
- 51..90% ammo - yellow;
- 91..100% ammo - green.
Fixed
- Fixed backpack ammo not flashing when it changes
- Fixed inconsistent dimming in backpack ammo
Screens

CHud::GetHudAmmoColor may cause "Integer division by zero" exception if maxvalue = 0 for whatever reason. Although I have no idea how to reproduce it (it happened on one particular server when dropping all weapons), I have received a crash report with that error.
diff --git a/cl_dll/CHud.cpp b/cl_dll/CHud.cpp
index de1a1cd..f74a385 100644
--- a/cl_dll/CHud.cpp
+++ b/cl_dll/CHud.cpp
@@ -1037,7 +1037,7 @@ void CHud::GetHudColor( int hudPart, int value, int &r, int &g, int &b )
void CHud::GetHudAmmoColor(int value, int maxvalue, int &r, int &g, int &b)
{
RGBA *c;
- if (maxvalue == -1) // if you are using custom weapons, then default colors are going to be used....
+ if (maxvalue == -1 || maxvalue == 0) // if you are using custom weapons, then default colors are going to be used....
{
ParseColor(m_pCvarColor->string, m_hudColor); c = &m_hudColor;
}