Raised This Month: $ Target: $400
 0% 

Weird bug in Counter-Strike: Source Night vision gives ammo


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ElooKoN
        ^_^
Join Date: Apr 2011
Old 08-18-2020 , 10:40   Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #1

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?

Last edited by ElooKoN; 08-18-2020 at 10:41.
ElooKoN is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-18-2020 , 14:50   Re: Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #2

Quote:
Originally Posted by ElooKoN View Post
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?
__________________
8guawong is offline
ElooKoN
        ^_^
Join Date: Apr 2011
Old 08-18-2020 , 16:32   Re: Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #3

Yes. Don't you have this bug? It should work on every server.
ElooKoN is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 08-19-2020 , 13:16   Re: Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #4

Quote:
Originally Posted by ElooKoN View Post
Yes. Don't you have this bug? It should work on every server.
how bout on listen server?
maybe check your key bind?
__________________

Last edited by 8guawong; 08-19-2020 at 13:16.
8guawong is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-20-2020 , 08:29   Re: Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #5

Seems it does buy ammo when purchade nvgs. bug
Happens also when buy kevlar/armor

Last edited by Bacardi; 08-20-2020 at 08:55.
Bacardi is offline
ElooKoN
        ^_^
Join Date: Apr 2011
Old 08-21-2020 , 19:32   Re: Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #6

Quote:
Originally Posted by Bacardi View Post
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.

Last edited by ElooKoN; 08-21-2020 at 19:34.
ElooKoN is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-22-2020 , 08:53   Re: Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #7

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 *pszNameint 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).
not perfect
__________________
Do not Private Message @me

Last edited by Bacardi; 08-22-2020 at 08:55.
Bacardi is offline
ElooKoN
        ^_^
Join Date: Apr 2011
Old 08-22-2020 , 09:27   Re: Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #8

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(clientID0);
            new 
PrimaryWeaponEntityRef = -1;
            
            new 
SecondaryWeaponEntity GetPlayerWeaponSlot(clientID1);
            new 
SecondaryWeaponEntityRef = -1;
            
            if (
PrimaryWeaponEntity > -1) {
                
PrimaryWeaponEntityRef EntIndexToEntRef(PrimaryWeaponEntity);
                
PrimaryAmmo GetAmmo(clientID0);
                
PrimaryClipSize GetClipSize(PrimaryWeaponEntity);
            }
            
            if (
SecondaryWeaponEntity > -1) {
                
SecondaryWeaponEntityRef EntIndexToEntRef(SecondaryWeaponEntity);
                
SecondaryAmmo GetAmmo(clientID1);
                
SecondaryClipSize GetClipSize(SecondaryWeaponEntity);
            }
            
            
/**
            *    Cache information
            */
            
new Handle:handle CreateDataPack();
            
            
WritePackCell(handleGetClientUserId(clientID));
            
WritePackCell(handlePrimaryWeaponEntityRef);
            
WritePackCell(handlePrimaryAmmo);
            
WritePackCell(handlePrimaryClipSize);
            
WritePackCell(handleSecondaryWeaponEntityRef);
            
WritePackCell(handleSecondaryAmmo);
            
WritePackCell(handleSecondaryClipSize);

            
/**
            *    Restore in the next frame, otherwise this will have no effect
            */
            
RequestFrame(GameBugFix_RestoreClientAmmoAndClipSizehandle);
            
        }
        
    }
    
}

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)) {
        
        
/**
        *    Primary
        */
        
if (PrimaryWeaponEntity != -1) {
            
PrimaryWeaponEntity EntRefToEntIndex(PrimaryWeaponEntity);
            
            if (
IsValidEntity(PrimaryWeaponEntity)) {
                
SetPlayerAmmoForWeaponEntity(clientIDPrimaryWeaponEntityPrimaryAmmo);
                
SetClipSize(PrimaryWeaponEntityPrimaryClipSize);
            }
        }
    
        
/**
        *    Secondary
        */    
        
if (SecondaryWeaponEntity != -1) {
            
SecondaryWeaponEntity EntRefToEntIndex(SecondaryWeaponEntity);
    
            if (
IsValidEntity(SecondaryWeaponEntity)) {
                
SetPlayerAmmoForWeaponEntity(clientIDSecondaryWeaponEntitySecondaryAmmo);
                
SetClipSize(SecondaryWeaponEntitySecondaryClipSize);
            }
        }
        
    }
    
    
CloseHandle(handle);
    
}

stock bool:IsValidClient(const clientID) {

    if (!
IsValidClientID(clientID)) {
        return 
false;
    }
    
    if (!
IsClientInGame(clientID)) {
        return 
false;
    }

    return 
true;
    
}

stock GetAmmo(const clientID, const slot) {
    new 
weapon GetPlayerWeaponSlot(clientIDslot);
    
    if (
IsValidEntity(weapon)) {
        new 
offset GetEntProp(weaponProp_Send"m_iPrimaryAmmoType"1) * 4;
        return 
GetEntData(clientIDOffset_m_iAmmo offset);
    }
    
    return -
1;
}

stock SetPlayerAmmoForWeaponEntity(const clientID, const entity, const amount) {
    new 
offset GetEntProp(entityProp_Send"m_iPrimaryAmmoType"1) * 4;
    
    
SetEntData(clientIDOffset_m_iAmmo offsetamount4true);
}

stock GetClipSize(const entity) {
    return 
GetEntProp(entityProp_Send"m_iClip1");
}

stock SetClipSize(const entity, const amount) {
    
SetEntProp(entityProp_Send"m_iClip1"amount);

ElooKoN is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-22-2020 , 09:58   Re: Weird bug in Counter-Strike: Source Night vision gives ammo
Reply With Quote #9

yes, entity ref ID is safer because of my delayed timer.
Bacardi is offline
Reply


Thread Tools
Display Modes

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 19:12.


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