08.07.2011, 15:28
Hey. I'm using GetClosestVehicle for my server, but it isn't working.
I've tried the one from uf.inc, here https://sampwiki.blast.hk/wiki/Useful_Functions, and my own version, here:
I have made a command, /closestcar:
But nothing happens. If I remove the if-statement check, it says "You have been put in vehicle ID: -1", which shouldn't happen as there are vehicles on my server.
I've tried the one from uf.inc, here https://sampwiki.blast.hk/wiki/Useful_Functions, and my own version, here:
pawn Код:
stock GetClosestVehicle(playerid)
{
new closestdist = 0, closestvehicle = -1;
new Float:x[2],Float:y[2],Float:z[2],distance;
for(new i; i < MAX_VEHICLES; i++)
{
GetVehiclePos(i,x[0],y[0],z[0]);
//if(x[0] == 0.0 && y[0] == 0.0 && z[0] == 0.0) return -1;
GetPlayerPos(playerid,x[1],y[1],z[1]);
distance = floatround(GetDistance(x[0],y[0],z[0],x[1],y[1],z[1]));
if(distance < closestdist) {
closestdist = distance;
closestvehicle = i;
}
}
return closestvehicle;
}
I have made a command, /closestcar:
pawn Код:
CMD:closestcar(playerid, params[]) {
#pragma unused params
new closest = GetClosestVehicle(playerid);
if(closest != -1) {
PutPlayerInVehicle(playerid, closest, 0);
SendFormattedMessage(playerid, COLOR_WHITE, "You have been put in vehicle ID: %d", closest);
}
return 1;
}