Help me with the error please
#1

When I type /v to view my vehicle garage I get this error:
Код HTML:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Attempted to read/write array element at negative index -400
[debug] AMX backtrace:
[debug] #0 0009fbb0 in ?? (0) from gm.amx
[debug] #1 0007c93c in public cmd_v (0, 24069752) from gm.amx
[debug] #2 native CallLocalFunction () from samp-server.exe
[debug] #3 000006b8 in public OnPlayerCommandText (0, 24069740) from gm.amx
I think I know the cause, and it's part
PHP код:
aVehicleNames[CarInfo[car][cModel]-400
And this is the command:
PHP код:
CMD:v(playeridparams[]) { 
    
ShowPlayerVehicle(playerid);
    return 
1;
}
stock ShowPlayerVehicle(playerid) {
    new 
szTitle[180], szDialog[1300], szDialog2[1300], vstatus[1024];
    if(
GetVehicles(playerid) == 0) return SendClientMessage(playeridCOLOR_GREY"You don't own any vehicles.");    
    
format(szTitlesizeof(szTitle), "Vehicles (%d/4)"GetVehicles(playerid));            
    for(new 
03i++) {
        if(
PlayerInfo[playerid][pCarKey][i] > 0) {
            new 
car =  PlayerInfo[playerid][pCarKey][i];
            if(
IsVehicleOccupied(CarInfo[car][cSpawned])) format(vstatussizeof(vstatus), "{FFFF00}(Occupied){FFFFFF} %s"aVehicleNames[CarInfo[car][cModel]-400]);
            else if(
CarInfo[car][cSpawned] > 0format(vstatussizeof(vstatus), "{26B309}(Spawned){FFFFFF} %s"aVehicleNames[CarInfo[car][cModel]-400]);
            else 
format(vstatussizeof(vstatus), "{FF0000}(Despawned){FFFFFF} %s"aVehicleNames[CarInfo[car][cModel]-400]);
            
format(szDialogsizeof(szDialog), "%s\n"vstatus);
            
strcat(szDialog2szDialog);
        }
        
ShowPlayerDialog(playeridDIALOG_GARAGEDIALOG_STYLE_LISTszTitleszDialog2"Ok""Exit");
    }
    return 
1;

Have a nice day!
Reply
#2

Yes, that line causing it. cModel is 0 and subtracts 400 from it.

Currently, the script is faulty. pCarKey is > 0 so this means that vehicle exists but the model is none. Reasons:
1) You do not reset pCarKey if car is removed from player's vehicles.
2) You do not load model of car correctly.

Find the reason and fix it. Until then, a way to prevent it is to check model instead.
pawn Код:
new car = PlayerInfo[playerid][pCarKey][i];
if (CarInfo[car][cModel] == 0) continue;
If model is 0, it will execute next iteration.

Oh and create variables outside (before) of loops, as well as show the dialog only once after the loop.
Reply
#3

All it is, is the model -400 part, and it's because you haven't got that set up correctly, either through copy pasting, or some other issue.

The reason being is that this is how you use arrays to store the vehicle names/stats.

I'd avoid making any other changes to the code unrelated to this line, until they actually produce an error, or you can provide more info about the points mentioned above if they relate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)