Get Last 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: Get Last Vehicle (
/showthread.php?tid=452439)
Get Last Vehicle -
arjanforgames - 21.07.2013
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).
Re: Get Last Vehicle -
Threshold - 21.07.2013
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.