Skip to content
RustPluginGenerator

OnPlayerSleepEnd

OnPlayerSleepEnd is called at the start of BasePlayer.EndSleeping, before the player's sleep state is cleared and before their inventory is unlocked from restraints. Returning a non-null value aborts the original method.

Signature
object OnPlayerSleepEnd(BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
playerBasePlayerThe BasePlayer whose sleeping state is ending. Check IsConnected and IsSleeping before doing work; this can be a player who was sleeping and is now waking up.

Return value

Returning null lets EndSleeping continue normally. Returning any non-null value prevents the rest of BasePlayer.EndSleeping from running, which leaves the player's sleep transition incomplete — avoid this unless you deliberately take over the whole wake-up process.

How it works

This hook fires from BasePlayer.EndSleeping, which the game runs when a sleeping player wakes up (for example when they reconnect, or when a wake-up is triggered server-side). It is called while the player is still considered sleeping: the check IsSleeping() happens before the hook, so player.IsSleeping() returns true inside your handler. The only argument is the waking BasePlayer.

Because the hook runs before the rest of EndSleeping, it is the right place to run logic that must happen before the player regains control: restoring state, applying a starting effect, or validating that the wake-up should proceed. Declaring the parameter as BasePlayer is the natural choice; a narrower type is not useful here since the game always passes a player.

Note the early exit: if you return any non-null value, the original EndSleeping body is skipped. That means the player is not moved out of the sleeping state by the game path, the restraint unlock does not run, and the player can be left in an inconsistent state. Return null in almost every case, and use OnPlayerSleepEnded (not this hook) when you need to act after the player has actually woken up.

Example plugin: Apply a login effect and message when a player wakes up

WakeUpNotice.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Wake Up Notice", "RustPluginGenerator", "1.0.0")]
    [Description("Plays an effect and shows a configurable message when a player wakes up.")]
    public class WakeUpNotice : RustPlugin
    {
        private const string PermEffect = "wakeupnotice.effect";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Play effect on wake")]
            public bool PlayEffect { get; set; } = true;

            [JsonProperty("Effect prefab")]
            public string EffectPrefab { get; set; } = "assets/bundled/prefabs/fx/player/gutshot_scream.prefab";
        }

        protected override void LoadDefaultConfig() => config = new PluginConfig();

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<PluginConfig>();
                if (config == null) throw new Exception();
            }
            catch
            {
                PrintWarning("Configuration file is invalid, using defaults");
                LoadDefaultConfig();
            }
            SaveConfig();
        }

        protected override void SaveConfig() => Config.WriteObject(config);

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["Welcome"] = "Welcome back. You woke up near {0}.",
                ["WakeLocation"] = "your bed"
            }, this);
        }

        private string Msg(string key, string userId = null, params object[] args)
        {
            return string.Format(lang.GetMessage(key, this, userId), args);
        }

        private void Init()
        {
            permission.RegisterPermission(PermEffect, this);
        }

        private object OnPlayerSleepEnd(BasePlayer player)
        {
            if (player == null || !player.IsConnected)
            {
                return null;
            }

            // The player is still flagged as sleeping here; keep this handler light.
            var pos = player.transform.position;

            if (config.PlayEffect && permission.UserHasPermission(player.UserIDString, PermEffect))
            {
                Effect.server.Run(config.EffectPrefab, pos);
            }

            player.ChatMessage(Msg("Welcome", player.UserIDString, Msg("WakeLocation", player.UserIDString)));

            return null;
        }
    }
}

The plugin listens for OnPlayerSleepEnd and, for players who are still connected, plays a short visual effect at their position and sends a configurable chat message. Configuration holds the effect prefab and the message text (localized through the language file), and a permission gates whether the effect is shown. The hook returns null so the normal wake-up path is untouched. A short comment notes that the player is still sleeping at this point, which is why the code does not assume they can be teleported or moved yet. Timer references and config are cleaned up in Unload.

Common use cases

  • Welcome message on wake-up

    Send a configurable chat line to the player as they wake so they know server rules or the current wipe status without waiting for a separate connect event.

  • Restore per-player state before controls return

    Check saved data and reapply status such as a custom flag or effect while the player is still transitioning, then let the game finish the wake-up normally.

  • Spawn a visual marker at the bed

    Run a small effect at the player's position so other nearby players see where the sleeper woke, useful on survival servers where sleepers are lootable.

Pitfalls

  • Returning a value breaks the wake-up

    Any non-null return skips the rest of EndSleeping, so the player may be stuck mid-transition. Always return null from this hook.

  • Player is still sleeping

    IsSleeping() is true when the hook fires, and movement or teleports here can behave oddly. Defer actions that need a fully awake player to OnPlayerSleepEnded.

  • Fires on reconnect, not only manual wake

    A player reconnecting also triggers EndSleeping, so do not assume the player was physically present and awake just before this call.

Build a plugin with OnPlayerSleepEnd

Describe what should happen and get a compiled plugin that uses this hook.

Prompt: Welcome message on wake-up using the OnPlayerSleepEnd hook, with a config file and a permission
Generate this plugin

Edit the prompt on the next screen. 2 free plugins a month, no card.

Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.

Build a plugin with OnPlayerSleepEnd

Generate