What you're doing is fine, the problem probably lies in how you use it in your plugin.
Edit: Found the problem, in your stock ShowInfo(medic, target):
PHP Code:
class = TF2_GetPlayerClass(target);
if (class == TFClass_Pyro || class == TFClass_Heavy)
{
iAmmo1 = GetHeavyPyroAmmo(target);
Format(sMessage, sizeof(sMessage), "Primary Ammo: %i ", iAmmo1);
}
else if (iClip1 == -1)
{
iAmmo1 = TF2_GetSlotAmmo(target, 0);
if (iAmmo1 != -1)
{
Format(sMessage, sizeof(sMessage), "Primary Ammo: %i ", iAmmo1);
}
}
if (iClip1 != -1)
{
Format(sMessage, sizeof(sMessage), "Primary Ammo: %i / %i ", iClip1, g_aClientSettings[target][iMaxClip1]);
}
Fix by changing the
if(iClip1 != -1) to
else, I also suggest adding a sniper check with the heavy/pyro since it would have the same problem, and possibly use a switch for better performance since this will be calculated repeatedly.
Another observation when I glanced at it, you check that the class isn't medic, right after checking that the class IS demoman?
Code:
if (class == TFClass_DemoMan)
{
if (iClip2 != -1 && class != TFClass_Medic)
{
Format(sMessage, sizeof(sMessage), "%sSecondary Ammo: %i / %i ", sMessage, iClip2, g_aClientSettings[target][iMaxClip2]);
}
}
Here's an example of how I would change that particular section:
PHP Code:
if (iClip1 == -1)
{
iAmmo1 = TF2_GetSlotAmmo(target, 0);
if (iAmmo1 != -1) Format(sMessage, sizeof(sMessage), "Primary Ammo: %i ", iAmmo1);
}
else Format(sMessage, sizeof(sMessage), "Primary Ammo: %i / %i ", iClip1, g_aClientSettings[target][iMaxClip1]);
new class = TF2_GetPlayerClass(target);
switch(class)
{
case TFClass_Pyro, TFClass_Heavy, TFClass_Sniper:
{
iAmmo1 = GetHeavyPyroAmmo(target);
Format(sMessage, sizeof(sMessage), "Primary Ammo: %i ", iAmmo1);
}
case TFClass_DemoMan:
{
if (iClip2 != -1) Format(sMessage, sizeof(sMessage), "%sSecondary Ammo: %i / %i ", sMessage, iClip2, g_aClientSettings[target][iMaxClip2]);
}
}