View Single Post
Tylerst
Veteran Member
Join Date: Oct 2010
Old 11-20-2011 , 22:32   Re: TF2 Reading the current ammo of pyro/heavy
Reply With Quote #3

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(sMessagesizeof(sMessage), "Primary Ammo: %i "iAmmo1);
}
else if (
iClip1 == -1)
{
     
iAmmo1 TF2_GetSlotAmmo(target0);
     if (
iAmmo1 != -1)
     {
          
Format(sMessagesizeof(sMessage), "Primary Ammo: %i "iAmmo1);
     }
}
if (
iClip1 != -1)
{
     
Format(sMessagesizeof(sMessage), "Primary Ammo: %i / %i "iClip1g_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(target0);
     if (
iAmmo1 != -1Format(sMessagesizeof(sMessage), "Primary Ammo: %i "iAmmo1);
}
else 
Format(sMessagesizeof(sMessage), "Primary Ammo: %i / %i "iClip1g_aClientSettings[target][iMaxClip1]);
 
new class = 
TF2_GetPlayerClass(target);
switch(class)
{
     case 
TFClass_PyroTFClass_HeavyTFClass_Sniper:
     {
          
iAmmo1 GetHeavyPyroAmmo(target);
          
Format(sMessagesizeof(sMessage), "Primary Ammo: %i "iAmmo1);
     }
     case 
TFClass_DemoMan:
     {
          if (
iClip2 != -1Format(sMessagesizeof(sMessage), "%sSecondary Ammo: %i / %i "sMessageiClip2g_aClientSettings[target][iMaxClip2]);
     }


Last edited by Tylerst; 11-21-2011 at 03:40.
Tylerst is offline