near pos
#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


Messages In This Thread
near pos - by usersamp - 30.06.2012, 21:03
Re: near pos - by .FuneraL. - 30.06.2012, 21:13
Re: near pos - by usersamp - 30.06.2012, 21:20
Re: near pos - by Vince - 30.06.2012, 22:52
AW: near pos - by Nero_3D - 01.07.2012, 01:35
Re: near pos - by [MM]RoXoR[FS] - 01.07.2012, 04:56
Re: near pos - by usersamp - 01.07.2012, 10:34

Forum Jump:


Users browsing this thread: 1 Guest(s)