AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   index out of bounds (https://forums.alliedmods.net/showthread.php?t=192826)

DoviuX 08-14-2012 12:52

index out of bounds
 
I have this const:
PHP Code:

new const PRIMARY[ ][ ] = { 
    
"weapon_m4a1",        // Gun ID - 1
    
"weapon_ak47",        // Gun ID - 2
    
"weapon_m3",         // Gun ID - 3
    
"weapon_xm1014",    // Gun ID - 4
    
"weapon_aug",        // Gun ID - 5
    
"weapon_mac10",        // Gun ID - 6
    
"weapon_ump45",        // Gun ID - 7
    
"weapon_mp5navy",    // Gun ID - 8
    
"weapon_p90",        // Gun ID - 9
    
"weapon_galil",        // Gun ID - 10
    
"weapon_famas"        // Gun ID - 11
}; 

and I need that from another const:
PHP Code:

 new const allowed_primary[ ] = { 124567891011 

Would print into menu only those ids which are in const:
PHP Code:

        for( i_prim 0i_prim 8i_prim++ ) {
            
p_id = ( ( _curr_pageid ] * ) + i_prim );
            if( 
p_id _totalguns )
                
len += formatexdata_holderlen ], charsmaxdata_holder ) - len"^n \r%i\d. %s"i_prim 1P_NAMESallowed_primaryp_id ] ] );                
        } 

But I get index out of bounds here:
PHP Code:

P_NAMESallowed_primaryp_id ] ] 

Is there any other way to do this ?

lucas_7_94 08-14-2012 13:31

Re: index out of bounds
 
PRIMARY[][] has 11 weapons , and allowed_primary[] has 10.. check that.

DoviuX 08-14-2012 13:40

Re: index out of bounds
 
I know but I want that if allowed_primary has 10 then in menu shows 10 but primary still leaves 11, what I want to say is if there is guns id in allowed_primary so it will be in the menu.

example:
new const allowed_primary[ ] = { 1, 2, 4, 5, 6, 7, 8, 9, 10, 11 }

meniu:
1. 1 gun ( becouse id 1 )
2. 2 gun ( becouse id 2 )
3. 4 gun ( becouse id 4 )
and etc.

Merciless 08-14-2012 13:45

Re: index out of bounds
 
"weapon_m4a1", // Gun ID - 1

its gun id 0

It starts with 0 not 1

Napoleon_be 08-14-2012 17:25

Re: index out of bounds
 
Quote:

Originally Posted by Merciless (Post 1771372)
"weapon_m4a1", // Gun ID - 1

its gun id 0

It starts with 0 not 1

Not if you set a value to the array

Exolent[jNr] 08-14-2012 17:44

Re: index out of bounds
 
PHP Code:

new const PRIMARY[ ][ ] = { 
    
"weapon_m4a1",        // Gun ID - 1
    
"weapon_ak47",        // Gun ID - 2
    
"weapon_m3",         // Gun ID - 3
    
"weapon_xm1014",    // Gun ID - 4
    
"weapon_aug",        // Gun ID - 5
    
"weapon_mac10",        // Gun ID - 6
    
"weapon_ump45",        // Gun ID - 7
    
"weapon_mp5navy",    // Gun ID - 8
    
"weapon_p90",        // Gun ID - 9
    
"weapon_galil",        // Gun ID - 10
    
"weapon_famas"        // Gun ID - 11
}; 

:arrow:
PHP Code:

new const PRIMARY[ ][ ] = { 
    
""// Gun ID - 0, doesn't exist
    
"weapon_m4a1",        // Gun ID - 1
    
"weapon_ak47",        // Gun ID - 2
    
"weapon_m3",         // Gun ID - 3
    
"weapon_xm1014",    // Gun ID - 4
    
"weapon_aug",        // Gun ID - 5
    
"weapon_mac10",        // Gun ID - 6
    
"weapon_ump45",        // Gun ID - 7
    
"weapon_mp5navy",    // Gun ID - 8
    
"weapon_p90",        // Gun ID - 9
    
"weapon_galil",        // Gun ID - 10
    
"weapon_famas"        // Gun ID - 11
}; 


Merciless 08-14-2012 19:48

Re: index out of bounds
 
Quote:

Originally Posted by Napoleon_be (Post 1771515)
Not if you set a value to the array

Say w00t ?


All times are GMT -4. The time now is 05:45.

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