new CopCar[18];
CopCar[0] = AddStaticVehicle( CopCar[1] = AddStaticVehicle( CopCar[2] = AddStaticVehicle( CopCar[3] = AddStaticVehicle( ... all up to [17]
OnPlayerStateChange
TEAM_COP
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) { if(GetVehicleModel(vehicleid) == 520) // replace 520 with the id of the car you want only police to drive { if(gTeam[playerid] == TEAM_COP) { SendClientMessage(playerid, red, "You are police, You needed to be police to drive this car"); } else { new Float:px, Float:py, Float:pz; SendClientMessage(playerid, red, "You need to be a cop to drive a cop car!."); GetPlayerPos(playerid, px, py, pz); SetPlayerPos(playerid, px, py, pz+3); } } }
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) { if(GetVehicleModel(vehicleid) == 520) // replace 520 with the id of the car you want only police to drive { if(gTeam[playerid] == TEAM_COP) { SendClientMessage(playerid, red, "You are police, You can drive the car!"); } else { RemovePlayerFromVehicle(playerid); PlayerPlaySound(playerid, 1147, 0.0, 0.0, 0.0); SendClientMessage(playerid, COLOR_RED, "You need to be a Cop to drive this!"); } } }
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(playerid, x, y, z);
Originally Posted by Don Correlli
This won't work if you're going to use "RemovePlayerFromVehicle" function because OnPlayerEnterVehicle is called every time if player is near the vehicle AND if he presses the enter key, which means he can cancel the entry but callback will get called anyway.
Use this: pawn Код:
|
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new
vm = GetVehicleModel(vehicleid),
Float:playerX, Float:playerY, Float:playerZ;
if(vm == 597 || vm == 598 || vm == 599 || vm == 601) // etc ..
{
if(gTeam[playerid] != TEAM_COP)
{
GetPlayerPos(playerid, playerX, playerY, playerZ);
SetPlayerPos(playerid, playerX, playerY, playerZ);
SendClientMessage(playerid, COLOR_RED, " You don't have the keys for this vehicle.");
}
else return SendClientMessage(playerid, COLOR_RED, " Welcome back on patrol, officer.");
}
return 1;
}