AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Run time error 10 (cs_set_weapon_ammo) (https://forums.alliedmods.net/showthread.php?t=307590)

GoldNux 05-16-2018 19:43

[HELP] Run time error 10 (cs_set_weapon_ammo)
 
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!

Bugsy 05-16-2018 19:50

Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
 
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

GoldNux 05-16-2018 19:54

Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
 
Quote:

Originally Posted by Bugsy (Post 2592492)
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.

HamletEagle 05-17-2018 10:25

Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
 
Quote:

Originally Posted by GoldNux (Post 2592493)
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.

CrazY. 05-18-2018 07:52

Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
 
Honestly I have not seen anything informing to ignore this error on the site that Bugsy given to you...

GoldNux 05-18-2018 08:19

Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
 
Quote:

Originally Posted by CrazY. (Post 2592649)
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)
            } 


CrazY. 05-18-2018 14:11

Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
 
That's right.

GoldNux 05-18-2018 14:17

Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
 
Quote:

Originally Posted by CrazY. (Post 2592689)
That's right.

Thanks! :)

Bugsy 05-18-2018 18:17

Re: [HELP] Run time error 10 (cs_set_weapon_ammo)
 
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)
    } 



All times are GMT -4. The time now is 17:02.

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