Skip to content
RustPluginGenerator

OnSleepingBagValidCheck

OnSleepingBagValidCheck is called every time the game checks whether a sleeping bag or bed can be used by a specific player, before the vanilla owner and cooldown checks run. Returning a bool overrides the result.

Signature
object OnSleepingBagValidCheck(SleepingBag sleepingBag, ulong playerID, bool ignoreTimers)

Parameters

Hook parameters
ParameterTypeDescription
sleepingBagSleepingBagThe SleepingBag (or bed variant) whose validity for a player is being checked. Use its OwnerID, deployerUserID, transform position or net.ID to make decisions.
playerIDulongSteam ID (ulong) of the player who is trying to use the bag, e.g. as a respawn target. Note this is a raw ulong, not a string.
ignoreTimersboolTrue when the game should ignore cooldown/timer restrictions for this check (used by admin respawn or forced logic). Mirrors the argument passed to SleepingBag.ValidForPlayer.

Return value

Returning null (or any non-bool) leaves the vanilla check in place. Returning a bool short-circuits ValidForPlayer entirely: true makes the bag usable by that player, false blocks it, bypassing both the owner and timer checks.

How it works

The hook fires inside SleepingBag.ValidForPlayer(ulong playerID, bool ignoreTimers), which Rust calls when it needs to know if a player may use a bag as a respawn point (opening the respawn screen, validating a selected bag, or programmatically querying validity). It runs before the vanilla deployerUserID == playerID check and the timer checks, so it is a clean place to add your own rules.

sleepingBag is the entity being validated, playerID the player attempting to use it, and ignoreTimers tells you whether timer restrictions are being bypassed. Because the dispatcher accepts any bool return, you can force a bag to be usable or blocked regardless of ownership. Declaring SleepingBag restricts the hook to bags and beds only (the vanilla method is inherited, so other subclasses could call it). This is also the natural place to enforce team-sharing rules, VIP restrictions, or per-bag bans.

Keep the handler cheap: it can run repeatedly while a player sits on the respawn screen, so avoid logging or heavy scans.

Example plugin: Allow team members to use each other's bags

TeamSleepingBagShare.cs
using System.Linq;
using System;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Team Sleeping Bag Share", "RustPluginGenerator", "1.0.0")]
    [Description("Allows Rust teammates to respawn on each other's sleeping bags.")]
    public class TeamSleepingBagShare : RustPlugin
    {
        private const string PermUse = "teamsleepingbagshare.use";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Require permission to share bags")]
            public bool RequirePermission { get; set; } = false;

            [JsonProperty("Block non-teammates instead of vanilla check")]
            public bool BlockOutsiders { get; set; } = false;
        }

        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);

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

        private object OnSleepingBagValidCheck(SleepingBag sleepingBag, ulong playerID, bool ignoreTimers)
        {
            if (sleepingBag == null || playerID == 0) return null;
            if (sleepingBag.OwnerID == playerID) return null;

            var player = BasePlayer.FindByID(playerID);
            if (player == null || player.IsNpc) return null;

            if (config.RequirePermission && !permission.UserHasPermission(player.UserIDString, PermUse))
                return null;

            var owner = BasePlayer.FindByID(sleepingBag.OwnerID);
            if (owner == null) return config.BlockOutsiders ? (object)false : null;

            if (player.currentTeam == 0 || player.currentTeam != owner.currentTeam)
                return config.BlockOutsiders ? (object)false : null;

            var team = RelationshipManager.ServerInstance.FindTeam(player.currentTeam);
            if (team == null || !team.members.Contains(sleepingBag.OwnerID)) return null;

            return true;
        }
    }
}

The plugin overrides OnSleepingBagValidCheck so a bag owned by another player is treated as valid when the requester is on the same Rust team. It reads sleepingBag.OwnerID, compares it with playerID, and if they differ it resolves the player with BasePlayer.FindByID. If RequirePermission is set and the player lacks teamsleepingbagshare.use, the hook returns null. It then resolves the bag owner with BasePlayer.FindByID and checks that player.currentTeam is non-zero, matches owner.currentTeam, and that the team returned by RelationshipManager.ServerInstance.FindTeam contains the owner's ID. When those checks pass the hook returns true. If the owner cannot be found or the players are not teammates, the result is false when BlockOutsiders is enabled, otherwise null.

Common use cases

  • Team respawn sharing

    Let teammates respawn on each other's bags without re-deploying them, matching how many survival servers handle shared bases.

  • VIP-only bags

    Block use of bags by players without a permission such as vipbags.use, forcing them to use vanilla bags instead.

  • Wipe-day cooldown

    During the first hours after a wipe, return false for non-owners to prevent instant respawn base camping.

Pitfalls

  • playerID is a ulong, not a string

    Use player.UserIDString when logging or looking up players; pass playerID directly to permission or team APIs only if they expect a ulong.

  • Runs frequently

    The game queries validity multiple times per respawn screen, so avoid PrintWarning or expensive iteration inside this hook.

  • Returning false blocks everyone on that bag

    Beds inherit this method, so explicitly check sleepingBag.OwnerID and the player before blocking, or you may lock out the owner too.

Build a plugin with OnSleepingBagValidCheck

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

Prompt: Team respawn sharing using the OnSleepingBagValidCheck 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 OnSleepingBagValidCheck

Generate