Raised This Month: $32 Target: $400
 8% 

[HELP] Run time error 10 (cs_set_weapon_ammo)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GoldNux
Senior Member
Join Date: Mar 2018
Old 05-16-2018 , 19:43   [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #1

Quote:
[CSTRIKE] Non-player entity 0 out of range
[AMXX] Run time error 10: native error (native "cs_set_weapon_ammo")
[AMXX] [0] gn_retake.sma::playerSpawned (line 127)
Code:
public playerSpawned(id) {     if (cs_get_user_team(id) == CS_TEAM_T)     {         cs_set_weapon_ammo(find_ent_by_owner(-1,"weapon_ak47",id),30)         cs_set_weapon_ammo(find_ent_by_owner(-1,"weapon_glock18",id),20)         cs_set_weapon_ammo(find_ent_by_owner(-1,"weapon_usp",id),12)     } }

This function does what I want it to do but I get this error and I would like to know why.
I'm not sure if the weapon entity index is set incorrectly or if the issue is that noone has a specific weapon.

Thanks!
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 05-16-2018 at 19:52.
GoldNux is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-16-2018 , 19:50   Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #2

http://www.amxmodx.org/api/engine/find_ent_by_owner

Code:
[CSTRIKE] Non-player entity 0 out of range
[AMXX] Run time error 10: native error (native "cs_set_weapon_ammo") [AMXX] [0] gn_retake.sma::playerSpawned (line 127)
Code:
Return
Entity index if an entity was found, 0 otherwise
__________________
Bugsy is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 05-16-2018 , 19:54   Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
http://www.amxmodx.org/api/engine/find_ent_by_owner

Code:
[CSTRIKE] Non-player entity 0 out of range
[AMXX] Run time error 10: native error (native "cs_set_weapon_ammo") [AMXX] [0] gn_retake.sma::playerSpawned (line 127)
Code:
Return
Entity index if an entity was found, 0 otherwise
Ahh I see, so this can be ignored. Thank you sir.
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 05-16-2018 at 19:58.
GoldNux is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-17-2018 , 10:25   Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #4

Quote:
Originally Posted by GoldNux View Post
Ahh I see, so this can be ignored. Thank you sir.
You need to check if this entities exist before doing stuff with them, so no, don't ignore the error, fix the code.
__________________

Last edited by HamletEagle; 05-17-2018 at 10:25.
HamletEagle is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-18-2018 , 07:52   Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #5

Honestly I have not seen anything informing to ignore this error on the site that Bugsy given to you...
__________________








CrazY. is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 05-18-2018 , 08:19   Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #6

Quote:
Originally Posted by CrazY. View Post
Honestly I have not seen anything informing to ignore this error on the site that Bugsy given to you...
Well, I am far from a programmer and just starting out.
My plugin works without any issues, and I simply thought that it would return 0 if it didnt find any weapon entity.
There was not much further explanation, I still don't know how to properly check if an entity exists..

Something like this?

PHP Code:
            new ak47Ent;
            new 
glock18Ent;
            new 
uspEnt;
            
ak47Ent find_ent_by_owner(-1"weapon_ak47"id);
            
glock18Ent find_ent_by_owner(-1"weapon_glock18"id);
            
uspEnt find_ent_by_owner(-1"weapon_usp"id);
            if(
pev_valid(ak47Ent))
            {
                
cs_set_weapon_ammo(find_ent_by_owner(-1,"weapon_ak47",id),30)
            }
            if(
pev_valid(glock18Ent))
            {
                
cs_set_weapon_ammo(find_ent_by_owner(-1,"weapon_glock18",id),20)
            }
            if(
pev_valid(uspEnt))
            {
                
cs_set_weapon_ammo(find_ent_by_owner(-1,"weapon_usp",id),12)
            } 
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 05-18-2018 at 08:34.
GoldNux is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-18-2018 , 14:11   Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #7

That's right.
__________________








CrazY. is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 05-18-2018 , 14:17   Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #8

Quote:
Originally Posted by CrazY. View Post
That's right.
Thanks!
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731
GoldNux is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-18-2018 , 18:17   Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
Reply With Quote #9

You should not call find_ent_by_owner() redundantly like that. You are calling it once and storing the value in a variable, so you should reuse that in cs_set_weapon_ammo().
PHP Code:
    new ak47Ent find_ent_by_owner(-1"weapon_ak47"id);
    new 
glock18Ent find_ent_by_owner(-1"weapon_glock18"id);
    new 
uspEnt find_ent_by_owner(-1"weapon_usp"id);
    
    if(
pev_valid(ak47Ent))
    {
        
cs_set_weapon_ammo(ak47Ent,30)
    }
    if(
pev_valid(glock18Ent))
    {
        
cs_set_weapon_ammo(glock18Ent,20)
    }
    if(
pev_valid(uspEnt))
    {
        
cs_set_weapon_ammo(uspEnt,12)
    } 
__________________
Bugsy is offline
Reply


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 03:01.


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