Checking if vehicle is still occupied after exiting it (urgent)
#1

I was wondering if there is anyway to check if the vehicle is still occupied when the driver has exited it.

example: 2 people in a car the driver gets out. Can i now check after that driver has came out fully if the vehicle is still occupied.


I cannot use OnPlayerExitVehicle as this is called when actually exiting. I need something like OnPlayerHasExitedVehicle.


Darren
Reply
#2

You should code it within this callback.

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT ) // Player entered a vehicle as a driver
    {
        //Your code
    }
    return 1;
}
Reply
#3

Would this work also in OnPlayerExitVehicle.

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
		if(IsPlayerConnected(i))
		{
			if(IsPlayerInVehicle(i, vehicleid)) 
			{
				if(GetPlayerState(i) != PLAYER_STATE_DRIVER) 
				{
					return 1;
				}
			}
		}
		
    }
Where it returns 1 it stops the below code which happens to be a parking code ive got which i don't want initiated if a player is still in vehicle.
Reply
#4

Quote:
Originally Posted by dazman14
Посмотреть сообщение
Would this work also in OnPlayerExitVehicle.

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
		if(IsPlayerConnected(i))
		{
			if(IsPlayerInVehicle(i, vehicleid)) 
			{
				if(GetPlayerState(i) != PLAYER_STATE_DRIVER) 
				{
					return 1;
				}
			}
		}
		
    }
Where it returns 1 it stops the below code which happens to be a parking code ive got which i don't want initiated if a player is still in vehicle.
You don't have to loop for the playerid... You already have it in the callback as a parameter.
And it may work, yes... But the one that @Ballu Miaa stated is more efficient
Reply
#5

Quote:
Originally Posted by dazman14
Посмотреть сообщение
Would this work also in OnPlayerExitVehicle.

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
		if(IsPlayerConnected(i))
		{
			if(IsPlayerInVehicle(i, vehicleid)) 
			{
				if(GetPlayerState(i) != PLAYER_STATE_DRIVER) 
				{
                                        return 1;
				}
			}
		}
		
    }
Where it returns 1 it stops the below code which happens to be a parking code ive got which i don't want initiated if a player is still in vehicle.
Quote:
Originally Posted by Ahmad45123
Посмотреть сообщение
You don't have to loop for the playerid... You already have it in the callback as a parameter.
And it may work, yes... But the one that @Ballu Miaa stated is more efficient
Yeah i guess therefore i attempted to code something you want. It is untested code and run some tests that it does the job or not?

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
   if(IsPlayerConnected(playerid))
   {
        if(IsPlayerInVehicle(playerid, vehicleid))
        {
            if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
            {
                        //Your code.
                    return 1;
            }
        }
    }
    return 1;
}
Reply
#6

pawn Код:
GetPlayersInVehicle(vehicleid)
{
    new players_in_veh;
    for(new playerid; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid) && GetPlayerVehicleID(playerid) == vehicleid)
            players_in_veh ++;
    }
    return players_in_veh;
}

OnPlayerHasExitedVehicle(playerid, vehicleid)
{
    if(GetPlayersInVehicle(vehicleid) > 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "DEBUG: The vehicle you left is still not empty.");
        // Put your code here
    }
    else
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "DEBUG: The vehicle you left is now empty.");
        // Put your code here
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    static
        recent_vehicleid[MAX_PLAYERS]
    ;

    switch(newstate)
    {
        case PLAYER_STATE_DRIVER, PLAYER_STATE_PASSENGER:
            recent_vehicleid[playerid] = GetPlayerVehicleID(playerid);
    }
    switch(oldstate)
    {
        case PLAYER_STATE_DRIVER, PLAYER_STATE_PASSENGER:
        {
            OnPlayerHasExitedVehicle(playerid, recent_vehicleid[playerid]);
            recent_vehicleid[playerid] = 0;
        }
    }
}
It sounds like you want something like this?
Reply
#7

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
pawn Код:
GetPlayersInVehicle(vehicleid)
{
    new players_in_veh;
    for(new playerid; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid) && GetPlayerVehicleID(playerid) == vehicleid)
            players_in_veh ++;
    }
    return players_in_veh;
}

OnPlayerHasExitedVehicle(playerid, vehicleid)
{
    if(GetPlayersInVehicle(vehicleid) > 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "DEBUG: The vehicle you left is still not empty.");
        // Put your code here
    }
    else
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "DEBUG: The vehicle you left is now empty.");
        // Put your code here
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    static
        recent_vehicleid[MAX_PLAYERS]
    ;

    switch(newstate)
    {
        case PLAYER_STATE_DRIVER, PLAYER_STATE_PASSENGER:
            recent_vehicleid[playerid] = GetPlayerVehicleID(playerid);
    }
    switch(oldstate)
    {
        case PLAYER_STATE_DRIVER, PLAYER_STATE_PASSENGER:
        {
            OnPlayerHasExitedVehicle(playerid, recent_vehicleid[playerid]);
            recent_vehicleid[playerid] = 0;
        }
    }
}
It sounds like you want something like this?
Seems nice! I think thats what he wants too. Good job! Rep+4. Hope it helps him!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)