04.02.2011, 07:02
Try getting the nearest vehicle ID, I'll find you the stock...
Paste that on the bottom of your code... Then change the code to
The seat however, I don't know how to get out of it...
pawn Code:
stock GetNearestVehicle(playerid, Float:dis)
{
new Float:X, Float:Y, Float:Z;
if(GetPlayerPos(playerid, X, Y, Z))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VX, VY, VZ))
{
VX -= X, VY -= Y, VZ -= Z;
temp = VX * VX + VY * VY + VZ * VZ;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 0.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}
pawn Code:
if ( (newkeys & KEY_SECONDARY_ATTACK) && IsPlayerInAnyVehicle(playerid) )
{
new nearest = GetNearestVehicle(playerid, 5.0);
PutPlayerInVehicle(playerid, nearest, GetPlayerSeat(playerid));
}