OnPlayerEnterVehicle bug
#1

Hi, i have a problem with OnPlayerEnterVehicle callback. I want to do this: when a player enter into a police car / paramedic car and he isn't from this faction, to get him out of the car. The code works with this vehicles (police and paramedic) but for example when i spawn a car with /spawncar, if i want to enter vehicle, the code works as if entering a police or paramedic car. Here is my code: https://pastebin.com/y7HrFxFw

Thank you!
Reply
#2

There is no need of a Timer to remove the player from the vehicle, instead use ClearAnimations and the player won't be able to enter it. The code should work.

PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    if(
vehicleid == PoliceVehicle[1] || PoliceVehicle[2] || PoliceVehicle[3] || PoliceVehicle[4] || PoliceVehicle[5] || PoliceVehicle[6] || PoliceVehicle[7] || PoliceVehicle[8] || PoliceVehicle[9])
    {
        if(
PlayerInfo[playerid][pFaction] != 1)
        {
            
ClearAnimations(playerid);
            
GameTextForPlayer(playerid"~r~Nu esti autorizat sa conduci aceasta masina!"10003);
        }
        else return 
InCopCar[playerid] = 1;
    }
    else return 
InCopCar[playerid] = 0;
 
    else if(
vehicleid == ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1])
    {
        if(
PlayerInfo[playerid][pFaction] != 2)
        {
           
ClearAnimations(playerid);
           
GameTextForPlayer(playerid"~r~Nu esti autorizat sa conduci aceasta masina!"10003);
        }
        else return 
InParamedicCar[playerid] = 1;
    }
    else return 
InParamedicCar[playerid] = 0;
 
    return 
1;

Reply
#3

You are right with ClearAnimations instead of Timers, but not this is my problem. I can't enter in any other car, like spawned car if i'm not in the group 1 (police). Some photos here if they help: http://imgur.com/a/A2nOr
I hope you understand my problem now.
Thanks again for your time.
Reply
#4

Can you send me your variable of PoliceVehicle & Parademic Vehicle? Then maybe I can help you out.
Reply
#5

It's ok? https://pastebin.com/ecmR7WKR
Reply
#6

Ah.. Maybe try use these 2 stock(s), would be much better.
PHP код:
stock IsAPoliceVehicle(vehicleid)
{
     switch(
GetVehicleModel(vehicleid)) 
           {
            case 
598599523: return 1// You can add more vehicles id if u add more cop vehicles.
           
}
           return 
0;

PHP код:
stock IsAParademicVehicle(vehicleid)
{
     switch(
GetVehicleModel(vehicleid)) 
           {
            case 
416: return 1// same applies here.
           
}
           return 
0;

Your final code should be this and should be working. (Haven't tested it but looks fine for me.)
PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger

    if(
IsAPoliceVehicle(vehicleid)) 
    { 
        if(
PlayerInfo[playerid][pFaction] != 1
        { 
            
ClearAnimations(playerid); 
            
GameTextForPlayer(playerid"~r~Nu esti autorizat sa conduci aceasta masina!"10003); 
        } 
        else return 
InCopCar[playerid] = 1
    } 
    else return 
InCopCar[playerid] = 0
  
    else if(
IsAParademicVehicle(vehicleid)) 
    { 
        if(
PlayerInfo[playerid][pFaction] != 2
        { 
           
ClearAnimations(playerid); 
           
GameTextForPlayer(playerid"~r~Nu esti autorizat sa conduci aceasta masina!"10003); 
        } 
        else return 
InParamedicCar[playerid] = 1
    } 
    else return 
InParamedicCar[playerid] = 0
  
    return 
1

Reply
#7

Please try something like this:
PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger) {
   if (!
ispassenger) {
       for (new 
1sizeof(PoliceVehicle); i++) {
           if (
vehicleid == PoliceVehicle[i]) {
              if (
PlayerInfo[playerid][pFaction] != 1) {
                 
ClearAnimations(playerid);
              } else {
                 
InCopCar[playerid] = 1;
              }
              break;
           }
       }
   }
   return 
1;

Reply
#8

This code works. Thank you very much for helping! Rep+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)