IsPlayerInVehicle does not work
#1

I have the following code:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)

{
    if(IsPlayerInVehicle(playerid, 578) == 1)
	{
		SendClientMessage(playerid, COLOR_WHITE, "-----------------------------Trucker-Job------------------------------");
		SendClientMessage(playerid, COLOR_WHITE, "Use /starttruck to start the truckersjob. Use /truckhelp for more info");
		SendClientMessage(playerid, COLOR_WHITE, "----------------------------------------------------------------------");
		return 1;
	}
	else return 0;
}
When I enter the vehicle nothing happens. I have tried this too:

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)

{
    if(!IsPlayerInVehicle(playerid, 578) == 1)
	{
		SendClientMessage(playerid, COLOR_WHITE, "-----------------------------Trucker-Job------------------------------");
		SendClientMessage(playerid, COLOR_WHITE, "Use /starttruck to start the truckersjob. Use /truckhelp for more info");
		SendClientMessage(playerid, COLOR_WHITE, "----------------------------------------------------------------------");
		return 1;
	}
	else return 0;
}
It works in every vehicle now, and outside the vehicle too if you add commands.
Reply
#2

It does work, you're just using it wrong. IsPlayerInVehicle checks if a player is in a vehicle with a specific, unique, id. Not if he's in a car with a non-unique model id. You need to use GetVehicleModel.
Reply
#3

try this:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 578)
        {
        SendClientMessage(playerid, COLOR_WHITE, "-----------------------------Trucker-Job------------------------------");
        SendClientMessage(playerid, COLOR_WHITE, "Use /starttruck to start the truckersjob. Use /truckhelp for more info");
        SendClientMessage(playerid, COLOR_WHITE, "----------------------------------------------------------------------");
        }
    }
    return 1;
}
or This:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(GetVehicleModel(vehicleid) == 578)
    {
        SendClientMessage(playerid, COLOR_WHITE, "-----------------------------Trucker-Job------------------------------");
        SendClientMessage(playerid, COLOR_WHITE, "Use /starttruck to start the truckersjob. Use /truckhelp for more info");
        SendClientMessage(playerid, COLOR_WHITE, "----------------------------------------------------------------------");
    }
    return 1;
}
Reply
#4

It's better to use OnPlayerStateChange callback

OnPlayerEnterVehicle callback:
Quote:

This callback is called when a player starts to enter a vehicle, meaning the player is not in vehicle yet at the time this callback is called.

If two players press enter to enter the same vehicle at the same time and they start to enter in it, the message will be shown to both.
Reply
#5

This one helped me the most thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)