It's a bit hard to explain with words, so i will just post basically the method i use in my gamemode:
Define points at the top of script:
pawn Код:
enum
{
INVALID_POINT = -1,
POINT_1,
POINT_2,
POINT_3
}
static Float:Points[][] =
{
{ 10.0, 10.0, 10.0 }, //POINT_1
{ 0.0, 0.0, 0.0 }, //POINT_2
{ -10.0, -10.0, -10.0 } //etc
};
Then, the main function, which return an index of the Points array, and you can get the distance in 'd':
pawn Код:
GetClosestPoint(Float:x, Float:y, Float:z, &Float:d = 0.0)
{
new
c = INVALID_POINT,
Float:x2,
Float:y2,
Float:z2,
Float:d2 = 70000.0
;
for (new p = 0; p < sizeof Points; p ++)
{
x2 = x - Points[p][0];
x2 *= x2;
y2 = y - Points[p][1];
y2 *= y2;
z2 = z - Points[p][2];
z2 *= z2;
d = floatsqroot(x2 + y2 + z2);
if (d < d2)
{
d2 = d;
c = p;
}
}
d = d2;
return c;
}
pawn Код:
GetPlayerClosestPoint(playerid)
{
new
Float:x,
Float:y,
Float:z
;
GetPlayerPos(playerid, x, y, z);
return GetClosestPoint(x, y, z);
}
So basically now all you have to do is:
pawn Код:
switch (GetPlayerClosestPoint(playerid))
{
case POINT_1 : //bla
case POINT_2 : //etc
}