View Single Post
Author Message
Mixtaz
Junior Member
Join Date: Sep 2017
Old 10-28-2020 , 10:45   Index out of bounds
Reply With Quote #1

Hello, I have encountered a problem, once in an ~hour, it throws an error in errorlog, which goes as follow:

PHP Code:
L 08/11/2020 08:39:03Start of error session.
L 08/11/2020 08:39:03Info (map "zm_kancl3r") (file "addons/amxmodx/logs/error_20200811.log")
L 08/11/2020 08:39:03: [AMXXDisplaying debug trace (plugin "biohazard.amxx"version "1")
L 08/11/2020 08:39:03: [AMXXRun time error 4index out of bounds 
L 08
/11/2020 08:39:03: [AMXX]    [0biohazard.sma::equipweapon (line 1726)
L 08/11/2020 08:39:03: [AMXX]    [1biohazard.sma::action_sec (line 1432)
L 08/11/2020 10:10:25Start of error session.
L 08/11/2020 10:10:25Info (map "zm_infantry") (file "addons/amxmodx/logs/error_20200811.log")
L 08/11/2020 10:10:25: [AMXXDisplaying debug trace (plugin "biohazard.amxx"version "1")
L 08/11/2020 10:10:25: [AMXXRun time error 4index out of bounds 
L 08
/11/2020 10:10:25: [AMXX]    [0biohazard.sma::equipweapon (line 1706)
L 08/11/2020 10:10:25: [AMXX]    [1biohazard.sma::action_prim (line 1414
Since there are 3d arrays and I'm confused just by looking at it, I would request a tip on how to fix this, below I attach needed code:

equipweapon:
PHP Code:
stock equipweapon(idweapon)
{
    if(!
is_user_alive(id)) 
        return
    
    static 
weaponid[2], weaponent
    
    
if(weapon EQUIP_PRI)
    {
        
weaponent fm_lastprimary(id)
        
weaponid[1] = get_weaponid(g_primaryweapons[g_player_weapons[id][0]][1])
        
        if(
pev_valid(weaponent))
        {
            
weaponid[0] = fm_get_weapon_id(weaponent)
            if(
weaponid[0] != weaponid[1])
                
fm_strip_user_gun(idweaponid[0])
        }
        else
            
weaponid[0] = -1
        
        
if(weaponid[0] != weaponid[1])
            
fm_give_item(idg_primaryweapons[g_player_weapons[id][0]][1])
        
        
fm_set_user_bpammo(idweaponid[1], g_weapon_ammo[weaponid[1]])
    }
    
    if(
weapon EQUIP_SEC)
    {
        
weaponent fm_lastsecondry(id)
        
weaponid[1] = get_weaponid(g_secondaryweapons[g_player_weapons[id][1]][1])
        
        if(
pev_valid(weaponent))
        {
            
weaponid[0] = fm_get_weapon_id(weaponent)
            if(
weaponid[0] != weaponid[1])
                
fm_strip_user_gun(idweaponid[0])
        }
        else
            
weaponid[0] = -1
        
        
if(weaponid[0] != weaponid[1])
            
fm_give_item(idg_secondaryweapons[g_player_weapons[id][1]][1])
        
        
fm_set_user_bpammo(idweaponid[1], g_weapon_ammo[weaponid[1]])
    }
    
    if(
weapon EQUIP_GREN)
        
fm_give_item(id"weapon_hegrenade")
    

action_prim:
PHP Code:
public action_prim(idmenuitem)
{
    if(
item == MENU_EXIT)
        
menu_destroy(menu)
    
    if(!
is_user_alive(id) || g_zombie[id])
        return 
PLUGIN_HANDLED

    g_player_weapons
[id][0] = item
    equipweapon
(idEQUIP_PRI)
            
    
display_weaponmenu(idMENU_SECONDARY)
        
    return 
PLUGIN_HANDLED

action_sec:
PHP Code:
public action_sec(idmenuitem)
{
    if(
item == MENU_EXIT)
        
menu_destroy(menu)
    
    if(!
is_user_alive(id) || g_zombie[id])
        return 
PLUGIN_HANDLED
    
    g_menufailsafe
[id] = false

    g_player_weapons
[id][1] = item
    equipweapon
(idEQUIP_SEC)
    
equipweapon(idEQUIP_GREN)

    return 
PLUGIN_HANDLED

and the aforementioned arrays:
PHP Code:
new g_primaryweapons[][][] = 


    { 
"M4A1",     "weapon_m4a1"    },
    { 
"AK47",     "weapon_ak47"    },
    { 
"AWP",      "weapon_awp"     },
    { 
"AUG",      "weapon_aug"     },
    { 
"SG552",    "weapon_sg552"   },
    { 
"Galil",    "weapon_galil"   },
    { 
"Famas",    "weapon_famas"   },
    { 
"MP5 Navy""weapon_mp5navy" },
    { 
"P90",      "weapon_p90"     },
    { 
"M3",       "weapon_m3"      },
    { 
"XM1014",   "weapon_xm1014"  }
    
}
new 
g_secondaryweapons[][][] = 

    { 
"Glock",    "weapon_glock18" },
    { 
"USP",      "weapon_usp"     },
    { 
"Deagle",   "weapon_deagle"  },
    { 
"P228",     "weapon_p228"    },
    { 
"Elite",    "weapon_elite"   
}

new const 
g_weapon_ammo[] = 

    -
152, -190132
    
1100901120100,
    
100909090100120,
    
301202003290120
    
902359090, -1100 

Any ideas? I tried to make the g_weapon_ammo an 2d array and despite lack of errorlogs, server crashed sometime... Thanks for reading, cheers ;d.
Mixtaz is offline