[debug] Run time error 4: "Array index out of bounds" [READ FOR MORE INFO]
#1

Hello, I added this

Код:
        new cdveh = GetPlayerVehicleID(MAX_PLAYERS);
		if(GetCarDealershipVehicleId(cdveh) != -1 && GetCarDealershipVehicleId(cdveh) == GetPVarInt(playerid, "editingcdveh")) return 1;
		if(GetCarDealershipVehicleId(cdveh) != -1)
		{
		    new string[128];
			//new string[57 + 20 + 4];
			format(string, sizeof(string),"Would you like to buy this %s? This vehicle costs $%d.", GetVehicleName(cdveh), CarDealershipInfo[GetCarDealershipId(cdveh)][cdVehicleCost][GetCarDealershipVehicleId(cdveh)]);
			//ShowPlayerDialogEx(playerid,DIALOG_CDBUY,DIALOG_STYLE_MSGBOX,"Warning:",string,"Buy","Cancel");
			SendClientMessage(playerid, COLOR_REALRED, string);
			SendClientMessage(playerid, COLOR_YELLOW, "Type /buyvehicle to buy the car");
			TogglePlayerControllable(playerid, false);
			return 1;
		}
And those messages doesnt appear. I tried to add the crashdetect plugin and i figure out the problem. Is caming from that line (im very sure)

How do i fix it Thanks

Full Debug Error
Код:
[15/05/2014 15:14:07] [debug] Run time error 4: "Array index out of bounds"
[15/05/2014 15:14:07] [debug]  Accessing element at negative index -400
[15/05/2014 15:14:07] [debug] AMX backtrace:
[15/05/2014 15:14:07] [debug] #0 002641b4 in public OnPlayerStateChange (0x00000000, 0x00000002, 0x00000001) from PHRP_1.5.amx
Just a note: Before i add that everything is fine no debug errors after i add it appears.

Respectfully yours,
Reply
#2

OnPlayerEnterDynamicCP or any CMD
what is that function ?
Reply
#3

Quote:
Originally Posted by Trynda
Посмотреть сообщение
Hello, I added this

Код:
        new cdveh = GetPlayerVehicleID(MAX_PLAYERS);
What the hell is this? What are you trying to do?
Reply
#4

Because you did:
pawn Код:
new cdveh = GetPlayerVehicleID(MAX_PLAYERS);
when it should be "playerid" instead of "MAX_PLAYERS" and cdveh is 0 and then using:
pawn Код:
GetVehicleName(cdveh)
will cause the run time error because you basically do: 0-400 which results to a negative index. You must check if the modelid is not 0 and subtract.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)