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: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(); } }
Solved Calling player.anything() causes NullReferenceException, what have I missing ?
Discussion in 'Rust Development' started by -=Skate=-, Apr 21, 2017.