OnPlayerEnterVehicle help
#1

I'm trying to make it so when a player enters a car but has no license he gets thrown in the air. Everything works but the problem was, whenever someone pressed G on the car he also was getting the no license message.
I decided to use the
Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER
function but that didn't work either, it just messed my code up.

This is my code.
Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
	new vmodel = GetVehicleModel(vehicleid);
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
	if(pInfo[playerid][pLic1] == 1)
	{
		if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		{
			if(pInfo[playerid][pGroup] == 0 && cInfo[vehicleid][cGroup] > 0)
			{
				SetPlayerPos(playerid, x, y, z+3);
				if(cInfo[vehicleid][cGroup] == 1)
				{
					SendClientMessage(playerid, -1, "You are not part of Los Santos Police Department.");
				}
			}
			else if(pInfo[playerid][pGroupRank] < cInfo[vehicleid][cRank])
			{
				new rank = cInfo[vehicleid][cRank];
				new string[256];
				format(string, sizeof(string), "You must be a rank %d police officer to drive this car.", rank);
				SendClientMessage(playerid, -1, string);
			}
		}
		else return 0;
	}
	else
	{
		if(vmodel == 481 || vmodel == 510 || vmodel == 509)
		{
			new engine, lights, alarm, doors, bonnet, boot, objective;
			GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
			SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective);
		}
		else if(vmodel == 462)
		{
			return 0;
		}
		else
		{
			if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
			{
				SetPlayerPos(playerid, x, y, z+3);
				SendClientMessage(playerid, -1, "You don't have a drivings license, a checkpoint has been set on your map.");
				SetPlayerCheckpoint(playerid, 1219.1997,-1811.9343,16.5938, 5);
				return 1;
			}
			else return 0;
		}
	}
	return 1;
}
How do I fix this?
Reply
#2

Try using OnPlayerStateChange instead of OnPlayerEnterVehicle, it might help.

Edit: Also a little bit of a tip, I'd use RemovePlayerFromVehicle function instead of teleporting them.
Reply
#3

See how this callback should looks
https://sampwiki.blast.hk/wiki/OnPlayerEnterVehicle
Reply
#4

Quote:
Originally Posted by Rufio
Посмотреть сообщение
Try using OnPlayerStateChange instead of OnPlayerEnterVehicle, it might help.

Edit: Also a little bit of a tip, I'd use RemovePlayerFromVehicle function instead of teleporting them.
But I don't want them to be able to enter the car.
Reply
#5

Quote:
Originally Posted by danielpalade
Посмотреть сообщение
But I don't want them to be able to enter the car.
Uhm. Why wouldn't you want them to be able to enter the car? I am afraid there is no way of detecting if a player wants to enter the driver side of a vehicle, atleast it is what I know, correct me if I am wrong hence why I told you to use OnPlayerStateChange.

Edit: The issue with your code is OnPlayerEnterVehicle is called when a player starts entering a vehicle therefore his state won't be changed to a passenger or a driver, so getplayerstate won't work at all.
Reply
#6

Hmm.. If you wan't to make them unable to enter the vehicle, you could do it by one way, is to clearing animations.

PHP код:
public OnPlayerEnterVehicle(playeridvehicleid)
{
    new 
vmodel GetVehicleModel(vehicleid);
    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);
    if(
pInfo[playerid][pLic1] == 1)
    {
        if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            if(
pInfo[playerid][pGroup] == && cInfo[vehicleid][cGroup] > 0)
            {
                
SetPlayerPos(playeridxyz+3);
                if(
cInfo[vehicleid][cGroup] == 1)
                {
                    
SendClientMessage(playerid, -1"You are not part of Los Santos Police Department.");
                }
            }
            else if(
pInfo[playerid][pGroupRank] < cInfo[vehicleid][cRank])
            {
                new 
rank cInfo[vehicleid][cRank];
                new 
string[256];
                
format(stringsizeof(string), "You must be a rank %d police officer to drive this car."rank);
                
SendClientMessage(playerid, -1string);
            }
        }
        else return 
0;
    }
    else
    {
        if(
vmodel == 481 || vmodel == 510 || vmodel == 509)
        {
            new 
enginelightsalarmdoorsbonnetbootobjective;
            
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
            
SetVehicleParamsEx(vehicleidVEHICLE_PARAMS_ONlightsalarmdoorsbonnetbootobjective);
        }
        else if(
vmodel == 462)
        {
            return 
0;
        }
        else
        {
            if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                
SetPlayerPos(playeridxyz+3);
                  
ClearAnimations(playerid); // Edited
                        
SendClientMessage(playerid, -1"You don't have a drivings license, a checkpoint has been set on your map.");
                
SetPlayerCheckpoint(playerid1219.1997,-1811.9343,16.59385);
                return 
1;
            }
            else return 
0;
        }
    }
    return 
1;

Reply
#7

I'm not sure what SA:MP server version you're using, but if it's the latest, you're missing the ispassenger parameter.

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
With that, use it instead of GetPlayerState (as that won't work with OnPlayerEnterVehicle afaik), so just replace:

Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
with

Код:
if(ispassenger == 0)
If that doesn't work, try this bit of code:

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(ispassenger == 0)
	{
		if(pInfo[playerid][pLic1] == 0)
		{
			SetPlayerPos(playerid, x, y, z+3);
			SendClientMessage(playerid, -1, "You do not have a driver license. A checkpoint has been set on your map.");
			SetPlayerCheckpoint(playerid, 1219.1997,-1811.9343,16.5938, 5);
			return 1;
		}
		if(pInfo[playerid][pLic1] == 1)
		{
			if(pInfo[playerid][pGroup] == 0 && cInfo[vehicleid][cGroup] > 0)
			{
				SetPlayerPos(playerid, x, y, z+3);
				if(cInfo[vehicleid][cGroup] == 1)
				{
					SendClientMessage(playerid, -1, "You are not part of Los Santos Police Department.");
				}
			}
			if(pInfo[playerid][pGroupRank] < cInfo[vehicleid][cRank])
			{
				new rank = cInfo[vehicleid][cRank];
				new string[256];
				format(string, sizeof(string), "You must be a rank %d police officer to drive this car.", rank);
				SendClientMessage(playerid, -1, string);
			}
			if(vmodel == 481 || vmodel == 510 || vmodel == 509)
			{
				new engine, lights, alarm, doors, bonnet, boot, objective;
				GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
				SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective);
			}
			if(vmodel == 462)
			{
				return 0;
			}
			return 1;
		}
	}
	return 1;
}
Let know if that works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)