Closest Vehicle
#1

How could I target the closest vehicle to me? Example: I type /plate and it gets the closest vehicle's plate.
Reply
#2

i do it like this:

Код:
	if(newkeys == KEY_FIRE)
	{
	    if(!IsPlayerInAnyVehicle(playerid)) return 1;
		new v,Float:d=10.0,vehicleid;
		vehicleid=GetPlayerVehicleID(playerid);
		if(GetVehicleModel(vehicleid) != 525) return 1;
		if(IsTrailerAttachedToVehicle(vehicleid)) return DetachTrailerFromVehicle(vehicleid);
	    for(new i=0;i<MAX_VEHICLES;i++)
	    {
	    new Float:t;
		t=GetDistanceBetweenVehicles(vehicleid,i);
		if(t<d && i != vehicleid)
		    {
		    d=t;
		    v=i;
		    }
		}
		AttachTrailerToVehicle(v,GetPlayerVehicleID(playerid));
	}


stock GetDistanceBetweenVehicles(vehicleid,vehicleid2)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    GetVehiclePos(vehicleid,x1,y1,z1);
    GetVehiclePos(vehicleid2,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);
}
well i use it for towing but you can just get an idea with that. GL
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)