View Single Post
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 09-11-2021 , 17:35   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
Reply With Quote #2

I don't think a detour is required. SDKHook clients SDKHook_WeaponEquip and SDKHook_WeaponDrop and modify the reserve ammo with the following code.

You could track the entity each time someone equips or drops a weapon and set the ammo value accordingly. For example have g_iAmmo[2048][2] where g_iAmmo[weapon][0] is the EntIndexToEntRef() of the weapon to verify itself is the same weapon, and [1] would be the ammo you read/set when picked up/dropped. That would work for all weapons without issue from what I can think.

PHP Code:
// Plugin start:
g_iOffsetAmmo FindSendPropInfo("CTerrorPlayer""m_iAmmo");
g_iPrimaryAmmoType FindSendPropInfo("CBaseCombatWeapon""m_iPrimaryAmmoType");

// The function
int GetOrSetPlayerAmmo(int clientint iWeaponint iAmmo = -1)
{
    
int offset GetEntData(iWeapong_iPrimaryAmmoType) * 4// Thanks to "Root" or whoever for this method of not hard-coding offsets: https://github.com/zadroot/AmmoManager/blob/master/scripting/ammo_manager.sp

    // Get/Set
    
if( offset )
    {
        if( 
iAmmo != -SetEntData(clientg_iOffsetAmmo offsetiAmmo);
        else return 
GetEntData(clientg_iOffsetAmmo offset);
    }

    return 
0;

__________________
Silvers is offline