SA-MP Forums Archive
Removing Player from vehicle problem - 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)
+--- Thread: Removing Player from vehicle problem (/showthread.php?tid=492266)



Removing Player from vehicle problem - DarkLored - 03.02.2014

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



Re: Removing Player from vehicle problem - Don_Cage - 03.02.2014

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



Re: Removing Player from vehicle problem - Pottus - 03.02.2014

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

https://sampwiki.blast.hk/wiki/OnPlayerStateChange


Re: Removing Player from vehicle problem - DarkLored - 03.02.2014

thank you both +reped it worked