How to make police cars unenterable
#1

I am trying to make my police cars un enterable i have this code

PHP Code:
public OnVehicleStreamIn(vehicleidforplayerid)
{
    if (
cop >=1) {
    
SetVehicleParamsForPlayer(596,forplayerid,0,1);
    }
    else
    {
    
SetVehicleParamsForPlayer(596,forplayerid,0,0);
    }
    return 
1;

Reply
#2

pawn Code:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(IsVehicleCopCar(vehicleid) && pTeam[forplayerid] != TEAM_COP) // Or whatever team system you are using
    {
        SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1); // Lock doors
    }
    return 1;
}

stock IsVehicleCopCar(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 523, 427, 490, 528, 596 .. 599, 601: return 1;
    }
    return 0;
}
You never have to unlock the vehicles, because when they stream out and in again the doors get unlocked anyway, so if they change class/team/whatever it will likely stream the vehicle out (as they respawn, well I assume).

Not actually tested that, not sure if the IsVehicleCopCar will give errors due to the return.

NOTE: The cop bike doesn't have door locks, obviously, so I'm not sure if locking the doors works, I THINK it does.
Reply
#3

Quote:
Originally Posted by MP2
View Post
pawn Code:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(IsVehicleCopCar(vehicleid) && pTeam[forplayerid] != TEAM_COP) // Or whatever team system you are using
    {
        SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1); // Lock doors
    }
    return 1;
}

stock IsVehicleCopCar(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 523, 427, 490, 528, 596 .. 599, 601: return 1;
    }
    return 0;
}
You never have to unlock the vehicles, because when they stream out and in again the doors get unlocked anyway, so if they change class/team/whatever it will likely stream the vehicle out (as they respawn, well I assume).

Not actually tested that, not sure if the IsVehicleCopCar will give errors due to the return.

NOTE: The cop bike doesn't have door locks, obviously, so I'm not sure if locking the doors works, I THINK it does.
it doesn't seem to be working its letting me still enter the cars

oh never mind works but i made accidently made it so its 0 instead of 1 thanks.
Reply
#4

Try using OnPlayerStateChange with these

pawn Code:
if(newstate == PLAYER_STATE_DRIVER)
if you want to remove player when he/she enters the driver seat/passenger seat

then do this

pawn Code:
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
Reply
#5

Try to put this
PHP Code:
if(IsVehicleCopCar(vehicleid) && pTeam[forplayerid] != TEAM_COP// Or whatever team system you are using
{
        
SetVehicleParamsForPlayer(vehicleidforplayerid01); // Lock doors

under OnPlayerEnterVehicle
or try this code
PHP Code:
if(IsVehicleCopCar(vehicleid) && pTeam[forplayerid] != TEAM_COP// Or whatever team system you are using
{
        new 
motore,luci,allarme,sicura,cofano,bagagliaio,objective;
    
GetVehicleParamsEx(vehicleid,motore,luci,allarme,sicura,cofano,bagagliaio,objective);
        
SetVehicleParamsEx(vehicleid,motore,luci,allarme,VEHICLE_PARAMS_ON,cofano,bagagliaio,objective);

Reply
#6

Quote:
Originally Posted by xX_Simon_Xx
View Post
Try to put this
PHP Code:
if(IsVehicleCopCar(vehicleid) && pTeam[forplayerid] != TEAM_COP// Or whatever team system you are using
{
        
SetVehicleParamsForPlayer(vehicleidforplayerid01); // Lock doors

under OnPlayerEnterVehicle
or try this code
PHP Code:
if(IsVehicleCopCar(vehicleid) && pTeam[forplayerid] != TEAM_COP// Or whatever team system you are using
{
        new 
motore,luci,allarme,sicura,cofano,bagagliaio,objective;
    
GetVehicleParamsEx(vehicleid,motore,luci,allarme,sicura,cofano,bagagliaio,objective);
        
SetVehicleParamsEx(vehicleid,motore,luci,allarme,VEHICLE_PARAMS_ON,cofano,bagagliaio,objective);

im using it as a factiontype thing like this

PHP Code:
             if(IsVehicleCopCar(vehicleid) && cop 1// Or whatever team system you are using
    
{
        
SetVehicleParamsForPlayer(vehicleidforplayerid01); // Lock doors
    
}
    if(
IsVehicleCopCar(vehicleid) && cop >= 1// Or whatever team system you are using
    
{
        
SetVehicleParamsForPlayer(vehicleidforplayerid00); // Lock doors
    

It locks the car for the cops as well so even a cop can't drive it but ill try what you said. under on player enter vehicle.
Reply
#7

Quote:
Originally Posted by jueix
View Post
im using it as a factiontype thing like this

PHP Code:
             if(IsVehicleCopCar(vehicleid) && cop 1// Or whatever team system you are using
    
{
        
SetVehicleParamsForPlayer(vehicleidforplayerid01); // Lock doors
    
}
    if(
IsVehicleCopCar(vehicleid) && cop >= 1// Or whatever team system you are using
    
{
        
SetVehicleParamsForPlayer(vehicleidforplayerid00); // Lock doors
    

It locks the car for the cops as well so even a cop can't drive it but ill try what you said. under on player enter vehicle.
Putting the code OnPlayerEnterVehicle will not work as i told you before put it in OnPlayerStateChange
check my last previous post
Reply
#8

Quote:
Originally Posted by RollTi
View Post
Putting the code OnPlayerEnterVehicle will not work as i told you before put it in OnPlayerStateChange
check my last previous post
okay ill try that. Its giving me errors saying undefined vehicleid
Reply
#9

No, don't put it under OnPlayerStateChange, that's a stupid thing to suggest. That's called when they HAVE ENTERED a vehicle. My method will lock the doors, preventing entry.
Reply
#10

Quote:
Originally Posted by MP2
View Post
No, don't put it under OnPlayerStateChange, that's a stupid thing to suggest. That's called when they HAVE ENTERED a vehicle. My method will lock the doors, preventing entry.
but i want it so that if a player enters the cop car that the cop < 0 it will not allow him to enter but if a players cop is greater than 1 it will let him enter.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)