Function such as "IsPlayerCloseToPlayer" or something
Hey

Is there a function that can detect if a player is within a certain distance to another player? I looked all over the SA-MP Wiki but couldn't find one?

Thanks!
It's impossible you've looked all over the SAMP wiki because there's something which can help you : IsPlayerInRangeOfPoint.

Just get the player2 pos and check if it's close enough through the "radius" parameter to the playerid's position (gotten automatically by SAMP)
pawn Код:
`stock Float:GetDistanceBetweenPlayers(playerid,targetplayerid){    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {        return -1.00;    }    GetPlayerPos(playerid,x1,y1,z1);    GetPlayerPos(targetplayerid,x2,y2,z2);    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));}`
P.S : by Kostantinos
Quote:
 Originally Posted by S4t3K It's impossible you've looked all over the SAMP wiki because there's something which can help you : IsPlayerInRangeOfPoint. Just get the player2 pos and check if it's close enough through the "radius" parameter to the playerid's position (gotten automatically by SAMP)
Quote:
 Originally Posted by Clad pawn Код: `stock Float:GetDistanceBetweenPlayers(playerid,targetplayerid){    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {        return -1.00;    }    GetPlayerPos(playerid,x1,y1,z1);    GetPlayerPos(targetplayerid,x2,y2,z2);    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));}` P.S : by Kostantinos
This is exactly what I wanted! Thank you. And S4t3K, I saw that but I didn't think that would be useful. Thanks anyways!

EDIT: Now for the GetDistanceBetweenPlayers function, would I do:
Код:
`if(GetDistanceBetweenPlayers(playerid, targetid)) = x (x would be a number or a float)`
Konstantinos' function can be optimized using VectorSize :

PHP код:
``` stock Float:GetDistanceBetweenPlayers(pl1, pl2){      new Float:pos[6];      if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2)) return -1.0;      GetPlayerPos(pl1, pos[0], pos[1], pos[2]);      GetPlayerPos(pl2, pos[3], pos[4], pos[5]);      return VectorSize(pos[0]-pos[3],pos[1] - pos[4], pos[2]-pos[5]);}  ```
This "VectorSize" usage is from the wiki page VectorSize, and a similar function called "GetDistanceBetweenPoints" uses this kind of implementation, credits go to Vince.
pawn Код:
`forward Float:GetDistanceBetweenPlayers(playerid,targetplayerid);public Float:GetDistanceBetweenPlayers(playerid,targetplayerid){    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {        return -1.00;    }    GetPlayerPos(playerid,x1,y1,z1);    GetPlayerPos(targetplayerid,x2,y2,z2);    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));}`
Why do you want to use a public function here ? Except if you plan to call the function through a timer or through CallLocal/RemoteFunction, it's pointless.

And why do you repost the exact function as above ?
Late.
?
Quote:
 EDIT: Now for the GetDistanceBetweenPlayers function, would I do: Code: if(GetDistanceBetweenPlayers(playerid, targetid)) == x (x would be a number or a float)
I don't understand what you are trying to say by just giving me the stock?
Quote:
 Originally Posted by S4t3K Why do you want to use a public function here ? Except if you plan to call the function through a timer or through CallLocal/RemoteFunction, it's pointless. And why do you repost the exact function as above ?
Don't get mad homie, When I sent it I didn't know you will send it too, Relax pls.

Forum Jump: