onPlayerEnterVehicle problem
#1

Hey guys I'v got a problem with the onPlayerEnterVehicle section of the gamemode.
What iv got is:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)//click enter on vehicle
{
    if(!ispassenger)
    {
        if(IsDMVCar(vehicleid))
        {
            if(!LicenseTest[playerid])
            {
                new Float:pos[3];
                GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                SendClientMessage(playerid, COLOR_ORANGE, "You are not taking a drivers license test.");
            }
            else
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "* GPS: Finish the test by driving through all of the checkpoints on your GPS.");
                SetPlayerCheckpoint(playerid,2040.7101,-1930.1340,13.4667,5);
                SendClientMessage(playerid, COLOR_RED, "If you exit the car your test will be failed and it will have to be re-done.");
            }
        }
        else if(IsFamVehicle(vehicleid) && Fam[vehicleid] != PlayerInfo[playerid][pFam] && !IsACop(playerid))
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to a family.");
        }
        else if(IsLeoVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 1)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the SAPD faction.");
        }
        else if(IsGovVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 2)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the GOV faction.");
        }
        else if(IsNewsVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 4)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the News Agency faction.");
        }
        else if(IsTruckerVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_TRUCKER)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to Truckers.");
        }
        else if(IsSkipperVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_SKIPPER)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to Skippers.");
        }
    }
    return 1;
}
You can see what it's supposed to do, but what im trying to figure out is why it is not doing so?
Obviously if you are not a trucker or skipper and you try enter a trucker or skipper vehicle it shouldnt let you in. It doesnt work though, the only park of the code that works is the top dmv vehicle bit.
Thanks for reading guys, apreciate all the help i can get.
Reply
#2

You should add a debug message to see if it is passing through the if statement.

Like so:

pawn Код:
else if(IsLeoVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 1)
{
     printf("IsLeoVehicle passed");
//Sends a message to console saying IsLeoVehicle passed
if it does work, try this method, I usually did this when I wanted to avoid someone getting in a vehicle:

pawn Код:
new Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
SetPlayerPos(playerid, pos[0], pos[1], pos[2]);

//To...

ClearAnimations(playerid);
Actually, try what he stated below, I didn't think about that...
Reply
#3

Delete everyhting from OnPlayerEnterVehicle,and add it to OnPlayerStateChange:

pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
  if(newstate==PLAYER_STATE_DRIVER)
  {
        if(IsDMVCar(vehicleid))
        {
            if(!LicenseTest[playerid])
            {
                new Float:pos[3];
                GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                SendClientMessage(playerid, COLOR_ORANGE, "You are not taking a drivers license test.");
            }
            else
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "* GPS: Finish the test by driving through all of the checkpoints on your GPS.");
                SetPlayerCheckpoint(playerid,2040.7101,-1930.1340,13.4667,5);
                SendClientMessage(playerid, COLOR_RED, "If you exit the car your test will be failed and it will have to be re-done.");
            }
        }
        else if(IsFamVehicle(vehicleid) && Fam[vehicleid] != PlayerInfo[playerid][pFam] && !IsACop(playerid))
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to a family.");
        }
        else if(IsLeoVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 1)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the SAPD faction.");
        }
        else if(IsGovVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 2)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the GOV faction.");
        }
        else if(IsNewsVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 4)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the News Agency faction.");
        }
        else if(IsTruckerVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_TRUCKER)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to Truckers.");
        }
        else if(IsSkipperVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_SKIPPER)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to Skippers.");
        }
  }
  return 1;
}
Reply
#4

Yeah iv actually got it in the onplayerstatechange as a temp thing until i could get it working. :P
Thanks for the info though, Ill probably just delete it and keep it under state change. Thanks
Reply
#5

