SA-MP Forums Archive
Checking if a player exits a vehicle - 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: Checking if a player exits a vehicle (/showthread.php?tid=321115)



Checking if a player exits a vehicle - [WSE]Dave - 25.02.2012

Why doesn't this work?

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
    {
        if(Checkpoint[playerid] != 0) //They're doing something..
        {
            PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), 0);
        }
    }
    return true;
}



Re: Checking if a player exits a vehicle - FalconX - 25.02.2012

Quote:
Originally Posted by [WSE]Dave
Посмотреть сообщение
Why doesn't this work?

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
    {
        if(Checkpoint[playerid] != 0) //They're doing something..
        {
            PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), 0);
        }
    }
    return true;
}
Hello mate,

You can also use this for checking if player is exiting a vehicle:-

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid, ispassenger)
{
    SendClientMessage(playerid, -1, "You are going to exit the vehicle.");
    return 1;
}
or for the states, it's better and more accurate on some places:-

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if ((newstate == PLAYER_STATE_ONFOOT) && ((oldstate == PLAYER_STATE_DRIVER) || (oldstate == PLAYER_STATE_PASSENGER))) // your new state is ONFOOT and old state is when he was in the vehicle.
        // your rest of code here
        SendClientMessage(playerid, -1, "you just exited a vehicle.");
    return 1;
}
was just a fast coding, reply down if i have helped you.

-FalconX


Re: Checking if a player exits a vehicle - [WSE]Dave - 25.02.2012

Quote:
Originally Posted by ue_falconx
Посмотреть сообщение
Hello mate,

You can also use this for checking if player is exiting a vehicle:-

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid, ispassenger)
{
    SendClientMessage(playerid, -1, "You are going to exit the vehicle.");
    return 1;
}
or for the states, it's better and more accurate on some places:-

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if ((newstate == PLAYER_STATE_ONFOOT) && ((oldstate == PLAYER_STATE_DRIVER) || (oldstate == PLAYER_STATE_PASSENGER))) // your new state is ONFOOT and old state is when he was in the vehicle.
        // your rest of code here
        SendClientMessage(playerid, -1, "you just exited a vehicle.");
    return 1;
}
was just a fast coding, reply down if i have helped you.

-FalconX
This doesn't work, it still allows me to exit the vehicle, OnPlayerExitVehicle doesn't seem to work either.


Re: Checking if a player exits a vehicle - FalconX - 25.02.2012

Quote:
Originally Posted by [WSE]Dave
Посмотреть сообщение
This doesn't work, it still allows me to exit the vehicle, OnPlayerExitVehicle doesn't seem to work either.
Please can you tell me what exactly you want?

EDIT:

If you want the player not to exit out of the vehicle you could use the following:-

pawn Код:
// Top in your script
new
    n_szPlayerVehicle[MAX_PLAYERS],
    n_bSeatID[MAX_PLAYERS]
;


// OnPlayerStateChange
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if ((newstate == PLAYER_STATE_DRIVER) || (newstate == PLAYER_STATE_PASSENGER))
    {
        n_szPlayerVehicle[playerid] = GetPlayerVehicleID(playerid);
        n_bSeatID[playerid] = GetPlayerVehicleSeat(playerid);
    }

    // this stops the player to exit the vehicle.
    if ((newstate == PLAYER_STATE_ONFOOT) && ((oldstate == PLAYER_STATE_DRIVER) || (oldstate == PLAYER_STATE_PASSENGER)))
        PutPlayerInVehicle(playerid, n_szPlayerVehicle[playerid], n_bSeatID[playerid]);
        SendClientMessage(playerid, -1, "You can't exit the vehicle");

    return 1;
}
This should work (not tested btw)... Check maybe ?

-FalconX