verify if a player is near
#1

Here's the code I'm using to see if a player is near.
pawn Код:
stock IsPlayerClose(playerid, Float:radi)
{
  new Float:oldposx, Float:oldposy, Float:oldposz;
  new Float:tempposx, Float:tempposy, Float:tempposz;
  new Float:otherx, Float:othery, Float:otherz;
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      GetPlayerPos(playerid, oldposx, oldposy, oldposz);
      GetPlayerPos(i, otherx, othery, otherz);
      tempposx = (oldposx -otherx);
      tempposy = (oldposy -othery);
      tempposz = (oldposz -otherz);
      if(((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
      {
        return 1;
      }
    }
  }
  return 0;
}
This command should only be used if no player is near, but always detects that a player is close but not there no player connected.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/sf", cmdtext, true, 10) == 0)
    {
      if (IsPlayerClose(playerid,5.00) == 0)
        {
            Teleport(playerid,80,-1977.1107,285.8831,35.1719,0,0);
            Announcecmd(playerid,": a ido hacia /sf","asd",1,COLOR_AZUL,3);
        }
        else
        {
            SendClientMessage(playerid,COLOR_ROJO,"AVISO: Hay un jugador cerca no puedes usar este comando.");
        }
        return 1;
    }
    return 0;
}
I'm using the wrong code?, Or because it does not work, any idea.
Thanks for your answers =D
Reply
#2

It returns 1, not 0.

pawn Код:
if(IsPlayerClose(playerid,5.00))
Or

pawn Код:
if(IsPlayerClose(playerid,5.00) == 1)
Would work.
Reply
#3

Dont Work, but man the code return 0 if any player is close and return 1 if a player is close or what .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)