1. -=Skate=-

    -=Skate=- Naked Wanderer

    I have this method and any usage of player data functions return null reference exception, I know i'm calling it wrong, but how do I call it right ? Also, any way to use the "var userid" to direct the functions to the right caller ?


    Code (Text):
            private void OnEntityBuilt(Planner plan, GameObject ent, BasePlayer player)
            {
                var cupboard = ent.GetComponent<BuildingPrivlidge>();
                if (cupboard)
                {
                    var hits = Physics.OverlapSphere(cupboard.transform.position, radius);
                    int i = 0;
                    var userid = plan.GetOwnerPlayer().userID;
                    Authorize(cupboard, userid);
                    foreach (var ents in hits)
                    {
                       
                        var privs = ents.GetComponentInParent<BuildingPrivlidge>();
                        if (ents.ToString() == "assets/prefabs/deployable/tool cupboard/cupboard.tool.deployed.prefab (UnityEngine.BoxCollider)")
                        {
                          i++;
                        }
                       
                        if (i >= 6)
                        {
                            DoRemove(cupboard, removeGibsAdmin);
                            SendReply(player, "Max cupboards limit in area reached (5)");            //NullReferenceException: Object reference not set to an instance of an object
                            player.inventory.GiveItem(ItemManager.CreateByItemID(1257201758, 1));   //NullReferenceException: Object reference not set to an instance of an object
                            break;
                        }
                    }
                    UpdateAllPlayersMethod.Invoke(cupboard, null);
                    cupboard.SendNetworkUpdate();
                }
            }
     
  2. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    OnEntityBuilt does not pass a BasePlayer: Oxide API for Rust
    You should grab the player from the Planner object (plan.GetOwnerPlayer() if I remember correctly).
     
  3. -=Skate=-

    -=Skate=- Naked Wanderer

    Thats what I thought -_-'. And yeah, that worked, cheers ! ;)