[Tool/Web/Other] [Function]IsPlayerNearPlayer
#1

With this function you can easily find is some player near some other player, it is simple to use.

pawn Код:
IsPlayerNearPlayer(playerid, n_playerid, Float:radius){
    new Float:npx, Float:npy, Float:npz;
    GetPlayerPos(n_playerid, npx, npy, npz);
    if(IsPlayerInRangeOfPoint(playerid, radius, npx, npy, npz)){
        return true;
    }else{
        return false;
    }
}
Usage:
pawn Код:
forward IsPlayerNearPlayer(playerid, n_playerid, Float:radius);
IsPlayerNearPlayer(playerid, n_playerid, Float:radius){
    new Float:npx, Float:npy, Float:npz;
    GetPlayerPos(n_playerid, npx, npy, npz);
    if(IsPlayerInRangeOfPoint(playerid, radius, npx, npy, npz)){
        return true;
    }else{
        return false;
    }
}
public OnPlayerCommandText(playerid, cmdtext[]){
  new idx, cmd[256];
  cmd = strtok(cmdtext, idx);
  if(strcmp(cmd, "/near")){
    if(IsPlayerNearPlayer(playerid, 5, 10.0)){
      SendClientMessage(playerid, COLOR_WHITE, "You are near player with id 5 Radius is 10");
      return 1;
    }else{
      SendClientMessage(playerid, COLOR_WHITE, "You are NOT near player with id 5 Radius is 10");
      return 1;
    }
  }
}
So as you can see, with this function we can check is player with example id 5 near player that called command /near
Reply
#2

Nice function.Simple,but usefull
7.5/10
Reply
#3

The way you did your code made the else statement useless in your forward, you could of just done it this way:

pawn Код:
stock PlayerToPlayer(playerid,targetid,Float:distance)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid,x,y,z);
    if(IsPlayerInRangeOfPoint(targetid,distance,x,y,z))
    {
        return true;
    }
    return false;
}

public OnPlayerCommandText(playerid, cmdtext[]){
  new idx, cmd[256];
  cmd = strtok(cmdtext, idx);
  if(strcmp(cmd, "/near")){
    if(PlayerToPlayer(playerid,5, 10.0)){
      SendClientMessage(playerid, COLOR_WHITE, "You are near player with id 5 Radius is 10");
      return 1;
    }else{
      SendClientMessage(playerid, COLOR_WHITE, "You are NOT near player with id 5 Radius is 10");
      return 1;
    }
  }
}
Reply
#4

I made something like this 2 weeks ago and i copy } else { reutrn true; code from your FUNC tnx alot i give you credits
Reply
#5

Quote:
Originally Posted by DarkPower
Посмотреть сообщение
I made something like this 2 weeks ago and i copy } else { reutrn true; code from your FUNC tnx alot i give you credits
xaxaxa. . . .you welcome
Reply
#6

HaHa, you saved me 5 mins. Thanks
Reply
#7

Useful for police use only really.... Say if someone wants a restraining order on somebody because of a harassment or just DMing, Police can use this to see if the player is anywhere near the other, OR if 2 people were caught in a police chase or bank robbery, they cannot be like say 100ft within eachother, if they are they will get breached and jailed.
Reply
#8

https://sampforum.blast.hk/showthread.php?tid=38965
Reply
#9

Quote:
Originally Posted by dice7
Посмотреть сообщение
what with that
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)