Array index out of bounds
#1

I have a command, which shows all the vehicles with the id, ownername, vehiclename and model. Although, im getting an error but im not sure how to fix it. The command DOES work, it shows all the vehicles, and after that you get the Unkown Command line after it.

pawn Code:
for( new j = 1; j < MAX_PERS_VEHICLES; j ++ )
    {
        new testvar[50];
        strset( testvar, aVehicleNames[VehicleInfo[j][vModel] - 400] );
        //if( VehicleInfo[i][vID] != -1 )
        //{
        format( query, sizeof query, "| CarID: %i | Owner: %s | Vehicle: %s(%i) |", VehicleInfo[j][vID], VehicleInfo[j][vOwner], testvar, VehicleInfo[j][vModel] );
        SendClientMessage( playerid, -1, query );
        printf( "i = %i, vehiclename = %s | i-vmodel = %i | vmodel = %i | VehicleInfo[%i]", j, aVehicleNames[VehicleInfo[j][vModel] - 400], ( VehicleInfo[j][vModel]-400 ), VehicleInfo[j][vModel], j );
        //}
    }
Code:
[14:12:26] i = 1, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[1]
[14:12:26] i = 2, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[2]
[14:12:26] i = 3, vehiclename = Infernus | i-vmodel = 11 | vmodel = 411 | VehicleInfo[3]
[14:12:26] i = 4, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[4]
[14:12:26] i = 5, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[5]

[14:12:26] [debug] Run time error 4: "Array index out of bounds"
[14:12:26] [debug]  Accessing element at negative index -400
[14:12:26] [debug] AMX backtrace:
[14:12:26] [debug] #0 0000c664 in public cmd_showcpv () from gm.amx
[14:12:26] [debug] #1 native CallLocalFunction () [00471e90] from samp-server.exe
[14:12:26] [debug] #2 00006118 in public OnPlayerCommandText () from gm.amx
Reply
#2

Bump
Reply
#3

The weird thing is, none of them are.
Code:
[14:12:26] i = 1, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[1]
[14:12:26] i = 2, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[2]
[14:12:26] i = 3, vehiclename = Infernus | i-vmodel = 11 | vmodel = 411 | VehicleInfo[3]
[14:12:26] i = 4, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[4]
[14:12:26] i = 5, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[5]
The i-vmodel are just normal values, same with the models.
Reply
#4

Thanks, fixed the problem.

VehicleInfo[vehicleid][vID] isnt set as -1, whenever the vehicle doesnt exists.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)