23.09.2012, 05:03
If you use #define then your script is not future proof. Adding a new vehicle may change the ID of your define there for breaking your code until you change the define. There's nothing wrong with using variables. There's also nothing wrong with storing EVERY vehicles ID, as long as you need it.
If you want to store multiple vehicles without declaring hundreds of variables you can use an array.
Just a small example. If you need to know more have a look for array tutorials.
@Danyal: Surely if a player player is entering a vehicle he must be connected, right?
If you want to store multiple vehicles without declaring hundreds of variables you can use an array.
pawn Код:
/* Outside OnGameModeInit */
// Change 5 to the number of vehicles you want to store
new gAdminVehicles[5];
/* Inside OnGameModeInit (or where ever the vehicle is created) */
gAdminVehicle[0] = AddStaticVehicle(...);
gAdminVehicle[1] = AddStaticVehicle(...);
gAdminVehicle[2] = AddStaticVehicle(...);
gAdminVehicle[3] = AddStaticVehicle(...);
gAdminVehicle[4] = AddStaticVehicle(...);
/* inside OnPlayerEnterVehicle */
// If the players level is not an admin level
if (PlayerInfo[playerid][Level] == 0)
{
for (new i; i < sizeof(gAdminVehicles); i++)
{
if (vehicleid == gAdminVehicle[i])
{
// Do what you want with the player
// break out of the loop as we have found our vehicle
break;
}
}
}
@Danyal: Surely if a player player is entering a vehicle he must be connected, right?

