17.05.2016, 19:53
Alright, this is a very basic example I can provide you right now. I hope you can understand something from this
And, you must set the g_PoliceVehicle[vehicleid]'s value to false whenever you destroy one of the created police vehicle. In the similar way you can check for other vehicles too.
Note that this method is probably not that efficient. But still works pretty good and is easier to use so.
PHP код:
// Just defining the model to avoid the confusion
#define PoliceLSPD 596
#define PoliceSFPD 597
#define PoliceLVPD 598
// Boolean variable to indicate it's a police vehicle
new bool: g_PoliceVehicle[MAX_VEHICLES];
// Custom function to create a vehicle
server_AddStaticVehicle(model, Float:x, Float:y, Float:z, Float:angle, color_1, color_2, delay)
{
new vehicleid = AddStaticVehicleEx(model, x, y, z, angle, color_1, color_2, delay);
switch (model)
{
case PoliceLSPD, PoliceSFPD, PoliceLVPD: // Police vehicles, you can add more
{
g_PoliceVehicle[vehicleid] = true;
}
}
return vehicleid;
}
// Adding the vehicle
public OnGamemodeInit()
{
server_AddStaticVehicle(PoliceLSPD, 0.0, 0.0, 0.0, 0.0, -1, -1, 120); // With your coordinates ofc
return 1;
}
// Detecting if players are allowed to drive these vehicles
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vehicleid = GetPlayerVehicleID(playerid);
if (newstate == PLAYER_STATE_DRIVER)
{
if (g_PoliceVehicle[vehicleid] == true)
{
// if (player is not detective)
// Eject
}
}
return 1;
}
Note that this method is probably not that efficient. But still works pretty good and is easier to use so.