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:
This is located in the CSharp Assembly file for rust.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 }); }
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
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.Code:NextTick(() =>{}) NextFrame.. OnPlayerInit OnPlayerRespawn(ed) OnPlayerConnected
Any help would be appreciated.
Listening to when a player has finished loading - CUI
Discussion in 'Rust Development' started by pinkstink, Dec 12, 2017.
-
I'd go with OnUserConnected(IPlayer player)
-
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.
-
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.
-
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(); } });
-
-
Code:if (player.IsSleeping()) player.EndSleeping();
-
-
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. -
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); } }
-