SA-MP Forums Archive
How to check nearby Players ? - 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)
+--- Thread: How to check nearby Players ? (/showthread.php?tid=561899)



How to check nearby Players ? - serman - 05.02.2015

How to get Nearby players like

when player do /kill

you can't sucide, when your Enemy nearby

sorry for english


Re: How to check nearby Players ? - M4D - 05.02.2015

make a loop between players and check their position and team
i'll give you a simple example script

pawn Код:
foreach(Player, i)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(IsPlayerInRangeOfPoint(i, 10.0, x, y, z) && GetPlayerTeam(i) != GetPlayerTeam(playerid))
    {
          return SendClientMessage(playerid, -1, "Enemy Near You!");
    }
}
playerid > the person who types command


Re: How to check nearby Players ? - serman - 05.02.2015

Quote:
Originally Posted by M4D
Посмотреть сообщение
make a loop between players and check their position and team
i'll give you a simple example script

pawn Код:
foreach(Player, i)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(IsPlayerInRangeOfPoint(i, 10.0, x, y, z) && GetPlayerTeam(i) != GetPlayerTeam(playerid))
    {
          return SendClientMessage(playerid, -1, "Enemy Near You!");
    }
}
playerid > the person who types command
Thank you


Re: How to check nearby Players ? - serman - 05.02.2015

This is not working

pawn Код:
c(kill)
{
    foreach(Player, i)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(IsPlayerInRangeOfPoint(i, 20.0, x, y, z) && gTeam[i] != gTeam[playerid])
    {
        SetPlayerHealth(playerid,0.0);
        return SendClientMessage(playerid, -1, "Error : You can not use this command when an enemy is near you!");
    }
}
    return 1;
}



Re: How to check nearby Players ? - Schneider - 05.02.2015

pawn Код:
c(kill)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    foreach(Player, i)
    {    
        if((IsPlayerInRangeOfPoint(i, 20.0, x, y, z)) && (gTeam[i] != gTeam[playerid]))
        {
            return SendClientMessage(playerid, -1, "Error : You can not use this command when an enemy is near you!");
        }
    }
    SetPlayerHealth(playerid,0.0);    
    return 1;
}