Raised This Month: $ Target: $400
 0% 

[TF2] Gamedata: GetMaxAmmo / GetMaxClip


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 05-15-2015 , 12:31   Re: [TF2] Accurately get a weapon's max clip/ammo.
Reply With Quote #1

Quote:
Originally Posted by Powerlord View Post
To be honest, after doing a bit of research, it's a bit of a pain to check ammo levels using methods. Hell, you'd need a signature to call CAmmDef::MaxCarry as it has no entity.

Incidentally, why would you need a TF2Items callback to get accurate numbers? Doesn't the post_inventory_application event fire after a player is given a new inventory? You could just iterate over their item slots then.
Hm, I used to use post_inventory_application but had problems. I ought to test it again.

and isvalident is something I mostly use privately, usually I edit that out of public things, dunno why I didn't here

So...

PHP Code:
stock GetWeaponAmmo(weapon)
{
    new 
owner GetEntPropEnt(weaponProp_Send"m_hOwnerEntity");
    if (
owner == -1) return 0;
    if (
IsValidEntity(weapon))
    {
        new 
iOffset GetEntProp(weaponProp_Send"m_iPrimaryAmmoType"1);
        return 
GetEntProp(ownerProp_Send"m_iAmmo"_iOffset);
    }
    return 
0;
}] 
I'd make an sdkcall but i'm too lazy.

Quote:
Originally Posted by Powerlord View Post
The 4 doesn't even need to be set as GetEntProp can figure it out on its own.
What exactly does "GetEntProp" do to "figure it out"? I see it has a default value of 4 for the size, but I don't see anything like sizeof(int) or something.
__________________

Last edited by Chdata; 05-17-2015 at 06:52.
Chdata is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-08-2015 , 16:47   Re: [TF2] Accurately get a weapon's max clip/ammo.
Reply With Quote #2

Quote:
Originally Posted by Chdata View Post
What exactly does "GetEntProp" do to "figure it out"? I see it has a default value of 4 for the size, but I don't see anything like sizeof(int) or something.
Whoops, I missed this last month.

If you check a netprops / datamaps list, you'll notice that it includes the number of bits each thing takes up. That's because the SendProp class (which is what netprops are) stores this information1. I'm assuming the DataMap equivalent does as well.

1Unless it's a CUtlVector SendProp or one of its direct children. These are really a wrapper around a CUtlVector object on the server side and not an actual number/string property.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-08-2015 at 16:51.
Powerlord is offline
psychonic

BAFFLED
Join Date: May 2008
Old 06-08-2015 , 17:11   Re: [TF2] Accurately get a weapon's max clip/ammo.
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
If you check a netprops / datamaps list, you'll notice that it includes the number of bits each thing takes up. That's because the SendProp class (which is what netprops are) stores this information1. I'm assuming the DataMap equivalent does as well.
Both store a data type (int, float, etc.), and SendProps also store a count of bits to be networked.
psychonic 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 18:33.


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