near pos -
usersamp - 30.06.2012
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!
Re: near pos -
.FuneraL. - 30.06.2012
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]
Re: near pos -
usersamp - 30.06.2012
No, my array is to long..
is a list of objects, and i need know what is the object nearest the player
Re: near pos -
Vince - 30.06.2012
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));
}
AW: near pos -
Nero_3D - 01.07.2012
Use a streamer and just check all objects which are streamed for the player
And use
GetPlayerDistanceFromPoint
Re: near pos -
[MM]RoXoR[FS] - 01.07.2012
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.
Re: near pos -
usersamp - 01.07.2012
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