Seems when use command buy item/weapon,
all weapons, item_kevlar(vest), item_assaultsuit(vesthelm), item_nvgs(nvgs) are using this function, except item_defuser
PHP Code:
CCSPlayer::GiveNamedItem( const char *pszName, int iSubType )
...which will StockPlayerAmmo( pWeapon ); at end of code.
if StockPlayerAmmo( pWeapon ); fail find entity as CWeaponCSBase, for example nvgs+vesthelm+vest,
it will then refill both, primary and secondary weapons ammo
This also happen to all items (nvgs, vest, vesthelm, defuser) with command give and SourceMod function GivePlayerItem,
it will refill primary and secondary weapons ammo.
But if those items are created by ent_create, it won't stock ammo.
---------------
I tried made plugin but I don't have time. There is many ways to get ammo (buyammo1, buyammo2, cl_rebuy "PrimaryWeapon PrimaryAmmo Defuser Armor HEGrenade Flashbang SmokeGrenade SecondaryWeapon SecondaryAmmo NightVision" and so on).
int primary = GetPlayerWeaponSlot(client, 0); int secondary = GetPlayerWeaponSlot(client, 1);
int primary_ammo_type = -1; int primary_ammo = -1; int primary_clip = -1; int secondary_ammo_type = -1; int secondary_ammo = -1; int secondary_clip = -1;
int primary = GetPlayerWeaponSlot(client, 0); int secondary = GetPlayerWeaponSlot(client, 1);
int primary_ammo_type = -1; int primary_ammo = -1; int primary_clip = -1; int secondary_ammo_type = -1; int secondary_ammo = -1; int secondary_clip = -1;
int primary = pack.ReadCell(); int primary_ammo_type = pack.ReadCell(); int primary_ammo = pack.ReadCell(); int primary_clip = pack.ReadCell(); int secondary = pack.ReadCell(); int secondary_ammo_type = pack.ReadCell(); int secondary_ammo = pack.ReadCell(); int secondary_clip = pack.ReadCell();
I was also writing a SourceMod patch yesterday, which looks almost the same (but using the old syntax). Your solution hooking item_pickup may be more reliable though, but you would want to use EntIndexToEntRef() for the entity IDs I think just to be safe:
PHP Code:
public Action:CS_OnBuyCommand(clientID, const String:weapon[]) {
if (IsValidClient(clientID) && IsPlayerAlive(clientID) && !IsFakeClient(clientID)) {
if (StrEqual(weapon, "vest") || StrEqual(weapon, "vesthelm") || StrEqual(weapon, "nvgs")) {
/**
* Find out current ammo and clip size of player
*/
new PrimaryAmmo = -1;
new PrimaryClipSize = -1;
new SecondaryAmmo = -1;
new SecondaryClipSize = -1;
new PrimaryWeaponEntity = GetPlayerWeaponSlot(clientID, 0);
new PrimaryWeaponEntityRef = -1;
new SecondaryWeaponEntity = GetPlayerWeaponSlot(clientID, 1);
new SecondaryWeaponEntityRef = -1;
/**
* Restore in the next frame, otherwise this will have no effect
*/
RequestFrame(GameBugFix_RestoreClientAmmoAndClipSize, handle);
}
}
}
public GameBugFix_RestoreClientAmmoAndClipSize(Handle:handle) {
ResetPack(handle);
new clientID = GetClientOfUserId(ReadPackCell(handle));
new PrimaryWeaponEntity = ReadPackCell(handle);
new PrimaryAmmo = ReadPackCell(handle);
new PrimaryClipSize = ReadPackCell(handle);
new SecondaryWeaponEntity = ReadPackCell(handle);
new SecondaryAmmo = ReadPackCell(handle);
new SecondaryClipSize = ReadPackCell(handle);
if (IsValidClient(clientID) && IsPlayerAlive(clientID)) {