Get Last Vehicle
#1

Is it possible to get the last vehicle the player has entered?
So I can use it to see if the player is near the vehicle. And if he is he can like /car trunk or something.
I need to know if he's close to the vehicle (a specific vehicle).
Reply
#2

pawn Код:
new lastvehicle[MAX_PLAYERS]; //Under your #includes etc. at the top of your script

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    //if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) // Use this is you want for passenger + driver seats.
    if(newstate == PLAYER_STATE_DRIVER) //If the player enters the car as a driver.
    {
        lastvehicle[playerid] = GetPlayerVehicleID(playerid);
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    lastvehicle[playerid] = INVALID_VEHICLE_ID;
    return 1;
}

public OnPlayerConnect(playerid)
{
    lastvehicle[playerid] = INVALID_VEHICLE_ID;
    return 1;
}

CMD:mycommand(playerid, params[]) //Example command: /mycommand
{
    if(lastvehicle[playerid] == INVALID_VEHICLE_ID) return SendClientMessage(playerid, -1, "You have not entered a vehicle yet.");
    if(PlayerIsNotCloseTo(lastvehicle[playerid])
    {
        SendClientMessage(playerid, -1, "You aren't even near the damn thing...");
    }
    else
    {
        SendClientMessage(playerid, -1, "You found your car.");
    }
    return 1;
}
This is merely an example, and the given code is less than likely to actually perform as expected. However the code is accurate and will work on a regular basis.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)