SA-MP Forums Archive
Array index out of bounds -- HELP PLS - 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: Array index out of bounds -- HELP PLS (/showthread.php?tid=663290)



Array index out of bounds -- HELP PLS - PoniStar - 27.01.2019

hi! so, i typed some codes on player death , but some of them will not work ! and i get this lines on samp-server.exe
:
Code:
[13:00:43] [debug] Run time error 4: "Array index out of bounds"
[13:00:43] [debug]  Attempted to read/write array element at index 99 in array of size 16
[13:00:43] [debug] AMX backtrace:
[13:00:43] [debug] #0 000df064 in public FailRob (0, 1) in BlankScript.amx
[13:00:43] [debug] #1 000df330 in public AB_OnPlayerDeath (0, 65535, 255) in BlankScript.amx
[13:00:43] [debug] #2 00035f24 in public OnPlayerDeathWeapons (0, 65535, 255) in BlankScript.amx
[13:00:43] [debug] #3 000319f0 in public ac_OnPlayerDeath (0, 65535, 255) in BlankScript.amx
[13:00:43] [debug] #4 0000d348 in public OnPlayerDeath (0, 65535, 255) in BlankScript.amx
here is onplayerdeath code :

Code:
new Robber[MAX_PLAYERS];
new BankRobber[MAX_PLAYERS];
	public OnPlayerDeath(playerid, killerid, reason)
	{
	    if(Robber[playerid] != 0)
	    {
			Robber[playerid] = 0;
			
		 	if(BankRobber[playerid] == 1)
		    {
		        BankRobber[playerid] = 0;
			FailRob(playerid,1);
		    }
	    }
         return 1;
       }
and the FailRob Public:
Code:
forward FailRob(playerid,robid);

public FailRob(playerid,robid)
{
	if(robid == 1)
	{
		        SendClientMessageToAll(-1,"Test String"); // worked!
				DestroyDynamicCP(RobCps[playerid]); // not worked!
				//
				HideTimer(playerid); // not worked (this stock should hide some textdraws)
	}
    return 1;
}
i tried to use failrob public codes in onplayerdeath to but not worked again and show same errors help me please!


Re: Array index out of bounds -- HELP PLS - PoniStar - 27.01.2019

Code:
new RobCps[MAX_PLAYERS];
and this is the code on starting robbery , set the player checkpoint:
Code:
		new rand = random(sizeof(robberycheckpoints));
		RobCps[playerid] = CreateDynamicCP(robberycheckpoints[rand][0],robberycheckpoints[rand][1],robberycheckpoints[rand][2],robberycheckpoints[rand][3], -1, -1, playerid, -1);
and this :
Code:
new Float: robberycheckpoints[3][4] =
{
	{-751.9777,-131.2435,65.8281, 3.0 }, // 1
	{-548.4982,-181.6734,78.4063, 3.0 }, // 2
	{-520.1964,-544.4396,25.5234, 3.0 }, // 3
};



Re: Array index out of bounds -- HELP PLS - Calisthenics - 27.01.2019

Did you post everything from `FailRob` function because it is incomplete. The function is called with playerid=0 and robid=1 and the only array in your current code is `RobCps`. The index is 0, not 99 that crashdetect reported.


Re: Array index out of bounds -- HELP PLS - PoniStar - 27.01.2019

Full code:
Code:
public FailRob(playerid,robid)
{
	if(robid == 1)
	{
				new Float:X, Float:Y, Float:Z , string[300];
				GetPlayerPos(playerid,X,Y,Z);
				mbag = CreateObject(1550, X, Y, Z);
		        mbtxtdraw = Create3DTextLabel("Money Bag",COLOR_CYAN,X,Y,Z-0.8010, 15.0, 0, 0); 
				//
		        SendClientMessageToAll(-1,"Test String");
				//
				DestroyDynamicCP(RobCps[playerid]);
				//
				HideTimer(playerid);
	}
    return 1;
}



Re: Array index out of bounds -- HELP PLS - GeorgeLimit - 27.01.2019

Quote:

public FailRob(playerid,robid)
{
if(robid == 1)
{
SendClientMessageToAll(-1,"Test String"); // worked!
DestroyDynamicCP(RobCps[playerid]); // not worked!
//
HideTimer(playerid); // not worked (this stock should hide some textdraws)
}
return 1;
}

lol why you place like this?
try use it
Quote:

public FailRob(playerid,robid)
{
if(robid == 1)
{
SendClientMessageToAll(-1,"Test String"); // worked!
DestroyDynamicCP(RobCps[playerid]); // not worked!
//
HideTimer(playerid); // not worked (this stock should hide some textdraws)
}
return 1;
}




Re: Array index out of bounds -- HELP PLS - PoniStar - 27.01.2019

cant see any diffrence


Re: Array index out of bounds -- HELP PLS - Calisthenics - 27.01.2019

Quote:
Originally Posted by PoniStar
View Post
um, i cant send the full code here , i will send it as a private mssge to you and y_less!
We only need the code in `FailRob` function, not the whole script. If it is that long, upload to pastebin but do not limit the help to just two users.


Re: Array index out of bounds -- HELP PLS - PoniStar - 27.01.2019

Quote:
Originally Posted by Calisthenics
View Post
We only need the code in `FailRob` function, not the whole script. If it is that long, upload to pastebin but do not limit the help to just two users.
i edited my post :
Code:
public FailRob(playerid,robid)
{
	if(robid == 1)
	{
				new Float:X, Float:Y, Float:Z , string[300];
				GetPlayerPos(playerid,X,Y,Z);
				mbag = CreateObject(1550, X, Y, Z);
		        mbtxtdraw = Create3DTextLabel("Money Bag",COLOR_CYAN,X,Y,Z-0.8010, 15.0, 0, 0);
				//
		        SendClientMessageToAll(-1,"Test String");
				//
				DestroyDynamicCP(RobCps[playerid]);
				//
				HideTimer(playerid);
	}
    return 1;
}



Re: Array index out of bounds -- HELP PLS - Calisthenics - 27.01.2019

Quote:
Originally Posted by PoniStar
View Post
i edited my post :
Code:
public FailRob(playerid,robid)
{
	if(robid == 1)
	{
				new Float:X, Float:Y, Float:Z , string[300];
				GetPlayerPos(playerid,X,Y,Z);
				mbag = CreateObject(1550, X, Y, Z);
		        mbtxtdraw = Create3DTextLabel("Money Bag",COLOR_CYAN,X,Y,Z-0.8010, 15.0, 0, 0);
				//
		        SendClientMessageToAll(-1,"Test String");
				//
				DestroyDynamicCP(RobCps[playerid]);
				//
				HideTimer(playerid);
	}
    return 1;
}
The above code cannot give run time error 4. By hiding the code, you hide the mistake.


Re: Array index out of bounds -- HELP PLS - PoniStar - 27.01.2019

-_- found the problem thnx for your help guys