That's pretty simple...
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(!IsPlayerInAnyVehicle(playerid))
{
new
vehicleid = GetClosestVehicle(playerid);
if(vehicleid != INVALID_VEHICLE_ID)
{
new
engine,
lights,
alarm,
doors
bonnet,
boot,
objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
if(newkeys & KEY_YES) // if they pushed Y, open/close the bonnet/hood
{
if(bonnet) == 1) SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, 0, boot, objective);
else SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, 1, boot, objective);
}
else if(newkeys & KEY_NO) // if they pushed N, open/close the boot/trunk
{
if(boot) == 1) SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, 0, objective); // if the boot is opened, close it
else SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, 1, objective); // if the boot is closed, open it
}
}
}
return 1;
}
stock GetCloestVehicle(playerid)
{
new
Float:X,
Float:Y,
Float:Z,
Float:distance,
Float:lastdistance = 20.0,
vehicleid = INVALID_VEHICLE_ID;
for(new i = 0; i < MAX_VEHICLES; i++)
{
GetVehiclePos(v, X, Y, Z);
distance = GetPlayerDistanceFromPoint(playerid, X, Y, Z);
if(distance < lastdistance)
{
lastdistance = distance;
vehicleid = v;
}
}
return vehicleid;
}
I'm not sure if the GetClosestVehicle function will work or not, I just wrote that up. It looks like it will though!