Quote:
Originally Posted by AdamCooper
It wont mess the other script usage of "GetPlayerNearestVehicle" ?
For example : /friskcar - Which need to check the car ID. I hope you understand my point.
I was thinking of creating new stock "GetVehicleNearestVehicle".
pawn Код:
stock GetVehicleNearestVehicle(playerid) { new closest = -1; for(new i = 0; i < MAX_VEHICLES; i++) { if(GetDistanceFromVehicleToVehicle(playerid, i) < GetDistanceFromVehicleToVehicle(playerid, closest) && closest != -1 && IsVehicleConnected(i) && GetVehicleVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) { closest = i; } if(closest == -1 && IsVehicleConnected(i)) closest = i; } return closest; } stock GetDistanceFromVehicleToVehicle(playerid, closestcarid) { new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2; new Float:tmpdis; GetPlayerPos(playerid,x1,y1,z1); GetVehiclePos(closestcarid,x2,y2,z2); tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2)); return floatround(tmpdis); }
Im giving it a test now.
// updating
Wont work it seems like the "wguns" wont go to the nearst vehicle.
|
That is a bad way to do it how about like this.
pawn Код:
stock GetVehicleNearestVehicle(playerid)
{
new Float:closestdist = 99999.0;
new Float:clostestvid;
new Float:checkdist;
new Float:x,Float:y,Float:z;
for(new i = 0; i < MAX_VEHICLES; i++)
{
GetVehiclePos(i, x, y, z);
checkdist = GetPlayerDistanceFromPoint(playerid, x, y, z);
if(checkdist < closestdist && IsVehicleConnected(i) && GetVehicleVirtualWorld(i) == GetPlayerVirtualWorld(playerid))
{
clostestvid = i;
checkdist = checkdist;
}
}
return clostestvid;
}