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

pawn Code:
COMMAND:takecar(playerid, params[])
{
    new Lrg[1800], count, statusaa[20], IsAtGarage = 0, takecarr[250];
    GarageLoop(g)
    {
        if(PublicGarage[g][gActive] == 0) continue;
        if(IsPlayerInRangeOfPoint(playerid, 2.0, PublicGarage[g][garageX],PublicGarage[g][garageY],PublicGarage[g][garageZ]))
        {
            new zone[50];
            IsAtGarage = 1;
            GetZone(PublicGarage[g][garageX],PublicGarage[g][garageY],PublicGarage[g][garageZ], zone);
            format(takecarr, sizeof(takecarr), "{D3D3D3}Take a vehicle from {778899}%s {D3D3D3}Garage", zone);
        }
    }
    if(IsAtGarage == 0) return SendClientError(playerid, "You need to be outside a public garage to use this command");
    VehLoop(v)
    {
        if(Vehicle[v][vActive] == 0) continue;
        new pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(!strcmp(Vehicle[v][owner], PlayerName(playerid), false))
        {
            count++;
            if(Vehicle[v][InGarage] == 1) format(statusaa, sizeof(statusaa), "{B0C4DE}Stored");
            else format(statusaa, sizeof(statusaa), "{ff0000}Spawned");
            format(LrgStr, sizeof(LrgStr), "{778899}Vehicle: {B0C4DE}%s {ffffff}>> {778899}Status: %s\n", GetVehicleNameFromModel(Vehicle[v][model]), statusaa);
            strcat(Lrg, LrgStr);
        }
    }
    if(count <= 0) return SendClientError(playerid, "You currently do not own any vehicles");
    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, takecarr, Lrg, "Take", "Cancel");
    return 1;
}
Crash Detect:

Code:
[23:41:24] [debug] Run time error 4: "Array index out of bounds"
[23:41:24] [debug]  Accessing element at negative index -400
[23:41:24] [debug] AMX backtrace:
[23:41:24] [debug] #0 000078e8 in GetVehicleNameFromModel (modelid=0) at C:\Users\Brandon\Desktop\programming\Sicilian Mafia Roleplay\gamemodes\sicilian.pwn:1008
[23:41:24] [debug] #1 0002b5a8 in public cmd_takecar (playerid=0, params[]=@0x0015368c "") at C:\Users\Brandon\Desktop\programming\Sicilian Mafia Roleplay\gamemodes\sicilian.pwn:3931
[23:41:24] [debug] #2 native CallLocalFunction () [00472ef0] from samp-server.exe
[23:41:24] [debug] #3 000006f4 in public OnPlayerCommandText (playerid=0, cmdtext[]=@0x00153668 "/takeca") at C:\Users\Brandon\Desktop\programming\Sicilian Mafia Roleplay\pawno\include\zcmd.inc:89
Reply
#2

You are acessing a negative array index.

Check your GetVehicleNameFromModel function.
Reply
#3

Check Vehicle[v][owner] in strcmp because if Vehicle[v][owner] is empty strcmp match
Reply
#4

pawn Code:
stock GetVehicleNameFromModel(modelid)
{
    new vn[50];
    format(vn,sizeof(vn),"%s",VehicleName[modelid-400]);
    return vn;
}
Reply
#5

pawn Code:
COMMAND:takecar(playerid, params[])
{
    new bool:IsAtGarage, takecarr[128];
    GarageLoop(g)
    {
        if(PublicGarage[g][gActive] == 0) continue;
        if(IsPlayerInRangeOfPoint(playerid, 2.0, PublicGarage[g][garageX],PublicGarage[g][garageY],PublicGarage[g][garageZ]))
        {
            new zone[50];
            IsAtGarage = true;
            GetZone(PublicGarage[g][garageX],PublicGarage[g][garageY],PublicGarage[g][garageZ], zone);
            format(takecarr, sizeof(takecarr), "{D3D3D3}Take a vehicle from {778899}%s {D3D3D3}Garage", zone);
            break;
        }
    }
    if(!IsAtGarage) return SendClientError(playerid, "You need to be outside a public garage to use this command");

    IsAtGarage = false;

    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    new Lrg[1800], count, statusaa[20];
    VehLoop(v)
    {
        if(Vehicle[v][vActive] == 0) continue;

        if(Vehicle[v][owner][0] != 0 && !strcmp(Vehicle[v][owner], pname))
        {
            IsAtGarage = true;
            if(Vehicle[v][InGarage] == 1) statusaa = "{B0C4DE}Stored";
            else statusaa = "{ff0000}Spawned";
            format(LrgStr, sizeof(LrgStr), "{778899}Vehicle: {B0C4DE}%s {ffffff}>> {778899}Status: %s\n", GetVehicleNameFromModel(Vehicle[v][model]), statusaa);
            strcat(Lrg, LrgStr);
        }
    }
    if(!count) return SendClientError(playerid, "You currently do not own any vehicles");
    return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_LIST, takecarr, Lrg, "Take", "Cancel");
}
and you don't need format here

pawn Code:
stock GetVehicleNameFromModel(modelid)
    return VehicleName[modelid-400];
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)