Removing Player from vehicle problem
#1

Hello so i made a variable that if a player dosent picks a class Engineer or Pilot he cant get in to army vehicles
but when i try to get in when i am not a pilot or engineer nothing happens it dosent remove me from the vehicle
if you guys help me i will +rep you

here is the code
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid == 432)
    {
       if(Engineer[playerid] != 1)
       {
          RemovePlayerFromVehicle(playerid);
          SendClientMessage(playerid,COLOR_RED,"You need to be Engineer class to use this vehicle");
       }
    }
    if(vehicleid == 520 && 425)
    {
       if(Pilot[playerid] != 1)
       {
          RemovePlayerFromVehicle(playerid);
          SendClientMessage(playerid,COLOR_RED,"You need to be Pilot class to use this vehicle");
       }
    }      
       
    return 1;
}
Reply
#2

Quote:
Originally Posted by DarkLored
Посмотреть сообщение
Hello so i made a variable that if a player dosent picks a class Engineer or Pilot he cant get in to army vehicles
but when i try to get in when i am not a pilot or engineer nothing happens it dosent remove me from the vehicle
if you guys help me i will +rep you

here is the code
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid == 432)
    {
       if(Engineer[playerid] != 1)
       {
          RemovePlayerFromVehicle(playerid);
          SendClientMessage(playerid,COLOR_RED,"You need to be Engineer class to use this vehicle");
       }
    }
    if(vehicleid == 520 && 425)
    {
       if(Pilot[playerid] != 1)
       {
          RemovePlayerFromVehicle(playerid);
          SendClientMessage(playerid,COLOR_RED,"You need to be Pilot class to use this vehicle");
       }
    }      
       
    return 1;
}
Well I'm guessing that you want the model id of the vehicle and not the vehicleid. And also && is the same as AND, so you're basiclly writing: if the vehicleid is 520 AND 425 then execute the code. But since it can't be 2 things at the same time you should rather use || (or)
This should work.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new model = GetVehicleModel(vehicleid);
    if(model == 432)
    {
        if(Engineer[playerid] != 1)
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid,COLOR_RED,"You need to be Engineer class to use this vehicle");
        }
    }
    if(model == 520 || 425)
    {
        if(Pilot[playerid] != 1)
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid,COLOR_RED,"You need to be Pilot class to use this vehicle");
        }
    }
    return 1;
}
Reply
#3

OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) is called when you try and enter a vehicle he needs OnPlayerStateChange()

https://sampwiki.blast.hk/wiki/OnPlayerStateChange
Reply
#4

thank you both +reped it worked
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)