near pos
#1

how i can get the closest pos of array?
new Float:Pos[ARRAY][3];

Pos[0][0] = float; Pos[0][1] = float; Pos[0][2]= float;
Pos[1][0] = float; Pos[1][1] = float; Pos[1][2]= float;
Pos[2][0] = float; Pos[2][1] = float; Pos[2][2]= float;

Please thanks!
Reply
#2

Quote:
Originally Posted by usersamp
Посмотреть сообщение
how i can get the closest pos of array?
new Float:Pos[ARRAY][3];

Pos[0][0] = float; Pos[0][1] = float; Pos[0][2]= float;
Pos[1][0] = float; Pos[1][1] = float; Pos[1][2]= float;
Pos[2][0] = float; Pos[2][1] = float; Pos[2][2]= float;

Please thanks!
pawn Код:
new Float:Position[3];
//Using : Position[0], Position[1], Position[2]
Reply
#3

No, my array is to long..
is a list of objects, and i need know what is the object nearest the player
Reply
#4

Loop and GetDistanceBetweenPoints.

pawn Код:
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
    x1 -= x2;
    y1 -= y2;
    z1 -= z2;
    return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}
Reply
#5

Use a streamer and just check all objects which are streamed for the player
And use GetPlayerDistanceFromPoint
Reply
#6

I think you mean this

pawn Код:
new Pos[100][3];//where 100 is the no of objects?

stock Float:GetDistance(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2) //By Gabriel "Larcius" Cordes
{
    return floatadd(floatadd(floatsqroot(floatpower(floatsub(x1,x2),2)),floatsqroot(floatpower(floatsub(y1,y2),2))),floatsqroot(floatpower(floatsub(z1,z2),2)));
}

//Now whereever you need pos

new i,min,id;
new Float:x,Float:y,Float:z;
GetPlyerPos(playerid,x,y,z);
min=999999;//ofcourse we assume it is very far.
id = -1;//INVALID
for(i=0;i<=100;++i)//Loop to go through all objects
{
    if(IsValidObject(i))
    {
    if(GetDistance(x,y,z,Pos[i][0],Pos[i][1],Pos[i][2])<min){
    min=GetDistance(x,y,z,Pos[i][0],Pos[i][1],Pos[i][2]);
    id = i;}
    }
}
//After loop id will be closed object.
//Do whatever you want to do to object here.
Reply
#7

Quote:
Originally Posted by [MM]RoXoR[FS]
Посмотреть сообщение
I think you mean this

pawn Код:
new Pos[100][3];//where 100 is the no of objects?

stock Float:GetDistance(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2) //By Gabriel "Larcius" Cordes
{
    return floatadd(floatadd(floatsqroot(floatpower(floatsub(x1,x2),2)),floatsqroot(floatpower(floatsub(y1,y2),2))),floatsqroot(floatpower(floatsub(z1,z2),2)));
}

//Now whereever you need pos

new i,min,id;
new Float:x,Float:y,Float:z;
GetPlyerPos(playerid,x,y,z);
min=999999;//ofcourse we assume it is very far.
id = -1;//INVALID
for(i=0;i<=100;++i)//Loop to go through all objects
{
    if(IsValidObject(i))
    {
    if(GetDistance(x,y,z,Pos[i][0],Pos[i][1],Pos[i][2])<min){
    min=GetDistance(x,y,z,Pos[i][0],Pos[i][1],Pos[i][2]);
    id = i;}
    }
}
//After loop id will be closed object.
//Do whatever you want to do to object here.
Yes Man thanks!

I create my Object here, right?

if(IsValidObject(i))
{
if(GetDistance(x,y,z,Pos[i][0],Pos[i][1],Pos[i][2])<min){
min=GetDistance(x,y,z,Pos[i][0],Pos[i][1],Pos[i][2]);
id = i; }
}

HERE

PS:
+Rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)