AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [SOLVED] TF2 Reading the current ammo of pyro/heavy (https://forums.alliedmods.net/showthread.php?t=172022)

BrutalGoerge 11-13-2011 19:42

[SOLVED] TF2 Reading the current ammo of pyro/heavy
 
Hi, for my medic ammo plugin, i just noticed it was showing 255 ammo for pyro and heavy all the time, and I'm not quite sure when this started happening, if it was a tf2 update, or sm change.

here's the code that I was using to read the ammo
Code:

stock GetHeavyPyroAmmo(client)
{
        new ammoOffset = FindSendPropInfo("CTFPlayer", "m_iAmmo");
        return GetEntData(client, ammoOffset + 4, 4);
}

ive tried doing different multiples of 4 for the offset 0-32, all just give me 255
before i go crazy with this later, i was hoping that maybe someone already knows!

thx :>

BrutalGoerge 11-20-2011 19:06

Re: TF2 Reading the current ammo of pyro/heavy
 
yeah im too dumb to figure this out, no matter what i change, it says PRIMARY AMMO: 255
/help me :<

Tylerst 11-20-2011 22:32

Re: TF2 Reading the current ammo of pyro/heavy
 
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]);
     }



BrutalGoerge 11-20-2011 23:45

Re: TF2 Reading the current ammo of pyro/heavy
 
wow don't i feel like the stooge mcFuck :( I dont even remember changing that bit, so i thought it was changes in tf2 that screwed it up and nothing i did... so i wasn't even looking at that portion

thanks a lot!!!!!! :D


All times are GMT -4. The time now is 12:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.