Skip to content
RustPluginGenerator

OnPlayerRespawn

OnPlayerRespawn is called on the server before a player is moved to a respawn location. It fires from BasePlayer.Respawn with a computed SpawnPoint and from SleepingBag.SpawnPlayer with the bag being used.

Signature
object OnPlayerRespawn(BasePlayer player, BasePlayer.SpawnPoint spawnPoint)

Parameters

Hook parameters
ParameterTypeDescription
playerBasePlayerThe BasePlayer who is being respawned. At this point the player is still dead or transitioning; use UserIDString for permissions and identity checks.
spawnPointBasePlayer.SpawnPointA BasePlayer.SpawnPoint holding the pos and rot the player is about to be teleported to. When the hook fires from a sleeping bag, this parameter is instead the SleepingBag entity.

Return value

Returning null keeps the game's original spawn point or sleeping bag. Returning a BasePlayer.SpawnPoint (from the Respawn site) replaces the spawn target used by RespawnAt; returning a SleepingBag from the bag site replaces the bag. Returning any other type is ignored.

How it works

The hook fires twice in two different respawn paths. In BasePlayer.Respawn, Oxide calls it after the game picks a spawn point via ServerMgr.FindSpawnPoint and applies the death-position override, but before RespawnAt moves the player. Here the second argument is a BasePlayer.SpawnPoint with pos and rot fields you can read or replace. In SleepingBag.SpawnPlayer, Oxide calls it after the null check on the bag and before the static-respawn-area authorization check. Here the second argument is the SleepingBag, which is useful for logging or vetoing bag respawns.

Because the signature is shared, declare the second parameter as object or BaseEntity if you want both sites to reach your code. If you declare BasePlayer.SpawnPoint, Oxide's dispatch only calls you when the argument is actually a SpawnPoint, so the bag path is skipped. Declaring SleepingBag narrows to the bag path only.

Returning a value replaces the game's local variable. This means you can move a respawn target without teleporting the player yourself, though the game will still perform the RespawnAt step afterwards.

Other signatures

Oxide also calls OnPlayerRespawn from other places in the game with these parameter types. Declare the overload you need, or several:

  • object OnPlayerRespawn(BasePlayer player, SleepingBag sleepingBag2)

Example plugin: Redirect respawns to a custom lobby location

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

namespace Oxide.Plugins
{
    [Info("Respawn Redirect", "RustPluginGenerator", "1.0.0")]
    [Description("Sends respawning players to a configurable location instead of the default spawn point.")]
    public class RespawnRedirect : RustPlugin
    {
        private const string PermBypass = "respawnredirect.admin";

        private PluginConfig config;
        private Vector3 targetPos;
        private Quaternion targetRot;

        private class PluginConfig
        {
            [JsonProperty("Enabled")]
            public bool Enabled = true;

            [JsonProperty("Target position (x y z)")]
            public string TargetPosition = "";

            [JsonProperty("Target rotation yaw (degrees)")]
            public float TargetYaw = 0f;
        }

        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 System.Collections.Generic.Dictionary<string, string>
            {
                ["Redirected"] = "Your respawn has been moved to the server lobby at {0}."
            }, this);
        }

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

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

            if (!string.IsNullOrEmpty(config.TargetPosition))
            {
                var parts = config.TargetPosition.Split(' ');
                if (parts.Length == 3 &&
                    float.TryParse(parts[0], out var x) &&
                    float.TryParse(parts[1], out var y) &&
                    float.TryParse(parts[2], out var z))
                {
                    targetPos = new Vector3(x, y, z);
                    targetRot = Quaternion.Euler(0f, config.TargetYaw, 0f);
                    Puts("Respawn target set to " + targetPos);
                }
                else
                {
                    PrintWarning("TargetPosition in config is malformed; respawns will not be redirected");
                }
            }
        }

        private object OnPlayerRespawn(BasePlayer player, object spawnArg)
        {
            if (!config.Enabled || player == null) return null;
            if (targetPos == Vector3.zero) return null;

            // Leave sleeping-bag respawns alone.
            if (!(spawnArg is BasePlayer.SpawnPoint)) return null;

            if (player.IsAdmin || permission.UserHasPermission(player.UserIDString, PermBypass)) return null;

            player.ChatMessage(Msg("Redirected", player.UserIDString, targetPos));

            return new BasePlayer.SpawnPoint
            {
                pos = targetPos,
                rot = targetRot
            };
        }
    }
}

The plugin registers a respawnredirect.admin permission and a Config with an enabled flag and a target position. OnPlayerRespawn checks the config, skips admins with the permission, and skips players who are using a sleeping bag (by testing is BasePlayer.SpawnPoint). When the conditions match, it builds a new BasePlayer.SpawnPoint with the configured position and rotation and returns it, so the game sends the player there instead of the default beach. If the config position is unset, the original spawn point is left untouched by returning null.

Common use cases

  • Send new players to a spawn lobby

    Return a custom SpawnPoint when the player is being respawned, so they always appear at your welcome area before teleporting anywhere else.

  • Log sleeping bag respawns

    Declare the second parameter as SleepingBag and record which bag (owner, position) each respawn used, useful for raid analysis.

  • Nudge respawns away from contested zones

    If the computed spawn point is too close to a raided base or another team, return a SpawnPoint that is a few meters away.

Pitfalls

  • Two different second arguments

    The hook fires with a SpawnPoint in one place and a SleepingBag in another. Declaring BasePlayer.SpawnPoint makes Oxide skip the sleeping-bag calls; declare object or a base type if you need both.

  • Player is not yet at the destination

    The hook fires before RespawnAt runs. If you need coordinates after the player has actually moved, use OnPlayerRespawned or OnPlayerSpawn instead.

  • Returning a fresh SpawnPoint overrides config only

    Returning a SpawnPoint skips the death-position override and any other logic the game applied earlier. Do not return a value if your plugin is just monitoring respawns.

Build a plugin with OnPlayerRespawn

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

Prompt: Send new players to a spawn lobby using the OnPlayerRespawn 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 OnPlayerRespawn

Generate