AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Source Servers (SRCDS) (https://forums.alliedmods.net/forumdisplay.php?f=130)
-   -   Weird bug in Counter-Strike: Source – Night vision gives ammo (https://forums.alliedmods.net/showthread.php?t=326823)

ElooKoN 08-18-2020 10:40

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 *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

ElooKoN 08-22-2020 09:27

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(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);



Bacardi 08-22-2020 09:58

Re: Weird bug in Counter-Strike: Source – Night vision gives ammo
 
yes, entity ref ID is safer because of my delayed timer.


All times are GMT -4. The time now is 03:16.

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