Raised This Month: $51 Target: $400
 12% 

Solved cs_get_weapon_ammo returning "Non-player entity"


Post New Thread Reply   
 
Thread Tools Display Modes
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
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 08-07-2021 , 02:35   Re: cs_get_weapon_ammo returning "Non-player entity"
Reply With Quote #2

Code:
stock weapon_details(id) {     wpnid = get_user_weapon(id, magazine, ammo);     return wpnid, magazine, ammo; }
__________________

Last edited by DJEarthQuake; 08-07-2021 at 09:43. Reason: Pasted wrong help!
DJEarthQuake is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-07-2021 , 03:14   Re: cs_get_weapon_ammo returning "Non-player entity"
Reply With Quote #3

No, it shouldn't. Pass the weapon ENTITY index. CHECK_NONPLAYER checks to make sure the entity you passed is not a player. The error message is correct, you passed id = 1 whicb is a player id and the native does not want that.

Based on "eventid" you know for which weapon the forward was triggered(you can deduce the CSW_* index). With the csw index you can retrieve the weapon entity index.

Also, what is "iPlayer"? In the forward header you have "id".
__________________

Last edited by HamletEagle; 08-07-2021 at 03:16.
HamletEagle is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-07-2021 , 03:26   Re: cs_get_weapon_ammo returning "Non-player entity"
Reply With Quote #4

Thank you!
I will try what Hamlet said.

And about this
Quote:
Originally Posted by HamletEagle View Post
Also, what is "iPlayer"? In the forward header you have "id".
Changed the code

Solved passing the Weapon Entity index retrieved from player's pdata:
PHP Code:
    static wID 
    wID 
get_pdata_cbase(iPlayer373XO_PLAYER)

    
iClip cs_get_weapon_ammo(wID); 
__________________


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. Reason: Solved
Shadows Adi is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 08-07-2021 , 09:42   Re: cs_get_weapon_ammo returning "Non-player entity"
Reply With Quote #5

I wasn't paying careful enough attention. Thought you needed stronger filter. That just made matters worse! Added more relevant code. A stock I use to get ammo from player's index.
__________________
DJEarthQuake is offline
Reply



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 19:18.


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