Help me to fix this :( -
kesarthakur - 17.01.2015
[19:56:39] [debug] Run time error 4: "Array index out of bounds"
[19:56:39] [debug] Accessing element at negative index -400
[19:56:39] [debug] AMX backtrace:
[19:56:39] [debug] #0 000544f4 in public cmd_v (10, 18260712) from usf.amx
[19:56:39] [debug] #1 native CallLocalFunction () from samp03svr
[19:56:39] [debug] #2 00006330 in public OnPlayerCommandText (10, 18260680) from usf.amx
Getting this errors in my console
pawn Код:
CMD:v(playerid, params[])
{
if (PlayerInfo[playerid][inDM] == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"You cannot spawn a vehicle here, please /leave to proceed.");
if( Minigamer_{ playerid } != false && inProgress >= 1) return SendClientMessage( playerid, COLOR_RED, ""RED"ERROR: "GREY"You can't use this command while in Don't Get Wet minigame." );
if(GetPlayerVirtualWorld(playerid) == 1520 || GetPlayerVirtualWorld(playerid) == 1517) return SendClientMessage(playerid, COLOR_GREY, "You can't use that cmd in this zone!");
new Vehicle[32], VehicleID, ColorOne, ColorTwo;
if(sscanf(params, "s[32]D(1)D(1)", Vehicle, ColorOne, ColorTwo))
{
SendClientMessage(playerid, 0x6FFF00FF, "{F07F1D}USAGE: {BBFF00}/v <Vehicle Name>");
return 1;
}
if(GetPlayerVirtualWorld(playerid) != 1518)
{
if(strcmp(Vehicle, "520")==0 || strcmp(Vehicle, "425")==0 || strcmp(Vehicle, "432")==0 || strcmp(Vehicle, "464")==0 ||
strcmp(Vehicle, "476")==0 && GetPlayerVirtualWorld(playerid) == 0) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"The vehicle you have specified is globally disabled.");
VehicleID = GetVehicleModelIDFromName(Vehicle);
if(VehicleID != 425 && VehicleID != 432 && VehicleID != 447 &&
VehicleID != 430 && VehicleID != 449 && VehicleID != 476 &&
VehicleID != 520 && VehicleID != 537 && VehicleID != 538 &&
VehicleID != 569 && VehicleID != 570 && VehicleID != 577 &&
VehicleID != 590 && VehicleID != 592 && VehicleID != 610 && VehicleID != 539) {
if(VehicleID == -1 )
{
VehicleID = strval(Vehicle);
if(VehicleID < 400 || VehicleID > 611 )
{
return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"You have specified an invalid vehicle name!");
}
}
GetPlayerPos(playerid, pX, pY, pZ);
GetPlayerFacingAngle(playerid, pAngle);
DestroyVehicle(PlayerInfo[playerid][pSpawnVehicle]);
PlayerInfo[playerid][pSpawnVehicle] = CreateVehicle(VehicleID, pX, pY, pZ+2.0, pAngle, random(128), random(128), -1);
LinkVehicleToInterior(PlayerInfo[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
SetVehicleVirtualWorld(PlayerInfo[playerid][pSpawnVehicle], GetPlayerVirtualWorld(playerid));
PutPlayerInVehicle(playerid, PlayerInfo[playerid][pSpawnVehicle], 0);
new msg[60];
format(msg, sizeof(msg), "~g~>> ~r~You have spawned ~g~%s", VehicleNames[GetVehicleModelIdFromName(params) - 400]);
TD_MSG( playerid, 3000, msg );
} else {
if(PlayerInfo[playerid][Admin] == 0) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"Unauthorized Vehicle.");
GetPlayerPos(playerid, pX, pY, pZ);
GetPlayerFacingAngle(playerid, pAngle);
DestroyVehicle(PlayerInfo[playerid][pSpawnVehicle]);
PlayerInfo[playerid][pSpawnVehicle] = CreateVehicle(VehicleID, pX, pY, pZ+2.0, pAngle, random(128), random(128), -1);
LinkVehicleToInterior(PlayerInfo[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
SetVehicleVirtualWorld(PlayerInfo[playerid][pSpawnVehicle], GetPlayerVirtualWorld(playerid));
PutPlayerInVehicle(playerid, PlayerInfo[playerid][pSpawnVehicle], 0);
new msg[60];
format(msg, sizeof(msg), "~g~>> ~r~You have spawned ~g~%s", VehicleNames[GetVehicleModelIdFromName(params) - 400]);
TD_MSG( playerid, 3000, msg );
}
} else {
SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"You cannot spawn a vehicle in this area.");
}
if(GetPlayerVirtualWorld(playerid) == 1518)
{
VehicleID = GetVehicleModelIDFromName(Vehicle);
if(VehicleID == -1 )
{
VehicleID = strval(Vehicle);
if(VehicleID < 400 || VehicleID > 611 )
{
return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"You have specified an invalid vehicle name!");
}
}
GetPlayerPos(playerid, pX, pY, pZ);
GetPlayerFacingAngle(playerid, pAngle);
DestroyVehicle(PlayerInfo[playerid][pSpawnVehicle]);
PlayerInfo[playerid][pSpawnVehicle] = CreateVehicle(VehicleID, pX, pY, pZ+2.0, pAngle, ColorOne, ColorTwo, -1);
LinkVehicleToInterior(PlayerInfo[playerid][pSpawnVehicle], GetPlayerInterior(playerid));
SetVehicleVirtualWorld(PlayerInfo[playerid][pSpawnVehicle], GetPlayerVirtualWorld(playerid));
PutPlayerInVehicle(playerid, PlayerInfo[playerid][pSpawnVehicle], 0);
new msg[60];
format(msg, sizeof(msg), "~g~>> ~r~You have spawned ~g~%s", VehicleNames[GetVehicleModelIdFromName(params) - 400]);
TD_MSG( playerid, 3000, msg );
}
return 1;
}
Please Help me to fix this...
Thanks in advance
Re: Dont know what error is this :( -
GShock - 12.04.2015
Hello...
Is your script compiling perfectly?
Re: Dont know what error is this :( -
dominik523 - 12.04.2015
Maybe is something from here:
pawn Код:
VehicleNames[GetVehicleModelIdFromName(params) - 400]
Show us this function:[/pawn]
GetVehicleModelIdFromName(params)
[/pawn]
It's maybe returning -1 so you are having VehicleNames[-401]
Re: Dont know what error is this :( -
R0 - 12.04.2015
It might be from this:
pawn Код:
VehicleNames[GetVehicleModelIdFromName(params) - 400]
change it to:
pawn Код:
VehicleNames[VehicleID - 400]
Re: Dont know what error is this :( -
GShock - 12.04.2015
Change
pawn Код:
VehicleNames[GetVehicleModelIdFromName(params) - 400]
To
pawn Код:
VehicleNames[GetVehicleModelIdFromName(VehicleID) - 400]
Re: Dont know what error is this :( -
Konstantinos - 12.04.2015
In the
else statement, you do not check if the modelid is between 400 and 611 and an invalid modelid (in your case it returns 0 and you subtract -400; hence the run time error) would cause it.
I'll give you an example of how you should check in format:
pawn Код:
format(msg, sizeof(msg), "~g~>> ~r~You have spawned ~g~%s", (modelid) ? (VehicleNames[modelid - 400]) : ("N/A"));
so if the modelid is valid, it'll pass the vehicle's name stored in the array otherwise N/A.
PS: Try optimizing your code, it'll be easier to read and also not having to re-calling functions again and again (that's what variables are for).