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

Index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
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
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-28-2020 , 21:36   Re: Index out of bounds
Reply With Quote #2

Check what you have written on line 1706
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Mixtaz
Junior Member
Join Date: Sep 2017
Old 10-29-2020 , 08:12   Re: Index out of bounds
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
Check what you have written on line 1706
PHP Code:
10:10:25: [AMXX]    [0biohazard.sma::equipweapon (line 1706
PHP Code:
weaponid[1] = get_weaponid(g_primaryweapons[g_player_weapons[id][0]][1]) 
whereas action_prim, and action_sec refers to it by either equipweapon(id, EQUIP_PRI || EQUIP_SEC)

so the problem lies within the stock, but I can't tell what should be changed there in order for it to work normally
Mixtaz is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-29-2020 , 08:42   Re: Index out of bounds
Reply With Quote #4

the problem is in what g_player_weapons[id][0] contains or equal to. make sure its a valid cell index.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 11:58.


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