how can i get the nearest player from point?
#1

how can i get the nearest player from point?
like.. getthenearstplayerfrompoint(x,y,z)
i trying many ways, but i have no idea how!
i try using this "GetPlayerDistanceFromPoint()" and then nother things, but i stuck.
this must be only one player, and not many...
some help will be nice.
Reply
#2

https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint

I think you're looking for this
Reply
#3

GetPlayerDistanceFromPoint() is where you you see the distance between a player and a point. If you want to see who gets to the point first, then you need to use a different function.

Is it in a command or something? First player to a do a command at a point? Or is it a race to a certain point, and the first person there "wins?"
Reply
#4

no, i already try.
i nned the nearest player to point, this is not help me
for Example.
if there are tow players in the range i want, so iwant to get the nearest.
if the point she 0 0 0
and one of the players are in 2 2 3
and the second in 4 5 4
so i want the first, u get it?

edit : this write for the first post.

and |zEd- no, this not, i need to get the nearest player to other one, for example,
Reply
#5

pawn Код:
// Returns the nearest player to point x/y/z
// ignoreplayer will be ignored, if set
// (useful when you want to find the closest player to another player)
stock GetNearestPlayer(Float:x, Float:y, Float:z, ignoreplayer=-1) {
    // Store the currently nearest player and currently shortest distance in these:
    new Float:dist=9999999.0, player = -1;
    new Float:px, Float:py, Float:pz;    // Position of the currently looped player
    new Float:curdist;
    // Loop through all players
    for (new i = 0; i < MAX_PLAYERS; i++) {
        // Skip not connected players, and the player to ignore, if set
        if (!IsPlayerConnected(i) || i == ignoreplayer) continue;
        // Calculate quadratic distance from x/y/z to player
        GetPlayerPos(i, px, py, pz);
        curdist = (px - x) * (px - x) + (py - y) * (py - y) + (pz - z) * (pz - z);
        // if it is closer than the current minimum, update it
        if (curdist < dist) {
            dist = curdist;
            player = i;
        }
    }
    return player;
}
This will work, it uses the quadratic distance, and so is faster without any square roots, but this makes no difference for the closest player.

You could also have searched btw.
Reply
#6

Ty much
"testing"
Reply
#7

ok, i dont get it, he do what exactly?
what he return? in my caomman all i need to do is this ?
GetNearestPlayer(X, Y, Z, playerid);
and how i use this? i say testing, but in fact i don't get it.
help?
Reply
#8

Quote:
Originally Posted by Yoseflm
Посмотреть сообщение
ok, i dont get it, he do what exactly?
what he return? in my caomman all i need to do is this ?
GetNearestPlayer(X, Y, Z, playerid);
and how i use this? i say testing, but in fact i don't get it.
help?
Yes thats the way to use it. You can also leave out the last parameter, so
nearestplayer = GetNearestPlayer(x, y, z);
I just added this for more general usages, but you wont need that in most cases
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)