A problem iv found that im having doing it like this, is the /engine message still apears when, say you arent a trucker and you get kicked out of the vehicle. How would I make it so the /engine message wont appear if you
pawn Код:
if(newstate == PLAYER_STATE_DRIVER && oldstate != PLAYER_STATE_DRIVER)//inside vehicle
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        if(!engine) SendClientMessage(playerid, COLOR_WHITE, "Type {FF6347}/engine{FFFFFF} to start the vehicle.");
        if(!PlayerInfo[playerid][pCarLic]) SendClientMessage(playerid, COLOR_LIGHTRED, " You don't have a drivers license, beware of cops.");
        if(IsATowTruck(vehicleid)) SendClientMessage(playerid, COLOR_WHITE, "You can tow a vehicle using {FF6347}/tow{FFFFFF}."); //cometow
        if(IsTruckerVehicle(vehicleid))
        {  
            if(PlayerInfo[playerid][pJob] == JOB_TRUCKER || PlayerInfo[playerid][pVIPJob] == JOB_TRUCKER)
            {
                startingtruckjob[playerid] = 1;
                GameTextForPlayer(playerid, "~g~Drive to the ~r~marker~g~ to~n~get a trailer",5000,3);
                TogglePlayerDynamicCP(playerid, Checkpoints[0],1);//enable trailer depot marker
                TruckTimer[playerid] = SetTimerEx("IsTrailer",1000,true,"i",playerid);
            }
            else
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to Truckers.");
                return 0;
            }
        }
        else if(IsSkipperVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_SKIPPER && PlayerInfo[playerid][pVIPJob] != JOB_SKIPPER)
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to Skippers.");
            return 0;
        }
    }[/
Reply
#6

Look at the last part I added:

pawn Код:
if(newstate == PLAYER_STATE_DRIVER && oldstate != PLAYER_STATE_DRIVER)//inside vehicle
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    if(!engine) SendClientMessage(playerid, COLOR_WHITE, "Type {FF6347}/engine{FFFFFF} to start the vehicle.");
    if(!PlayerInfo[playerid][pCarLic]) SendClientMessage(playerid, COLOR_LIGHTRED, " You don't have a drivers license, beware of cops.");
    if(IsATowTruck(vehicleid)) SendClientMessage(playerid, COLOR_WHITE, "You can tow a vehicle using {FF6347}/tow{FFFFFF}."); //cometow
    if(IsTruckerVehicle(vehicleid))
    {
        if(PlayerInfo[playerid][pJob] == JOB_TRUCKER || PlayerInfo[playerid][pVIPJob] == JOB_TRUCKER)
        {
            startingtruckjob[playerid] = 1;
            GameTextForPlayer(playerid, "~g~Drive to the ~r~marker~g~ to~n~get a trailer",5000,3);
            TogglePlayerDynamicCP(playerid, Checkpoints[0],1);//enable trailer depot marker
            TruckTimer[playerid] = SetTimerEx("IsTrailer",1000,true,"i",playerid);
        }
        else
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to Truckers.");
            return 0;
        }
    }
    else if(IsSkipperVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_SKIPPER && PlayerInfo[playerid][pVIPJob] != JOB_SKIPPER)
    {
        RemovePlayerFromVehicle(playerid);
        SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to Skippers.");
        return 0;
    }
}
if(newstate == PLAYER_STATE_ONFOOT && oldstate != PLAYER_STATE_ONFOOT)
{
    //whatever you want to do when the  player is now on foot
}
At the end.
Reply
#7

Im confuzed sorry. :/ That runs when the player is on foot but the engine text runs before it checks if it is a trucker / skipper vehicle.
Im trying to make it so it doesnt say "type /engine to start the vehicle" unless you are in a vehicle your able to drive. Im sorry if im not making sence :/
Reply
#8

Use OnPlayerEnterVehicle to show the text.

This function is called when the plyer is IN the vehicle, not as they enter it.

Using the code you provided below, it checks if the player pressed the enter vehicle key and is now becoming the driver.
Reply
#9

Okay ill check it out, Thanks
But can you tell me why in this code it doesnt progress past trucker:
pawn Код:
if(newstate == PLAYER_STATE_DRIVER && oldstate != PLAYER_STATE_DRIVER)//inside vehicle
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        if(!engine) SendClientMessage(playerid, COLOR_WHITE, "Type {FF6347}/engine{FFFFFF} to start the vehicle.");
        if(!PlayerInfo[playerid][pCarLic]) SendClientMessage(playerid, COLOR_LIGHTRED, " You don't have a drivers license, beware of cops.");
        if(IsATowTruck(vehicleid)) SendClientMessage(playerid, COLOR_WHITE, "You can tow a vehicle using {FF6347}/tow{FFFFFF}."); //cometow
        if(IsTruckerVehicle(vehicleid))
        {  
            if(PlayerInfo[playerid][pJob] != JOB_TRUCKER && PlayerInfo[playerid][pVIPJob] != JOB_TRUCKER)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_ORANGE, "This vehicle is restricted to Truckers.");
            }
            else
            {
                startingtruckjob[playerid] = 1;
                GameTextForPlayer(playerid, "~y~Drive to the ~r~marker~y~ to~n~get a trailer",5000,3);
                TogglePlayerDynamicCP(playerid, Checkpoints[0],1);//enable trailer depot marker
                TruckTimer[playerid] = SetTimerEx("IsTrailer",1000,true,"i",playerid);
            }
        }
        else if(IsSkipperVehicle(vehicleid))
        {
            if(PlayerInfo[playerid][pJob] != JOB_SKIPPER && PlayerInfo[playerid][pVIPJob] != JOB_SKIPPER)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_ORANGE, "This vehicle is restricted to Skippers.");
            }
            else
            {
                //StartingSkipperJob[playerid] = 1;
                GameTextForPlayer(playerid, "~y~Drive to the ~r~marker~y~ to~n~deliver the packages",5000,3);
            }
        }
        else if(IsFamVehicle(vehicleid) && Fam[vehicleid] != PlayerInfo[playerid][pFam] && !IsACop(playerid))
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to a family.");
        }
        else if(IsLeoVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 1)
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the SAPD faction.");
        }
        else if(IsGovVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 2)
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the GOV faction.");
        }
        else if(IsNewsVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 4)
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_ORANGE, " This vehicle is restricted to the News Agency faction.");
        }
    }
It never gets past the first trucker if statement. So it never checks if the player is inside a skipper boat or gov vehicle or anytihng. :/
Reply
#10

found out the problem was my functions. I set them up incorrectly. My bad, everything working how it should be now. thanks guys/
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)