Enter more vehicle to drive. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Enter more vehicle to drive. (
/showthread.php?tid=515678)
Enter more vehicle to drive. -
Mey6155 - 27.05.2014
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid == DriversTest[4])
{
if(AllowTakeLCar[playerid] == 1)
{
if(IsPlayerInAnyVehicle(playerid))
{
SCM(playerid, COLOR_RED, "------------------------------------------");
SCM(playerid, COLOR_BLUE, "Notes for drivers/motor license.");
SCM(playerid, COLOR_GREEN, "Don't crash the car!");
SCM(playerid, COLOR_GREEN, "Don't ride thru red!");
SCM(playerid, COLOR_GREEN, "Don't speed MAX 50 km/h");
SetPlayerCheckpoint(playerid, 1726.6279,1288.2347,10.3990, 2.5);
SCM(playerid, COLOR_RED, "------------------------------------------");
Ccp[playerid] = 1;
}
}
else if(AllowTakeLCar[playerid] == 0)
{
SCM(playerid, -1, "Your not taking a test!");
return RemovePlayerFromVehicle(playerid);
}
}
}
return 1;
}
pawn Код:
DriversTest[0] = AddStaticVehicleEx(426,1641.2000000,1293.3000000,10.6000000,270.0000000,254,254,15000); //Premier
DriversTest[1] = AddStaticVehicleEx(426,1641.2000000,1296.4000000,10.6000000,270.0000000,254,254,15000); //Premier
DriversTest[2] = AddStaticVehicleEx(426,1641.2000000,1299.5000000,10.6000000,270.0000000,254,254,15000); //Premier
DriversTest[3] = AddStaticVehicleEx(426,1641.1000000,1302.3000000,10.6000000,270.0000000,254,254,15000); //Premier
Error
Код:
F:\Mustafa\Dutch-RealLife\gamemodes\Haci.pwn(832) : error 032: array index out of bounds (variable "DriversTest")
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
1 Error.
Error line:
if(vehicleid == DriversTest[4])
Re: Enter more vehicle to drive. -
Konstantinos - 27.05.2014
The size of DriversTest is 4 so the valid indexes are 0-3. You can loop through all its indexes and see if the vehicleid matches.
pawn Код:
if (IsVehicleForDrivingTest(vehicleid))
{
// vehicle is for driving tests..
}
pawn Код:
IsVehicleForDrivingTest(vehicleid)
{
for (new i; i != sizeof (DriversTest); ++i)
{
if (vehicleid == DriversTest[i]) return 1;
}
return 0;
}
Re: Enter more vehicle to drive. -
NaClchemistryK - 27.05.2014
pawn Код:
if(vehicleid == DriversTest[4])
the array index of DriversTest can be between 0 and 3, not bigger than 3. 4 is bigger than 3, so it's out of bounds. use another value or loop through it
EDIT: too late.