Weird bug in Counter-Strike: Source – Night vision gives ammo
You buy a night vision via the buy menu (or even 'buy nvgs'). After that you get full ammo for your primary and secondary weapon.
Can someone confirm this bug?
8guawong
08-18-2020 14:50
Re: Weird bug in Counter-Strike: Source – Night vision gives ammo
Quote:
Originally Posted by ElooKoN
(Post 2714687)
You buy a night vision via the buy menu (or even 'buy nvgs'). After that you get full ammo for your primary and secondary weapon.
Can someone confirm this bug?
Have you tried it without sourcemod/metamod running?
ElooKoN
08-18-2020 16:32
Re: Weird bug in Counter-Strike: Source – Night vision gives ammo
Yes. Don't you have this bug? It should work on every server.
8guawong
08-19-2020 13:16
Re: Weird bug in Counter-Strike: Source – Night vision gives ammo
Quote:
Originally Posted by ElooKoN
(Post 2714722)
Yes. Don't you have this bug? It should work on every server.
how bout on listen server?
maybe check your key bind?
Bacardi
08-20-2020 08:29
Re: Weird bug in Counter-Strike: Source – Night vision gives ammo
Seems it does buy ammo when purchade nvgs. bug
Happens also when buy kevlar/armor
ElooKoN
08-21-2020 19:32
Re: Weird bug in Counter-Strike: Source – Night vision gives ammo
Quote:
Originally Posted by Bacardi
(Post 2714909)
Seems it does buy ammo when purchade nvgs. bug
Happens also when buy kevlar/armor
You're right, I tested it. That is very unfavorable, I wonder why nobody noticed this bug before.
Any way to fix this using a custom game patch? Otherwise the only solution would be to store/restore the values before/after buying I think.
Bacardi
08-22-2020 08:53
Re: Weird bug in Counter-Strike: Source – Night vision gives ammo
Was looking... source code.
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();
Re: Weird bug in Counter-Strike: Source – Night vision gives ammo
Thanks so much!
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)) {