Checking What Co-ords are Closest to a Player. -
Ciarannn - 22.02.2015
Title says it all.
How do I cycle through lets say 8 co-ordinates and check what co-ordinate the player is closest to?
Re: Checking What Co-ords are Closest to a Player. -
Crayder - 22.02.2015
pawn Код:
new shortest=-1, Float:shortdistance=-1;
for(new x; x<8; x++)
{
if(GetPlayerDistanceFromPoint(playerid, pos[x][PosX], pos[x][PosY], pos[x][PosZ]) < shortdistance)
{
shortest = x;
shortdistance = GetPlayerDistanceFromPoint(playerid, pos[x][PosX], pos[x][PosY], pos[x][PosZ]);
}
}
Wrote quickly but you should get the idea. I typed this on my iPad so it's just a representation.
Re: Checking What Co-ords are Closest to a Player. -
Ciarannn - 22.02.2015
Quote:
Originally Posted by Crayder
pawn Код:
new shortest=-1, Float:shortdistance=-1; for(new x; x<8; x++) { if(GetPlayerDistanceFromPoint(playerid, pos[x][PosX], pos[x][PosY], pos[x][PosZ]) < shortdistance) { shortest = x; shortdistance = GetPlayerDistanceFromPoint(playerid, pos[x][PosX], pos[x][PosY], pos[x][PosZ]); } }
Wrote quickly but you should get the idea. I typed this on my iPad so it's just a representation.
|
I don't quite understand what this code does, could you compare these checkpoints for me?
2194.9402,1991.0087,12.2969
1937.5569,2307.2969,10.8203
2452.4729,2065.1914,10.8203
2546.5164,1972.6677,10.8203
2884.5542,2454.0464,11.0690
2117.5156,896.7753,11.1797
Re: Checking What Co-ords are Closest to a Player. -
Crayder - 22.02.2015
pawn Код:
new Float:Points[6][3];
{
{2194.9402,1991.0087,12.2969},
{1937.5569,2307.2969,10.8203},
{2452.4729,2065.1914,10.8203},
{2546.5164,1972.6677,10.8203},
{2884.5542,2454.0464,11.0690},
{2117.5156,896.7753,11.1797}
}, shortest=-1, Float:shortdistance=-1;
for(new x; x<6; x++)
{
if(GetPlayerDistanceFromPoint(playerid, Points[x][PosX], Points[x][PosY], Points[x][PosZ]) < shortdistance)
{
shortest = x;
shortdistance = GetPlayerDistanceFromPoint(playerid, Points[x][PosX], Points[x][PosY], Points[x][PosZ]);
}
}
Re: Checking What Co-ords are Closest to a Player. -
Ciarannn - 22.02.2015
Quote:
Originally Posted by Crayder
pawn Код:
new Float:Points[6][3]; { {2194.9402,1991.0087,12.2969}, {1937.5569,2307.2969,10.8203}, {2452.4729,2065.1914,10.8203}, {2546.5164,1972.6677,10.8203}, {2884.5542,2454.0464,11.0690}, {2117.5156,896.7753,11.1797} }, shortest=-1, Float:shortdistance=-1; for(new x; x<6; x++) { if(GetPlayerDistanceFromPoint(playerid, Points[x][PosX], Points[x][PosY], Points[x][PosZ]) < shortdistance) { shortest = x; shortdistance = GetPlayerDistanceFromPoint(playerid, Points[x][PosX], Points[x][PosY], Points[x][PosZ]); } }
|
Thanks man.
Re: Checking What Co-ords are Closest to a Player. -
Ciarannn - 25.02.2015
This is not working, I tried it but I'm just getting errors. This is what I have:
Top of Script:
pawn Код:
new Float:GPSBANKS[][3] =
{
{2436.6328,2376.5159,10.8203},
{-179.1866,1133.1125,19.7422},
{-828.0347,1504.3336,19.8416},
{-1530.9633,2591.6548,55.8359},
{-227.2883,2711.7888,62.9766},
{2085.6655,2054.9348,11.0579}
};
Code with the errors:
pawn Код:
new shortest=-1, Float:shortdistance=-1;
for(new x; x<6; x++)
{
if(GetPlayerDistanceFromPoint(playerid, GPSBANKS[x][PosX], GPSBANKS[x][PosY], GPSBANKS[x][PosZ]) < shortdistance) //line 28785
{
shortest = x; //line 28787
shortdistance = GetPlayerDistanceFromPoint(playerid, GPSBANKS[x][PosX], GPSBANKS[x][PosY], GPSBANKS[x][PosZ]); //line 28788
SetPlayerCheckpoint(playerid, PosX, PosY, PosZ, 7.0); //line 28789
}
}
Errors:
pawn Код:
C:\Users\Ciarannn\Desktop\LVRP\gamemodes\bone.pwn(28785) : error 017: undefined symbol "PosX"
C:\Users\Ciarannn\Desktop\LVRP\gamemodes\bone.pwn(28788) : error 017: undefined symbol "PosX"
C:\Users\Ciarannn\Desktop\LVRP\gamemodes\bone.pwn(28789) : error 017: undefined symbol "PosX"
C:\Users\Ciarannn\Desktop\LVRP\gamemodes\bone.pwn(28787) : warning 204: symbol is assigned a value that is never used: "shortest"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
Can someone shed some light?
Re: Checking What Co-ords are Closest to a Player. -
ball - 25.02.2015
Код:
new shortest = -1, Float:shortdistance= 100.0, Float:distance;
for(new x; x != sizeof GPSBANKS; x++)
{
if((distance = GetPlayerDistanceFromPoint(playerid, GPSBANKS[x][0], GPSBANKS[x][1], GPSBANKS[x][2])) < shortdistance) //line 28785
{
shortest = x;
shortdistance = distance;
}
if(shortest != -1) SetPlayerCheckpoint(playerid, GPSBANKS[shortest][0], GPSBANKS[shortest][1], GPSBANKS[shortest][2], 7.0);
}
Should work, figure it out on your own next time, not only "give code".
Re: Checking What Co-ords are Closest to a Player. -
Schneider - 25.02.2015
pawn Код:
new shortest=-1, Float:shortdistance=9999.9, Float:distance;
for(new x; x<6; x++)
{
distance = GetPlayerDistanceFromPoint(playerid, GPSBANKS[x][0], GPSBANKS[x][1], GPSBANKS[x][2]);
if(distance < shortdistance)
{
shortest = x;
shortdistance = distance;
}
}
SetPlayerCheckpoint(playerid, GPSBANKS[shortest ][0], GPSBANKS[shortest ][1], GPSBANKS[shortest ][2], 7.0);
Re: Checking What Co-ords are Closest to a Player. -
Ciarannn - 25.02.2015
Quote:
Originally Posted by ball
Should work, figure it out on your own next time, not only "give code".
|
I spent a half an hour trying to get the code working, I didn't just "give code". Also, the point of this forums is to help you when your stuck, it's not about figuring it out yourself. I couldn't get it working so I asked.
Re: Checking What Co-ords are Closest to a Player. -
Ciarannn - 25.02.2015
Quote:
Originally Posted by Schneider
pawn Код:
new shortest=-1, Float:shortdistance=9999.9, Float:distance; for(new x; x<6; x++) { distance = GetPlayerDistanceFromPoint(playerid, GPSBANKS[x][0], GPSBANKS[x][1], GPSBANKS[x][2]); if(distance < shortdistance) { shortest = x; shortdistance = distance; } } SetPlayerCheckpoint(playerid, GPSBANKS[shortest ][0], GPSBANKS[shortest ][1], GPSBANKS[shortest ][2], 7.0);
|
Thanks, I've seen you helping around the forums. Keep it up!
+REP