Raised This Month: $ Target: $400
 0% 

[SOLVED] TF2 Reading the current ammo of pyro/heavy


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BrutalGoerge
AlliedModders Donor
Join Date: Jul 2007
Old 11-13-2011 , 19:42   [SOLVED] TF2 Reading the current ammo of pyro/heavy
Reply With Quote #1

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 :>
__________________
My Pluggies If you like, consider to me.

Last edited by BrutalGoerge; 11-13-2011 at 19:43.
BrutalGoerge is offline
BrutalGoerge
AlliedModders Donor
Join Date: Jul 2007
Old 11-20-2011 , 19:06   Re: TF2 Reading the current ammo of pyro/heavy
Reply With Quote #2

yeah im too dumb to figure this out, no matter what i change, it says PRIMARY AMMO: 255
/help me :<
__________________
My Pluggies If you like, consider to me.
BrutalGoerge is offline
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
BrutalGoerge
AlliedModders Donor
Join Date: Jul 2007
Old 11-20-2011 , 23:45   Re: TF2 Reading the current ammo of pyro/heavy
Reply With Quote #4

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!!!!!!
__________________
My Pluggies If you like, consider to me.
BrutalGoerge is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:50.


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