SA-MP Forums Archive
Making it soo theese cars can only be drove by TEAM_COP - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Making it soo theese cars can only be drove by TEAM_COP (/showthread.php?tid=100707)



Making it soo theese cars can only be drove by TEAM_COP - aspire5630 - 05.10.2009

Hello. i have

Код:
new CopCar[18];
and then

Код:
CopCar[0] = AddStaticVehicle(
CopCar[1] = AddStaticVehicle(
CopCar[2] = AddStaticVehicle(
CopCar[3] = AddStaticVehicle(
...
all up to [17]
But then i need something on,
Код:
OnPlayerStateChange
or something i think


But i dont know
i need to make it so
only
Код:
TEAM_COP
can drive the cars :S


Re: Making it soo theese cars can only be drove by TEAM_COP - [mad]MLK - 05.10.2009

Код:
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);
		}
		}
}



Re: Making it soo theese cars can only be drove by TEAM_COP - aspire5630 - 06.10.2009

mm this is now how i need it,

I need it soo
if your not TEAM_COP then it RemovePlayerFromVehicle
and then sends them a message saying, "You need to be a Cop to drive this"


Re: Making it soo theese cars can only be drove by TEAM_COP - kokkie20 - 06.10.2009

Код:
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!");
		}
		}
}



Re: Making it soo theese cars can only be drove by TEAM_COP - Correlli - 06.10.2009

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 Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(playerid, x, y, z);



Re: Making it soo theese cars can only be drove by TEAM_COP - kokkie20 - 06.10.2009

Quote:
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 Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(playerid, x, y, z);
i got it at a other place, cause i use it different then him, and i am not that good scripter
but it tryed to help him a little bit


Re: Making it soo theese cars can only be drove by TEAM_COP - woot - 06.10.2009

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