How can i get nearby players in radiusSolved

i'm trying coding a new plugin to my server and i need some way to get nearby players in x radius but dont know how to 

i already tried to play with some code 

int layer = LayerMask.GetMask("Construction", "Prevent Building", "Construction Trigger", "Trigger", "Deployed", "Default", "World", "Player (server)");
List<BaseEntity> list = new List<BaseEntity>();
Vis.Entities<BaseEntity>(radio.ServerPosition, 10f, list, layer, QueryTriggerInteraction.UseGlobal);


Puts("List size: " + list.Count);
foreach(BaseEntity e in list) {
    Puts("   - " + e.GetType().Name);
}

but i couldn't get it to work

i'm not sure is it because i don't use correct layerMask or is that even correct method 

where you can even find all this layersMask that you can use with this????

can someone please help me or point me to right direction, thanks :)

You can use entity.gameObject.layer or entity.gameObject.IsOnLayer to know which layer an entity belongs to.
Players are found in the Player (Server) layer.

You could loop through BasePlayer.activePlayerList and check for distance.

I'm pretty sure the layer is "Player_Server" not "Player (server)"

coPKsNKzKgChBGd.png Dana

You can use entity.gameObject.layer or entity.gameObject.IsOnLayer to know which layer an entity belongs to.
Players are found in the Player (Server) layer.

I tried to use this to see what layer should i use but this just prints number "17" and i tried to use that as a layer but it doesn't work

BasePlayer player = BasePlayer.Find("steamid");
Puts("layer: " + player.gameObject.layer);

 

Zugzwang

You could loop through BasePlayer.activePlayerList and check for distance.

I also thinked about doing this but i think that there must be some better way to do it and its not that smart it going to take too much resources from server to calculate all palyers distances

wXLxOgFUEnSjh1r.png 0x89A

I'm pretty sure the layer is "Player_Server" not "Player (server)"

I also tried to use "Player_Server" but that also doesn't work

This is surprisingly difficult to do it shouldn't be this hard :D

 

Take this example as a reference
        private bool HasPlayerNearby(Vector3 position)
        {
            List<BasePlayer> players = Pool.GetList<BasePlayer>();
            Vis.Entities(position, 10f, players, LayerMask.GetMask("Player (Server)"), QueryTriggerInteraction.Ignore);

            bool result = false;
            foreach (BasePlayer player in players)
            {
                if (!player.IsSleeping() && player.IsAlive() && player.userID.IsSteamId())
                {
                    result = true;
                    break;
                }
            }
            Pool.FreeList(ref players);
            return result;
        }
dp9EYo2eLODfI6h.png Dana

Something similar to this example should work

        private bool HasPlayerNearby(Vector3 position)
        {
            List<BasePlayer> players = Pool.GetList<BasePlayer>();
            Vis.Entities(position, 10f, players, LayerMask.GetMask("Player (Server)"), QueryTriggerInteraction.Ignore);

            bool result = false;
            foreach (BasePlayer player in players)
            {
                if (!player.IsSleeping() && player.IsAlive() && player.userID.IsSteamId())
                {
                    result = true;
                    break;
                }
            }
            Pool.FreeList(ref players);
            return result;
        }
That works, thanks for that :)
Locked automatically