20.12.2011, 14:22
Quote:
Код:
CMD:openbonnet(playerid, params[]) { new vid; new engine,lights,alarm,doors,bonnet,boot,objective; GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective); SetVehicleParamsEx(vid,engine,lights,alarm,doors,1,boot,objective); return 1; } |
when a player is in the car you want it then you can use
vid = GetPlayerVehicleID(playerid);
else assign an id to the vehicle at creation for later use.
another way is to loop all vehicles and compare distances and pick the closest one to your X Y Z point.
(eg:
pawn Код:
getPlayerClosestVehicle(playerid, Float:maximumDistance=-1.0)
{
if(!IsPlayerConnected(playerid))
return -1;
new
closestVehicle = -1,
Float:closestDistance = -1.0,
Float:currentDistance = 0.0,
Float:x0, Float:y0, Float:z0,
Float:x1, Float:y1, Float:z1;
GetPlayerPos(playerid, x0, y0, z0);
for(new checkVehicle; checkVehicle < MAX_VEHICLES; checkVehicle++)
{
if(!GetVehicleModel(checkVehicle)) // jeżeli pojazd o ID 'checkVehicle' ma model o ID '0' to pomijamy go
continue;
GetVehiclePos(checkVehicle, x1, y1, z1);
currentDistance = floatsqroot(floatadd(floatadd(floatpower(floatsub(x0, x1), 2), floatpower(floatsub(y0, y1), 2)), floatpower(floatsub(z0, z1), 2)));
if((maximumDistance == -1.0 || currentDistance < maximumDistance) && (closestDistance == -1.0 || currentDistance < closestDistance))
{
closestDistance = currentDistance;
closestVehicle = checkVehicle;
}
}
return closestVehicle;
}