SA-MP Forums Archive
[Help] Run time error 4: "Array index out of bounds" - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Help] Run time error 4: "Array index out of bounds" (/showthread.php?tid=524784)



[Help] Run time error 4: "Array index out of bounds" - David (Sabljak) - 08.07.2014

Hello, i have Anti Weapon Hack running on 4 sec...

but sometimes

Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 63 past array upper bound 46
[debug] AMX backtrace:
[debug] #0 004c81d4 in public SaboAC ()
Код:
if(GetPlayerWeapon(i) != 0 && !AntiCheatWeapon[i][GetPlayerWeapon(i)]) //This Line
	    	{
	    		if(GetPlayerWeapon(i) == 46 || GetPlayerWeapon(i) == 40 || GetPlayerWeapon(i) >= 1 && GetPlayerWeapon(i) <= 15)
				{
					//Nothing happened, ignores parachute and other things
				}
				else
				{
					//sends message and resetting weapons
					return 1;
				}
			}



Re: [Help] Run time error 4: "Array index out of bounds" - BroZeus - 08.07.2014

it is usually cazed due to the array size is samller than its being used
here i will give an example when this error is cazed
pawn Код:
new array[5];
array[0] = 4;
array[3] = 7;
array[8]= 5;//the error will be on this line caz aarry size is smaller than being used here
the array size of "new array[5];" will range from 0 to (5-1) that is 0 to 4


Re: [Help] Run time error 4: "Array index out of bounds" - David (Sabljak) - 08.07.2014

i have
Код:
new AntiCheatWeapon[MAX_PLAYERS][47];
when resseting
Код:
for(new i = 0; i < 47; i ++)
    {
    	AntiCheatOruzja[playerid][i] = 0;
    }
I'm confused


Re: [Help] Run time error 4: "Array index out of bounds" - BroZeus - 08.07.2014

https://sampwiki.blast.hk/wiki/Weapons
from this isaw the id can reach upto 201
try this
new AntiCheatWeapon[MAX_PLAYERS][202];


Re: [Help] Run time error 4: "Array index out of bounds" - Vince - 08.07.2014

Useless. Under normal circumstances only values up to 46 are sent by clients. A value of 63 might be caused by a cheater purposely sending false information, or by an unintentionally malformed packet. It's easier to verify that the weapon is valid before using it as an array index.
pawn Код:
new weapon = GetPlayerWeapon(i);
if(0 <= weapon <= 46)
{
    // your code
}
@OP: it is better to assign the output of a native function to a variable once, rather than calling a native function (GetPlayerWeapon) repeatedly.


Re: [Help] Run time error 4: "Array index out of bounds" - David (Sabljak) - 08.07.2014

Quote:
Originally Posted by Vince
Посмотреть сообщение
Useless. Under normal circumstances only values up to 46 are sent by clients. A value of 63 might be caused by a cheater purposely sending false information, or by an unintentionally malformed packet. It's easier to verify that the weapon is valid before using it as an array index.
pawn Код:
new weapon = GetPlayerWeapon(i);
if(0 <= weapon <= 46)
{
    // your code
}
@OP: it is better to assign the output of a native function to a variable once, rather than calling a native function (GetPlayerWeapon) repeatedly.
Thanks, got it