[Help] Run time error 4: "Array index out of bounds"
#1

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;
				}
			}
Reply
#2

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
Reply
#3

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

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

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.
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)