1. Hi All,

    I'm trying to have a new CUI element display once the player has finished load after connecting to a server. The function that is called when the player is ready is:
    Code:
    (BasePlayer Class)
    private void EnterGame()
        {
            this.SetPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot, false);
            base.ClientRPCPlayer(null, this, "FinishLoading");
            if (this.net != null)
            {
                EACServer.OnFinishLoading(this.net.connection);
            }
            Debug.LogFormat("{0} has entered the game", new object[] { this });
        }
    This is located in the CSharp Assembly file for rust.

    It's a simple element that has only text in it("Welcome to the server") The element will display fine if I trigger it in game after connecting some how(Walking in and out of the zone that I have hooked to in my plugin or simply f1 kill and respawning in the zone).

    I've tried so far calling CuiHelper.AddUi(player, elements) with
    Code:
    NextTick(() =>{})
    NextFrame..
    OnPlayerInit
    OnPlayerRespawn(ed)
    OnPlayerConnected
    I've tried using the plugin UiPlus for reference here which is where I tried utilizing the NextFrame method. But again the CuiHelper.Add method is call too early before the client sends the "FinishLoading" RPC.

    Any help would be appreciated.
     
    Last edited by a moderator: Dec 12, 2017
  2. I'd go with OnUserConnected(IPlayer player)
     
  3. Wulf

    Wulf Community Admin

    OnPlayerConnected is what you'd want for a RustPlugin, which does trigger after they have spawned. Their UI may not be fully loaded though, and I don't think there's really a way to tell that. OnUserConnected is triggered right after OnPlayerConnected and is intended for creating universal plugins or as a universal hook.
     
  4. You could try doing it through OnPlayerSleepEnded, and just add them to a List (so it won't trigger if they wake up from a teleport or respawn) and remove them from that list when they disconnect, so it only shows on wake ups from connecting.
     
  5. Thanks for all the suggestions.

    @Shady757 Your suggestion is valid, but how would I trigger the Cui Helper once the player is ready? The OnPlayerSleepEnded is still called to early. The helper needs to be called after the player has finished receiving a snapshot.

    I've managed to find a crude way to achieve the desired functionality, but I'm honestly unsure if it is bad practice doing it this way? Any input would be appreciated

    Code:
    Timer CheckPlayerFlags;
    CheckPlayerFlags = timer.Repeat(1, 20, () => {
         if (!player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
         {
              UpdateKdrCui(player);
              CheckPlayerFlags.Destroy();
         }
    });
    
    UpdateKdrCui is my helper method that simply manages the CuiPanel and Updates It as necessary
     
  6. I'm not sure how or why the player would be waking up while they're still loading. I don't think that the client accepts the input to wake up until after the loading screen is gone.
     
  7. It's a minigame server plugin so in the OnPlayerRespawned hook i have this:
    Code:
                if (player.IsSleeping()) player.EndSleeping();
    
    It's something that has become the bane of my existence throughout the creation of this plugin and I've had to find ways to mitigate it's consequences on numerous occasions...
     
  8. Isn't OnPlayerRespawned only called after a player died and, well, respawned? I'm still failing to see why using OnPlayerSleepEnded and on the first time it's called, put the player into a list so it isn't triggered again until they disconnect - wouldn't work. The only case where you may have an issue is before a server restart, as players would probably be waking up for the "first time" without having actually connected/reconnected, but this seems like a minor "issue". Sorry if I'm misunderstanding something here, just seems like it would work to me. ;)
     

  9. Thanks what I thought also, but since the script still wakes players up before they have finished receiving the snapshot, calling AddUi method will still not work as the client itself isn't ready even though the player is technically awake. If I remove that one line that auto awakes players, it works fine.
     
  10. Code:
            private void SendUI(BasePlayer player, string json, string name)
            {
                if(player.IsReceivingSnapshot)
                    timer.In(1, () => SendUI(player, json, name));
                else {
                    CuiHelper.DestroyUi(player, name);
                    CuiHelper.AddUi(player, json);
                }
            }
    In OnPlayerInit or in another hook, SendUI(player, your_var_with_ui, "ui_name");
     
  11. Cheers miRror, that's what I ended up with also.