Array Index Out Of Bounds
#1

Error line, returned in compiler. I'm not sure what's causing the issue.

MAX_VEHICLES is 500.

I'm not sure of the actual issue with the line.

Could someone kindly assist me?

pawn Код:
format(string, sizeof(string), "%sVehicle: %s | Plate: %s\n", string, VehicleNames[name], VehPlate[x]);



pawn Код:
CMD:collectvehicle(playerid, params[])//here
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    new string[512], am, name;
    for(new x = 0; x < MAX_VEHICLES; x++)
    {
        name = GetVehicleModel(x) - 400;
        if(VehOwner[x] == PlayerSQLID[playerid])
        {
            am ++;
        }
        if(RepairTime[x] == 0 && am == 1)
        {
            VehRepairList[x]= 0;
            format(string, sizeof(string), "Vehicle: %s | Plate: %s\n", VehicleNames[name], VehPlate[x]);
        }
        if(am > 1)
        {
            VehRepairList[x] = am - 1;
            format(string, sizeof(string), "%sVehicle: %s | Plate: %s\n", string, VehicleNames[name], VehPlate[x]);
        }
    }
    if(am == 0)return SendClientMessage(playerid, COLOUR_GREY, "You do not have any vehicles awaiting collection.");
    ShowPlayerDialog(playerid, DIALOG_COLLECTVEH, DIALOG_STYLE_LIST, "Vehicles Awaiting Collection", string, "Select","Close");
    return 1;
}
Reply
#2

Don't you think you should use it like this?
Код:
format(string, sizeof(string), "Vehicle: %s | Plate: %s\n", VehicleNames[name], VehPlate[x]);
SendClientMessage(playerid, -1, string);
Reply
#3

If a vehicle does not exist, GetVehicleModel returns 0 so subtracting 400 from it is negative index -400.
By the way, vehicle IDs start from 1. Using GetVehiclePoolSize or better yet foreach (if you create vehicles only in a single script) is better.
Reply
#4

Ahhhh thanks Konstantinos, again.


Godey, the way it works it has to retrieve multiple inputs.

They do?
Since when? aha...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)