16.10.2010, 16:18
It turns out you can RepairVehicle() without a driver, here is a thing that works. Its a little clumsy and unoptimized, but you can probably compare it with your script to get a solution to your problem.
I left the printf commands that I used for testing in there, you can remove them if you like.
feel free to add your own messages for success / failure and whatnot.
pawn Код:
#include <a_samp>
#include <zcmd>
CMD:fixtest(playerid,params[])
{
new veh = GetPlayerVehicleID(playerid);
if(veh)
{
RepairVehicle(veh);
printf("inveh %d",veh);
return 1;
}
veh = GetClosestVehicleID(playerid);
if(veh)
{
RepairVehicle(veh);
printf("nearveh %d",veh);
return 1;
}
return 1;
}
GetClosestVehicleID(playerid)
{
new Float:min_dist = 100.0;
new Float:dist;
new Float:vehx,Float:vehy,Float:vehz;
new Float:px,Float:py,Float:pz;
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,px,py,pz);
new close_vehid;
for(new i = 1; i < MAX_VEHICLES;i++)
{
if(GetVehicleModel(i) > 0)
{
GetVehiclePos(i,vehx,vehy,vehz);
x = px - vehx;
y = py - vehy;
z = pz - vehz;
dist = floatsqroot((x * x) + (y * y) + (z * z));
if(dist < min_dist)
{
min_dist = dist;
close_vehid = i;
}
}
}
return close_vehid;
}
feel free to add your own messages for success / failure and whatnot.