04.06.2013, 08:08
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".
Im giving it a test now.
// updating
Wont work it seems like the "wguns" wont go to the nearst vehicle.
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);
}
// updating
Wont work it seems like the "wguns" wont go to the nearst vehicle.