SA-MP Forums Archive
verify if a player is near - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: verify if a player is near (/showthread.php?tid=98079)



verify if a player is near - [SOB]Chris - 19.09.2009

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


Re: verify if a player is near - Calgon - 19.09.2009

It returns 1, not 0.

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

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


Re: verify if a player is near - [SOB]Chris - 19.09.2009

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