1. Hey all

    So I'm trying to add a player to a tool cupboard via a command. I get the ToolCupboard and the authorizedPlayers list, and add the player to the authorizedPlayers list. However, although the player is added, and therefore has building privilidge (however only after they have left and re-entered the TC zone), the TC still acts as if the player is not added (eg shows "Authorize" on the use menu rather than "Deauthorize"). If we take a look at the code, we can see there are a few things missing which I believe is required to get it working properly.
    Code:
    this.authorizedPlayers.Add(playerNameID); //We have this
    this.UpdateAllPlayers();
    base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
    Since we already have the first line where the player is added to the auth list, we don't need to worry about that. However, does anyone know how I would go about re-creating the second two lines? It seems I can use player.SendNetworkUpdate rather than base.SendNetworkUpdate, however this seems to have no effect which leads me to believe this is not necessarily required, or that player.SendNetworkUpdate doesn't perform the same function. this.UpdateAllPlayers() I have been unsuccessful in re-creating, as it seems the UpdateAllPlayers function used from within the BuildingPrivlidge class is a private method.

    Any ideas?
     
  2. You need to keep in mind that you are getting that code from the BuildingPrivlidge object so in this case `this` refers to that and `base` to the base class that it is derived from. In the case of base (in the decompiler) you can usually just use the object you are working with to call the method. The actual adding of players to the zone is handled in UpdateAllPlayers and you can run this by getting the method using reflection and then invoking it, here is a quick example to authorize yourself in the current cupboard zone:

    Code:
            private MethodInfo UpdateAllPlayers = typeof(BuildingPrivlidge).GetMethod("UpdateAllPlayers", BindingFlags.NonPublic | BindingFlags.Instance);        [ChatCommand("authorize")]
            private void Authorize(BasePlayer player)
            {
                var activeCupboard = player.GetBuildingPrivilege();
                activeCupboard.authorizedPlayers.Add(new PlayerNameID { userid = player.userID, username = player.displayName });
                UpdateAllPlayers.Invoke(activeCupboard, null);
                activeCupboard.SendNetworkUpdate(global::BasePlayer.NetworkQueue.Update);
            }
     
  3. Thanks alot Mughisi! Your code worked perfectly :)

    Cheers!