1. Hey.

    Basically, I'm trying to get the BuildingPrivilidge from a cupboard so I can get a list of all auth'ed players on the cupboard.

    Here is the code I have so far:

    Code:
    object closestEnt;
    Vector3 closestHit;
    Quaternion rot = Quaternion.Euler((serverinput.GetValue(player) as InputState).current.aimAngles);
    TryGetClosestRayPoint(player.transform.position, rot, out closestEnt, out closestHit);
    This code basically drwas a Raycast from the player in the direction they're looking, and returns the entity hit and the location of the entity hit.

    How would I get the BuildingPrivilidge from the closestEnt, checking the closestEnt was infact a tool cupboard?

    I'm asking for the BuildingPrivilidge specifically as this contains a list of PlayerNameID (a class containing the player nickname and user id), called authorizedPlayers.
    Code:
    public List<PlayerNameID> authorizedPlayers = new List<PlayerNameID>();
    Any ideas?
     
  2. Code:
    object GetAuthList(BaseEntity cupboard){
                if(cupboard is BuildingPrivlidge){
                    var bpriv = entity as BuildingPrivlidge;
                    if(bpriv == null) return null;
                    else return bpriv.authorizedPlayers.ToList();
                }
                return null;
            }
    List<ulong> players = new List<ulong>();
    players = GetAuthList(entity);
    Or if you just want the BuildingPrivlidge Type:
    Code:
            BuildingPrivlidge GetBuildingPriv(BaseEntity cupboard, List<ulong> authList){
                if(cupboard is BuildingPrivlidge){
                    return cupboard as BuildingPrivlidge;
                }
                return null;
            }
    *if that doesnt work:
    Code:
            object GetBuildingPriv(BaseEntity cupboard, List<ulong> authList){
                if(cupboard is BuildingPrivlidge){
                    return cupboard as BuildingPrivlidge;
                }
                return null;
            }
     
  3. I had some code something along these lines, however it would always return a NullReferenceException.

    It turns out, this was actually because of the way I was using the raycast. The raycast would return an object of type Collider, rather than a BaseEntity. This is why it seemed to refuse to play nicely with any of the code I was testing. I fixed this by using code, albeit slightly modified, from the Prod plugin, as follows:
    Code:
    BaseEntity DoRay(Vector3 Pos, Vector3 Aim)
            {
                var hits = UnityEngine.Physics.RaycastAll(Pos, Aim);
                float distance = 100000f;
                BaseEntity target = null;
                foreach (var hit in hits)
                {
                    if (hit.collider != null && isPluginDev && dumpAll)
                        Dump(hit.GetEntity());
                    if (hit.distance < distance)
                    {
                        distance = hit.distance;
                        target = hit.GetEntity();
                    }
                }
                return target;
            }
    Admin, please mark this thread as solved.
     
  4. Yeah. A bunch of plugins have examples of the raycast, eye detection stuff. Such as prod, old remover tool versions, and my smarthomes plugin.