1. Hi I am checking to scan for players around an entity based on distance and object angle (to determinate the facing). So, when a player is in range and in a 30-90degree facing vision of the object, it returns true (just like a camera would do when detecting a player that it's looking at).

    I've looked at the shotgun trap detection
    Code:
    public bool CheckTrigger(float offset, float radius)
        {
            List<RaycastHit> list = Pool.GetList<RaycastHit>();
            List<BasePlayer> basePlayers = Pool.GetList<BasePlayer>();
            Vis.Entities<BasePlayer>(this.GetEyePosition() + (base.transform.forward * offset), radius, basePlayers, 131072, QueryTriggerInteraction.Collide);
            bool flag = false;
            foreach (BasePlayer basePlayer in basePlayers)
            {
                if (basePlayer.IsSleeping() || !basePlayer.IsAlive() || basePlayer.IsBuildingAuthed())
                {
                    continue;
                }
                object obj = Interface.CallHook("CanBeTargeted", basePlayer, this);
                if (obj as bool)
                {
                    Pool.FreeList<RaycastHit>(ref list);
                    Pool.FreeList<BasePlayer>(ref basePlayers);
                    return (bool)obj;
                }
                list.Clear();
                Vector3 vector3 = basePlayer.eyes.position;
                Vector3 eyePosition = this.GetEyePosition() - basePlayer.eyes.position;
                GamePhysics.TraceAll(new Ray(vector3, eyePosition.normalized), 0f, list, 9f, 1084301569, QueryTriggerInteraction.UseGlobal);
                int num = 0;
                while (num < list.Count)
                {
                    BaseEntity entity = list[num].GetEntity();
                    if (entity != null && (entity == this || entity.EqualNetID(this)))
                    {
                        flag = true;
                        break;
                    }
                    else if (!(entity != null) || entity.ShouldBlockProjectiles())
                    {
                        break;
                    }
                    else
                    {
                        num++;
                    }
                }
                if (!flag)
                {
                    continue;
                }
                break;
            }
            Pool.FreeList<RaycastHit>(ref list);
            Pool.FreeList<BasePlayer>(ref basePlayers);
            return flag;
        }
    Can I use this and do if (CheckTrigger(3f, 1.25f)) Puts("Detected!"); //example

    Is there a simplier way with fewer lines or that's exactly what I need?
     
    Last edited by a moderator: Jun 11, 2018