How to check nearby Players ?
#1

How to get Nearby players like

when player do /kill

you can't sucide, when your Enemy nearby

sorry for english
Reply
#2

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
Reply
#3

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
Reply
#4

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;
}
Reply
#5

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)