Specific vehicle
#5

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.

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;
        }
    }
}
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?
Reply


Messages In This Thread
Specific vehicle - by Black Wolf - 23.09.2012, 04:43
Re: Specific vehicle - by Psymetrix - 23.09.2012, 04:49
Re: Specific vehicle - by Black Wolf - 23.09.2012, 04:54
Re: Specific vehicle - by Danyal - 23.09.2012, 04:58
Re: Specific vehicle - by Psymetrix - 23.09.2012, 05:03
Re: Specific vehicle - by Black Wolf - 23.09.2012, 05:04
Re: Specific vehicle - by Danyal - 23.09.2012, 05:12
Re: Specific vehicle - by Black Wolf - 23.09.2012, 05:15
Re: Specific vehicle - by Danyal - 23.09.2012, 05:16
Re: Specific vehicle - by Psymetrix - 23.09.2012, 05:16

Forum Jump:


Users browsing this thread: 1 Guest(s)