run time error 4 :" Arrray index out of bounds
#1

Код:
[22:24:21] [debug] Run time error 4: "Array index out of bounds"
[22:24:21] [debug] AMX backtrace:
[22:24:21] [debug] #0 0053ce3c in public OnPlayerEnterCheckpoint (playerid=0) at ./File/GTA-RP.pwn:94466
Код:
		if(DoubleXP)
                {
					SendClientMessageEx(playerid, COLOR_YELLOW, "Ban da duoc 2 diem ky nang truck thay vi 1 diem.");
					PlayerInfo[playerid][pTruckSkill] += 2;
                    if(TruckerTogetther[playerid] != INVALID_PLAYER_ID)
                    {
                        SendClientMessageEx(TruckerTogetther[playerid], COLOR_YELLOW, "Ban da duoc 2 diem ky nang truck thay vi 1 diem.");
                        PlayerInfo[TruckerTogetther[playerid]][pTruckSkill] += 2;
                    }
					PlayerInfo[playerid][pXP] += PlayerInfo[playerid][pLevel] * XP_RATE * 2;
				}
				else if(PlayerInfo[playerid][pDoubleEXP] > 0 && !DoubleXP)
				{
					format(string, sizeof(string), "Ban da duoc 2 ky nang truck thay vi 1 diem. Ban co %d gio con lai de nhan doi EXP token.", PlayerInfo[playerid][pDoubleEXP]);
					SendClientMessageEx(playerid, COLOR_YELLOW, string);
					PlayerInfo[playerid][pTruckSkill] += 2;
                    if(TruckerTogetther[playerid] != INVALID_PLAYER_ID)
                    {
                        if(PlayerInfo[TruckerTogetther[playerid]][pDoubleEXP] > 0)
                        {
                            format(string, sizeof(string), "Ban da duoc 2 ky nang truck thay vi 1 diem. Ban co %d gio con lai de nhan doi EXP token.", PlayerInfo[TruckerTogetther[playerid]][pDoubleEXP]);
                            SendClientMessageEx(TruckerTogetther[playerid], COLOR_YELLOW, string);
                            PlayerInfo[TruckerTogetther[playerid]][pTruckSkill] += 2;
                        }
                    }
					PlayerInfo[playerid][pXP] += PlayerInfo[playerid][pLevel] * XP_RATE * 2;
				}
				else
				{
					PlayerInfo[playerid][pTruckSkill] += 1;
                    if(TruckerTogetther[playerid] != INVALID_PLAYER_ID)
                    {
                        PlayerInfo[TruckerTogetther[playerid]][pTruckSkill] += 1;
                    }
					PlayerInfo[playerid][pXP] += PlayerInfo[playerid][pLevel] * XP_RATE;
				}

				if(PlayerInfo[playerid][pDaily_Status] == 1 && PlayerInfo[playerid][pDaily_Step] == 2 && PlayerInfo[playerid][pDaily_Step_Status] == 0)
				{
					PlayerInfo[playerid][pDaily_Count]++;

					if(PlayerInfo[playerid][pDaily_Count] == DAILY_TRUCK_DELIVER_TURN)
					{
						PlayerInfo[playerid][pDaily_Step_Status] = 1;
						SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "Ban da hoan thanh nhiem vu so 2: 'Giao 5 chuyen Truck' hay tro lai gap NPC de nhan nhiem vu tiep theo.");
					}
				}

				if(TruckerTogetther[playerid] != INVALID_PLAYER_ID)
				{
					if(PlayerInfo[TruckerTogetther[playerid]][pDaily_Status] == 1 && PlayerInfo[TruckerTogetther[playerid]][pDaily_Step] == 2 && PlayerInfo[TruckerTogetther[playerid]][pDaily_Step_Status] == 0)
					{
						PlayerInfo[TruckerTogetther[playerid]][pDaily_Count]++;

						if(PlayerInfo[TruckerTogetther[playerid]][pDaily_Count] == DAILY_TRUCK_DELIVER_TURN)
						{
							PlayerInfo[TruckerTogetther[playerid]][pDaily_Step_Status] = 1;
							SendClientMessageEx(TruckerTogetther[playerid], COLOR_LIGHTBLUE, "Ban da hoan thanh nhiem vu so 2: 'Giao 5 chuyen Truck' hay tro lai gap NPC de nhan nhiem vu tiep theo.");
						}
					}
				}

				if(PlayerInfo[playerid][pDaily_Status] == 1 && PlayerInfo[playerid][pDaily_Step] == 10 && PlayerInfo[playerid][pDaily_Step_Status] == 0)
				{
					PlayerInfo[playerid][pDaily_Count]++;

					if(PlayerInfo[playerid][pDaily_Count] == DAILY_TRUCK_DELIVER_TURN)
					{
						PlayerInfo[playerid][pDaily_Step_Status] = 1;
						SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "Ban da hoan thanh nhiem vu so 10: 'Giao 5 chuyen Truck' hay tro lai gap NPC de nhan nhiem vu tiep theo.");
					}
				}

				if(TruckerTogetther[playerid] != INVALID_PLAYER_ID)
				{
					if(PlayerInfo[TruckerTogetther[playerid]][pDaily_Status] == 1 && PlayerInfo[TruckerTogetther[playerid]][pDaily_Step] == 10 && PlayerInfo[TruckerTogetther[playerid]][pDaily_Step_Status] == 0)
					{
						PlayerInfo[TruckerTogetther[playerid]][pDaily_Count]++;

						if(PlayerInfo[TruckerTogetther[playerid]][pDaily_Count] == DAILY_TRUCK_DELIVER_TURN)
						{
							PlayerInfo[TruckerTogetther[playerid]][pDaily_Step_Status] = 1;
							SendClientMessageEx(TruckerTogetther[playerid], COLOR_LIGHTBLUE, "Ban da hoan thanh nhiem vu so 10: 'Giao 5 chuyen Truck' hay tro lai gap NPC de nhan nhiem vu tiep theo.");
						}
					}
				}

				TruckUsed[playerid] = INVALID_VEHICLE_ID;
				TruckUsed[TruckerTogetther[playerid]] = INVALID_VEHICLE_ID;
				TruckerTogetther[playerid] = INVALID_PLAYER_ID;
			    TruckerTogetther[TruckerTogetther[playerid]] = INVALID_PLAYER_ID;
				DeletePVar(playerid, "TruckDeliver");
