AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Non-player entity -1 out of range (https://forums.alliedmods.net/showthread.php?t=187772)

KamiN 06-17-2012 16:23

Non-player entity -1 out of range
 
Code:

public sub_choose_enemy(id, menu, item)
{
    if( item == MENU_EXIT )
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
   
    new Data[6], Name[64]
    new Access, Callback
    menu_item_getinfo(menu, item, Access, Data,5, Name, 63, Callback)
   
    new tempid = str_to_num(Data)
   
    new mapname[32], challenger[32], challenged[32], ct_origin[3], te_origin[3]

    get_mapname(mapname,31)
    get_user_name(id, challenger, 31)
    get_user_name(tempid, challenged, 31)
   
    // strip weapons
    strip_user_weapons(id)
    strip_user_weapons(tempid)
   
    // health
    set_user_health(id, 100)
    set_user_health(tempid, 100)
   
    // effects
    switch (get_pcvar_num(cvar_effect))
    {
        case 0: // glow
        {
            set_user_rendering(id, kRenderFxGlowShell, 250, 0, 0, kRenderNormal, 20)   
            set_user_rendering(tempid, kRenderFxGlowShell, 0, 0, 250, kRenderNormal, 20)
        }
        case 1: // beacon
        {
            set_task(1.0, "beacon", id)
            set_task(1.0, "beacon", tempid)
        }
        case 2: // glow n' beacon
        {
            set_user_rendering(id, kRenderFxGlowShell, 250, 0, 0, kRenderNormal, 20)   
            set_task(1.0, "beacon", id)
            set_user_rendering(tempid, kRenderFxGlowShell, 0, 0, 250, kRenderNormal, 20)
            set_task(1.0, "beacon", tempid)
        }
    }
   
    // player challenged
    player_challenged[tempid] = true
   
    // lr menu once until he kills the player challenged
    once[id] = true
   
    // unable pick up weapon (only the 2 players on duel)
    touch_weapons[id] = true
    touch_weapons[tempid] = true
           
    if(m3_duel[id])
    {
        give_item(id, "weapon_m3")
        give_item(tempid, "weapon_m3")
               
        if(equali(mapname,"some1s_jailbreak"))
        {
            ct_origin[0] = -759, ct_origin[1] = 1047, ct_origin[2] = 100
            te_origin[0] = -585, te_origin[1] = 867, te_origin[2] = 100
            set_user_origin(id,te_origin)
            set_user_origin(tempid,ct_origin)
        }
       
        set_hudmessage( 0, 255, 0, -1.0, 0.40, 2, 5.0, 8.0, 0.0, 0.0, 10)
        show_hudmessage(0, "%L",LANG_PLAYER,"POMPA_DUEL", challenger, challenged)
       
    }
    else if(deagle_duel[id])
    {
        deagle_duel[tempid] = true
       
        cs_set_weapon_ammo(give_item(id, "weapon_deagle"), 1)
        cs_set_weapon_ammo(give_item(tempid, "weapon_deagle"), 1)
       
        if(equali(mapname,"some1s_jailbreak"))
        {
            ct_origin[0] = -1352, ct_origin[1] = 271, ct_origin[2] = 38
            te_origin[0] = -1338, te_origin[1] = -782, te_origin[2] = 38
            set_user_origin(id,te_origin)
            set_user_origin(tempid,ct_origin)
        }
       
        set_hudmessage( 0, 255, 0, -1.0, 0.40, 2, 5.0, 8.0, 0.0, 0.0, 10)
        show_hudmessage(0, "%L", LANG_PLAYER,"DEAGLE_DUEL", challenger, challenged)
    }
    else if(ump_duel[id])
    {
        give_item(id, "weapon_ump45")
        give_item(tempid, "weapon_ump45")
        cs_set_user_bpammo(id, CSW_UMP45, 60)       
        cs_set_user_bpammo(tempid, CSW_UMP45, 60)
       
        if(equali(mapname,"some1s_jailbreak"))
        {
            ct_origin[0] = -1756, ct_origin[1] = -2526, ct_origin[2] = 36
            te_origin[0] = -3020, te_origin[1] = -2529, te_origin[2] = 36
            set_user_origin(id,te_origin)
            set_user_origin(tempid,ct_origin)
        }
       
        set_hudmessage( 0, 255, 0, -1.0, 0.40, 2, 5.0, 8.0, 0.0, 0.0, 10)
        show_hudmessage(0, "%L", LANG_PLAYER,"UMP_DUEL", challenger, challenged)
    }
    else if(scout_duel[id])
    {
        give_item(id, "weapon_scout")
        give_item(tempid, "weapon_scout")
        cs_set_user_bpammo(id, CSW_SCOUT, get_pcvar_num(cvar_scout_bpammo))
        cs_set_user_bpammo(tempid, CSW_SCOUT, get_pcvar_num(cvar_scout_bpammo))
       
        if(equali(mapname,"some1s_jailbreak"))
        {
            ct_origin[0] = -2898, ct_origin[1] = -2040, ct_origin[2] = 37
            te_origin[0] = -2908, te_origin[1] = 905, te_origin[2] = 37
            set_user_origin(id,te_origin)
            set_user_origin(tempid,ct_origin)
        }
       
        set_hudmessage( 0, 255, 0, -1.0, 0.40, 2, 5.0, 8.0, 0.0, 0.0, 10)
        show_hudmessage(0, "%L", LANG_PLAYER,"SCOUT_DUEL", challenger, challenged)
    }
   
    duel_active = true
   
    menu_destroy(menu)
    return PLUGIN_HANDLED
}

Code:

L 06/17/2012 - 15:00:19: [CSTRIKE] Non-player entity -1 out of range
L 06/17/2012 - 15:00:19: [AMXX] Displaying debug trace (plugin "jb_days_lr.amxx")
L 06/17/2012 - 15:00:19: [AMXX] Run time error 10: native error (native "cs_set_weapon_ammo")
L 06/17/2012 - 15:00:19: [AMXX]    [0] jb_days_lr.sma::sub_choose_enemy (line 646)

646 line is this one
Code:

        cs_set_weapon_ammo(give_item(id, "weapon_deagle"), 1)

Whats wrong in here?

Backstabnoob 06-17-2012 17:03

Re: Non-player entity -1 out of range
 
check if is_user_connected()

Bugsy 06-17-2012 20:05

Re: Non-player entity -1 out of range
 
I would do is_user_alive() which will confirm valid player and do alive check.

Exolent[jNr] 06-17-2012 20:51

Re: Non-player entity -1 out of range
 
The error is that the entity is not created. It has nothing to do whether the player is valid or not.

Code:
new weaponEnt = give_item(id, "weapon_deagle") if(weaponEnt > 0) {     cs_set_weapon_ammo(weaponEnt, 1) }

KamiN 06-18-2012 09:45

Re: Non-player entity -1 out of range
 
Quote:

Originally Posted by Exolent[jNr] (Post 1730853)
The error is that the entity is not created. It has nothing to do whether the player is valid or not.

Code:
new weaponEnt = give_item(id, "weapon_deagle") if(weaponEnt > 0) { cs_set_weapon_ammo(weaponEnt, 1) }

Shouldnt i do same with tempid? Something like that?

Code:

new weaponEnt = give_item(id, "weapon_deagle")
new weaponEntTemp = give_item(tempid, "weapon_deagle)
if(weaponEnt > 0) {
      cs_set_weapon_ammo(weaponEnt, 1)
}
if(weaponEntTemp > 0) {
      cs_set_weapon_ammo(weaponEntTemp, 1)
}


Exolent[jNr] 06-18-2012 10:24

Re: Non-player entity -1 out of range
 
Quote:

Originally Posted by KamiN (Post 1731082)
Shouldnt i do same with tempid? Something like that?

Code:

new weaponEnt = give_item(id, "weapon_deagle")
new weaponEntTemp = give_item(tempid, "weapon_deagle)
if(weaponEnt > 0) {
      cs_set_weapon_ammo(weaponEnt, 1)
}
if(weaponEntTemp > 0) {
      cs_set_weapon_ammo(weaponEntTemp, 1)
}


Yes.

KamiN 06-18-2012 11:22

Re: Non-player entity -1 out of range
 
By the way, could you simply tell me what does that "new tempid = str_to_num(Data)" do?

Do i get it right in this situation, when i use ID so i make changes to player with have opened the menu and when i use TEMPID then i make changes to that player with the openner chosen? That why it's nessesery to use same commads with ID and TEMPID?

fysiks 06-18-2012 19:03

Re: Non-player entity -1 out of range
 
Quote:

Originally Posted by KamiN (Post 1731123)
By the way, could you simply tell me what does that "new tempid = str_to_num(Data)" do?

str_to_num() changes a string to a number.

Quote:

Originally Posted by KamiN (Post 1731123)
Do i get it right in this situation, when i use ID so i make changes to player with have opened the menu and when i use TEMPID then i make changes to that player with the openner chosen? That why it's nessesery to use same commads with ID and TEMPID?

Yes. The first argument of a menu handler function is always the entity index of the player who selected the item. In this case (but not all) tempid is retrieved from the menu item which was chosen and is the entity index of that chosen player (in this case).


All times are GMT -4. The time now is 06:19.

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