s1lentq / reapi

AMX Mod X module, using API regamedll & rehlds
GNU General Public License v3.0
161 stars 103 forks source link

m_rgAmmo on ItemPostFrame #51

Closed ivanmaxlogiudice closed 7 years ago

ivanmaxlogiudice commented 7 years ago

I can't get the m_rgAmmo from the player on ItemPostFrame, i get all 0 with it.

Plugin to test

#include <amxmodx>
#include <reapi>
#include <hamsandwich>

#define MAX_CLIP 10

public plugin_init()
{
    for (new WeaponIdType: iWeaponID = WEAPON_P228, szEntity[32]; iWeaponID <= WEAPON_P90; iWeaponID++)
    {
        /* Ignore invalid weapons */
        if (iWeaponID == WEAPON_GLOCK || iWeaponID == WEAPON_C4) 
            continue;

        /* Get the weapon ent class */
        rg_get_weapon_info(iWeaponID, WI_NAME, szEntity, charsmax(szEntity));

        /* Hook the weapon deploy */
        RegisterHam(Ham_Item_PostFrame, szEntity, "fw_WeaponPostFrame");
    }
}

public fw_WeaponPostFrame( const iEntityID )
{
    /* Invalid entity? */
    if (is_nullent(iEntityID))
        return HAM_IGNORED;

    /* Get the player */
    new iPlayerID = get_member(iEntityID, m_pPlayer);

    /* Weapon end reloading? */
    if (get_member(iEntityID, m_Weapon_fInReload) && get_member(iPlayerID, m_flNextAttack) <= get_gametime())
    {
        /* Get weapon data */
        new iClip, iAmmoType;
        iClip     = get_member(iEntityID, m_Weapon_iClip);
        iAmmoType = get_member(iEntityID, m_Weapon_iPrimaryAmmoType);

        /* Get player rgAmmo */
        new rgAmmo[32];
        get_member(iPlayerID, m_rgAmmo, rgAmmo);

        /* Print rgAmmo to the player console */
        for (new iIndex = 0; iIndex < 32; iIndex++)
        {
            console_print(iPlayerID, "rgAmmo[ %d ]: %d", iIndex, rgAmmo[ iIndex ]);
        }

        /* Complete the reload */
        new iAdd = min(MAX_CLIP - iClip, rgAmmo[ iAmmoType ]);
        client_print_color(iPlayerID, iPlayerID, "iEntityID: %d | iClip: %d | iAmmoType: %d | iAmmo: %d - %d | iAdd: %d", iEntityID, iClip, iAmmoType, rgAmmo[ iAmmoType ], rg_get_user_bpammo(iPlayerID, get_member(iEntityID, m_iId)), iAdd);
        /* Add them to the clip */
        set_member(iEntityID, m_Weapon_iClip, iClip + iAdd);

        /* Update the player ammo */
        set_member(iPlayerID,  m_rgAmmo, (rgAmmo[ iAmmoType ] - iAdd), iAmmoType);

        set_member(iEntityID, m_Weapon_fInReload, false);
        return HAM_SUPERCEDE;
    }

    return HAM_IGNORED;
}

Output:

rgAmmo[ 0 ]: 0
rgAmmo[ 1 ]: 0
rgAmmo[ 2 ]: 0
rgAmmo[ 3 ]: 0
rgAmmo[ 4 ]: 0
rgAmmo[ 5 ]: 0
rgAmmo[ 6 ]: 0
rgAmmo[ 7 ]: 0
rgAmmo[ 8 ]: 0
rgAmmo[ 9 ]: 0
rgAmmo[ 10 ]: 0
rgAmmo[ 11 ]: 0
rgAmmo[ 12 ]: 0
rgAmmo[ 13 ]: 0
rgAmmo[ 14 ]: 0
rgAmmo[ 15 ]: 0
rgAmmo[ 16 ]: 0
rgAmmo[ 17 ]: 0
rgAmmo[ 18 ]: 0
rgAmmo[ 19 ]: 0
rgAmmo[ 20 ]: 0
rgAmmo[ 21 ]: 0
rgAmmo[ 22 ]: 0
rgAmmo[ 23 ]: 0
rgAmmo[ 24 ]: 0
rgAmmo[ 25 ]: 0
rgAmmo[ 26 ]: 0
rgAmmo[ 27 ]: 0
rgAmmo[ 28 ]: 0
rgAmmo[ 29 ]: 0
rgAmmo[ 30 ]: 0
rgAmmo[ 31 ]: 0
iEntityID: 108 | iClip: 15 | iAmmoType: 10 | iAmmo: 0 - 40 | iAdd: -5
ghost commented 7 years ago
        new iAmmoID = ExecuteHam(Ham_Item_PrimaryAmmoIndex, pWeapon) 
        // or
        // new iAmmoID = rg_get_weapon_info(get_member(pWeapon, m_iId), WI_AMMO_TYPE)

        new iCount = get_member(pPlayer, m_rgAmmo, iAmmoID)
        server_print("iCount %i", iCount)
ghost commented 7 years ago
        for (new iIndex = 0; iIndex < 32; iIndex++)
        {
            console_print(iPlayerID, "rgAmmo[ %d ]: %d", iIndex, rgAmmo[ iIndex ]);
        }

wtf?

theAsmodai commented 7 years ago

new a = get_member(iPlayerID, m_rgAmmo, WEAPON_P228)

WPMGPRoSToTeMa commented 7 years ago

new ammo = get_member(iPlayerID, m_rgAmmo, iAmmoType);

ivanmaxlogiudice commented 7 years ago

My bad, i think i get rgAmmo[ 32 ] with it ✌️