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

index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 03-26-2018 , 00:41   index out of bounds
Reply With Quote #1

what is the cause of this error ?

L 03/25/2018 - 15:04:13: [AMXX] Run time error 4: index out of bounds
L 03/25/2018 - 15:04:13: [AMXX] [0] t0wvy22q.sma.p::Knife_Model_Admin (line 924)

This line : if( !equal( VnamesAdmin[ setting[ id ] ], "" ) )

Code:
public Knife_Model_Admin ( id ) 
{
            if ( is_user_alive(id) && get_user_weapon ( id ) == CSW_KNIFE ) 
            {	
	          if( !equal( VnamesAdmin[ setting[ id ] ], "" ) )
		     entity_set_string(id, EV_SZ_viewmodel, VnamesAdmin[ setting[ id ] ]) 
                  if( !equal( Pnames[ setting[ id ] ], "" ) )
	             entity_set_string(id, EV_SZ_weaponmodel, Pnames[ setting[ id ] ]) 
            }
}
Saint Sinner is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 03-26-2018 , 08:27   Re: index out of bounds
Reply With Quote #2

We will have to see more of your code in case you wanna be helped properly
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
hellmonja
Senior Member
Join Date: Oct 2015
Old 03-26-2018 , 08:49   Re: index out of bounds
Reply With Quote #3

Perhaps if added a check for 'id'?...
PHP Code:
if(id 32)
     return 
__________________
hellmonja is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-26-2018 , 08:54   Re: index out of bounds
Reply With Quote #4

Quote:
Originally Posted by hellmonja View Post
Perhaps if added a check for 'id'?...
PHP Code:
if(id 32)
     return 
is_user_alive() already checks that.
__________________

Last edited by OciXCrom; 03-26-2018 at 08:54.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
hellmonja
Senior Member
Join Date: Oct 2015
Old 03-26-2018 , 09:01   Re: index out of bounds
Reply With Quote #5

Quote:
Originally Posted by OciXCrom View Post
is_user_alive() already checks that.
Yeah good point. The error would've been directed to that. Then it's the setting[] variable that's having a problem. Perhaps you didn't add +1 to it?...
__________________
hellmonja is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 03-26-2018 , 09:47   Re: index out of bounds
Reply With Quote #6

If i change setting to [22] still have errors

Code:
new setting[ 33 ];

new const VnamesAdmin[ ][ ] = 
{	
        "models/knife_darkelite/v_purple.mdl",
	"models/knife_darkelite/v_gold.mdl",
	"models/knife_darkelite/v_knife_assasins.mdl", 
	"models/knife_darkelite/v_butterfly.mdl",
	"models/knife_darkelite/v_dualknife.mdl",
	"models/knife_darkelite/v_karambit.mdl",
	"models/knife_darkelite/v_tattos.mdl",
	"models/knife_darkelite/v_kaf_axe2.mdl",
	"models/knife_darkelite/v_addidass.mdl",
	"models/knife_darkelite/v_dualkatana.mdl",
	"models/knife_darkelite/v_dragon_knife.mdl",
	"models/knife_darkelite/v_daedric.mdl",
	"models/knife_darkelite/v_transparent.mdl",
	"models/knife_darkelite/v_heineken.mdl",
	"models/knife_darkelite/v_aqua.mdl",
	"models/knife_darkelite/v_moartea.mdl",
	"models/knife_darkelite/m9_laminet.mdl",
	"models/knife_darkelite/v_knife_doppler.mdl",
	"models/knife_darkelite/v_axe_blood_new.mdl",
	"models/knife_darkelite/v_knife_hammer.mdl",
	"models/knife_darkelite/v_S1Nn3R.mdl",
	"models/knife_darkelite/v_kiss.mdl"
};

Last edited by Saint Sinner; 03-26-2018 at 09:53.
Saint Sinner is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 03-26-2018 , 11:05   Re: index out of bounds
Reply With Quote #7

Quote:
Originally Posted by Saint Sinner View Post
If i change setting to [22] still have errors
But how are you calling these settings? Remember, the first item on the array is numbered '0'. If there are 22 items, then the very last one is numbered '21'. It might be you're calling for item #22 when it doesn't exist.

Either way, the full code would definitely help solve this...

PS:
PHP Code:
"models/knife_darkelite/v_kiss.mdl" 
Is that supposed to be a Kriss Vector, or is player gonna kiss someone. Kek!...
__________________

Last edited by hellmonja; 03-26-2018 at 11:07.
hellmonja is offline
marcelowzd
Senior Member
Join Date: Feb 2011
Location: São Paulo, Brazil
Old 03-27-2018 , 11:28   Re: index out of bounds
Reply With Quote #8

According to your code, setting must be 33 and it probably holds a value between 0 and 21 for each player.

So, if this value is higher than 21 or lower than 0 you'll get this error.

Also, why do you do this?
if( !equal( VnamesAdmin[ setting[ id ] ], "" ) )

I don't know if you change setting[ id ] on ClientConnect or PutInServer but if you do it also could cause the error( if the value is -1 )

This would be better in this case
entity_set_string(id, EV_SZ_viewmodel, setting[ id ] >= 0 ? VnamesAdmin[ setting[ id ] ] : "models/v_knife.mdl");

You need to provide more code, as people already suggested

Last edited by marcelowzd; 03-27-2018 at 11:34.
marcelowzd is offline
Reply



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 21:00.


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