Posts: 864
Threads: 88
Joined: Jul 2012
Reputation:
0
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!
Posts: 1,241
Threads: 67
Joined: Dec 2013
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
Posts: 1,241
Threads: 67
Joined: Dec 2013
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));
}
Posts: 864
Threads: 57
Joined: Jan 2013
Reputation:
0
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 ?
Posts: 1,241
Threads: 67
Joined: Dec 2013
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.