Raised This Month: $ Target: $400
 0% 

Solved cs_get_weapon_ammo returning "Non-player entity"


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-07-2021 , 01:31   cs_get_weapon_ammo returning "Non-player entity"
Reply With Quote #1

Hello,
Today I tried out to retrieve player's weapon ammo inside FM_PlaybackEvent but every time I ran into this error:
PHP Code:
[CSTRIKENon-player entity 1 out of range 
Code:
PHP Code:
public fw_PlaybackEvent(flagsiPlayereventidFloat:delayFloat:origin[3], Float:angles[3], Float:fparam1Float:fparam2iParam1iParam2bParam1bParam2)
{
    if(!
is_user_connected(iPlayer) || !pev_valid(iPlayer))
        return;

    
server_print("Entities: %d/%d"entity_count(), global_get(glb_maxEntities))
    static 
iClip;

    
iClip cs_get_weapon_ammo(iPlayer);

http://www.amxmodx.org/api/cstrike/cs_get_weapon_ammo

PHP Code:
index    
Weapon entity index 
In API docs it's specified that the index should be a weapon entity, but after looking in the core code I saw that is not right; Index param should be player's index:
PHP Code:
// native cs_get_weapon_ammo(index);
static cell AMX_NATIVE_CALL cs_get_weapon_ammo(AMX *amxcell *params)
{
    
GET_OFFSET("CBasePlayerWeapon"m_iClip);

    
int index params[1];

    
CHECK_NONPLAYER(index);
    
edict_t *pWeapon TypeConversion.id_to_edict(index);

    return 
get_pdata<int>(pWeaponm_iClip);
}

#define CHECK_NONPLAYER(x) \
    
if (|| <= gpGlobals->maxClients || gpGlobals->maxEntities) { \
        
MF_LogError(amxAMX_ERR_NATIVE"Non-player entity %d out of range"x); \
        return 
0; \
    } else { \
        if (
FNullEnt(TypeConversion.id_to_edict(x))) { \
            
MF_LogError(amxAMX_ERR_NATIVE"Invalid non-player entity %d"x); \
            return 
0; \
        } \
    } 
It said that "Non-player entity 1 out of range" which is not right at all because player is connected to server and it can't exceed MaxEntities according to my debugging:
PHP Code:
server_print("Entities: %d/%d"entity_count(), global_get(glb_maxEntities))

OutputEntities126/1365 
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 08-07-2021 at 03:38.
Shadows Adi is offline
 


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 02:32.


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