View Single Post
psychonic

BAFFLED
Join Date: May 2008
Old 05-12-2015 , 13:35   Re: [TF2] Accurately get a weapon's max clip/ammo.
Reply With Quote #8

Quote:
Originally Posted by Chdata View Post
Anyway, TF2 doesn't seem to have a netprop or datamap for a weapon's max clip/ammo, meaning you have to get their 'current' clip/ammo...
As Powerlord mentioned, there are virtual methods for this on the weapon itself. They exist in every game and it would be a good candidate of something to be added to SDKTools as it also handles any game-specific logic rather than just reading the weapon script. Additionally, default ammo/clip is not guaranteed to be the max.

There are multiple other issues here as well.

Quote:
Originally Posted by Chdata View Post
#define TF_MAX_PLAYERS 34
There isn't much of a reason to not uses (MAXPLAYERS + 1) here instead of making your own define. Srcds already has a much higher memory variance than the 1.5kb you're saving with this. Additionally, if other people try to do the same, the define could conflict with another, or even be defined differently in the case of someone doing the same, but having it as 33 and then doing a +1.

Quote:
Originally Posted by Chdata View Post
new iOffset = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType", 1)*4;
new iAmmoTable = FindSendPropInfo("CTFPlayer", "m_iAmmo");
return GetEntData(owner, iAmmoTable+iOffset, 4);
Quote:
Originally Posted by Chdata View Post
new AmmoClipTable = FindSendPropInfo("CTFWeaponBase", "m_iClip1");
return GetEntData(weapon, AmmoClipTable);
GetEntProp should be used, else cache is being bypassed and for extra complication of code.

Quote:
Originally Posted by Chdata View Post
if (!IsValidEnt(iWeapon) || !GetEdictClassname(iWeapon, szClassname, sizeof(szClassname)))
This is checking whether it's a valid entity, but then getting the edict classname. Not all entities have edicts. GetEntityClassname or IsValidEdict would be more appropriate.

Quote:
Originally Posted by Chdata View Post
stock bool:IsValidEnt(iEnt)
This is ambiguously named and requires extra effort to figure out what the difference between IsValidEntity and IsValidEnt are.
psychonic is offline