s1lentq / reapi

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

[Question] Setting custom ammo for weapon with rg_add_ammo_registry #299

Closed aleeperezz16 closed 8 months ago

aleeperezz16 commented 8 months ago

Hey. I'm trying to make every weapon to have it's own ammo without sharing between ammotypes. I have few weapons for this so i'm in MAX_AMMO_SLOTS's range. The problem is that BPAmmo in hud is not getting updated, it's always stuck at 0. I followed de API doc and did this:

new const PrimaryWeapons[][] =
{
    "weapon_tmp", "weapon_mac10", "weapon_m3", "weapon_xm1014", "weapon_ump45", "weapon_p90", "weapon_scout", "weapon_m249", "weapon_mp5navy"
};

new const SecondaryWeapons[][] = 
{
    "weapon_glock18", "weapon_p228", "weapon_fiveseven", "weapon_elite", "weapon_deagle"
};

public plugin_precache()
{
    g_MsgWeaponList = get_user_msgid("WeaponList");
    g_MsgWeaponListId = register_message(g_MsgWeaponList, "Message_WeaponList");
}

public plugin_init() 
{
    unregister_message(g_MsgWeaponList, g_MsgWeaponListId);
}

public Message_WeaponList(id, dest, entity)
{
    new weaponName[20];
    get_msg_arg_string(1, weaponName, charsmax(weaponName));

    for (new i = 0; i < sizeof(PrimaryWeapons); i++)
    {
        if (!strcmp(PrimaryWeapons[i][7], weaponName[7]))
        {
            rg_set_global_iteminfo(rg_get_weapon_info(weaponName, WI_ID), ItemInfo_pszAmmo1, weaponName[7]);
            set_msg_arg_int(2, ARG_BYTE, rg_add_ammo_registry(weaponName[7]));
        }
    }

    for (new i = 0; i < sizeof(SecondaryWeapons); i++)
    {
        if (!strcmp(SecondaryWeapons[i][7], weaponName[7]))
        {
            rg_set_global_iteminfo(rg_get_weapon_info(weaponName, WI_ID), ItemInfo_pszAmmo1, weaponName[7]);
            set_msg_arg_int(2, ARG_BYTE, rg_add_ammo_registry(weaponName[7]));
        }
    }
}

Am i missing something for AmmoX to update the hud number? I already tested hooking this message and the params sent by the message are correct.