Error 94466
Код:
TruckUsed[playerid] = INVALID_VEHICLE_ID;
				TruckUsed[TruckerTogetther[playerid]] = INVALID_VEHICLE_ID;
				TruckerTogetther[playerid] = INVALID_PLAYER_ID;
			    TruckerTogetther[TruckerTogetther[playerid]] = INVALID_PLAYER_ID;
				DeletePVar(playerid, "TruckDeliver");
Reply
#2

Code?
Reply
#3

Quote:
Originally Posted by Variable™
Посмотреть сообщение
Code?
Bump
Reply
#4

What are you bumping? Show code.

Edit: You added code after my reply nvm.
Reply
#5

Quote:
Originally Posted by Variable™
Посмотреть сообщение
What are you bumping? Show code.
I have shown the above already?
Reply
#6

Код:
TruckerTogetther[playerid] = INVALID_PLAYER_ID;
TruckerTogetther[TruckerTogetther[playerid]] = INVALID_PLAYER_ID;
You set TruckerTogetther to INALID_PLAYER_ID and then use it as index.
That's your index out of bounds error.

Store the first value in a local variable, then reset it for playerid and after that use the local variable to reset the other player's TruckerTogetther index.
Reply
#7

Quote:
Originally Posted by NaS
Посмотреть сообщение
Код:
TruckerTogetther[playerid] = INVALID_PLAYER_ID;
TruckerTogetther[TruckerTogetther[playerid]] = INVALID_PLAYER_ID;
You set TruckerTogetther to INALID_PLAYER_ID and then use it as index.
That's your index out of bounds error.

Store the first value in a local variable, then reset it for playerid and after that use the local variable to reset the other player's TruckerTogetther index.
I have another error in this section
Код:
new mypoint = -1;
				for (new i=0; i<MAX_POINTS; i++)
				{
					if(strcmp(Points[i][Name], "LOS SANTOS Docks", true) == 0)
					{
						mypoint = i;
					}
				}
				for(new i = 0; i < sizeof(FamilyInfo); i++)
				{
					if(strcmp(Points[mypoint][Owner], FamilyInfo[i][FamilyName], true) == 0)
					{
						Misc_Save();
						FamilyInfo[i][FamilyBank] = FamilyInfo[i][FamilyBank]+(200);
					}
			 	}
			}
Error
Код:
if(strcmp(Points[mypoint][Owner], FamilyInfo[i][FamilyName], true) == 0)
Reply
#8

Check if mypoint isn't -1 before the second loop. -1 means no slot was found and would cause another array index out of bounds error.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)