IsAnyVehicleInRangeOfPoint
#1

I wana check if there is any vehicle in an sphere.
Defined with x, y, z and the radius.
But I stuck on the math^^
Can somebody help me pls?
Reply
#2

Haven't tested it, but it should return 1 if any vehicle is in range and 0 if no vehicle is in range.

By the way, if you get a error/warning for the IsValidVehicle-function, you have to add at the top of your script:
pawn Код:
native IsValidVehicle(vehicleid);
pawn Код:
stock IsAnyVehicleInSphere(Float:x1, Float:y1, Float:z1, Float:radius)
{
    new Float:x2, Float:y2, Float:z2, Float:Distance;
    for(new i; i<MAX_VEHICLES; i++)
    {
        if(IsValidVehicle(i))
        {
            GetVehiclePos(i, x2, y2, z2);
            Distance = floatsqroot(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2)));            
            if(Distance <= radius) return 1;
        }
    }
    return 0;
}
Reply
#3

Thank you for your efforts but I found myself with a little bit of surfing some functions
Код:
stock Float:floatquad(Float:pointer) return floatpower(pointer,2.0);
stock Float:GetDistanceBetween2Points(Float:X1,Float:Y1,Float:Z1,Float:X2,Float:Y2,Float:Z2) return floatsqroot(floatquad(floatsub(X1,X2))+floatquad(floatsub(Y1,Y2))+floatquad(floatsub(Z1,Z2)));
And with these I made this:
Код:
stock IsAnyVehicleInRangeOfPoint(Float:rad, Float:x, Float:y, Float:z)
{
	new Float:posx, Float:posy, Float:posz;
	for(new veh = 0; veh < MAX_VEHICLES; veh++)
	{
		GetVehiclePos(veh, posx, posy, posz);
		if( GetDistanceBetween2Points(x, y, z, posx, posy, posz) <=  rad) return 1;
	}
	return 0;
}
and it also works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)