Skip to content
RustPluginGenerator

OnDoorOpened

OnDoorOpened is called after a player opens a door, fired from Door.RPC_OpenDoor once the open logic and blockages check have run.

Signature
void OnDoorOpened(Door door, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
doorDoorThe Door entity that was opened. Cast it to the specific door type (e.g. CodeLock, KeyLock, or a ModdedDoor subclass) or read its transform and OwnerID for context.
playerBasePlayerThe BasePlayer who triggered the open RPC. This is the interacting player, not necessarily the door owner.

Return value

The return value is ignored; returning null or any object has no effect on the door open. Use this hook for side effects only.

How it works

OnDoorOpened fires when a player opens any Door entity in the world, including single and double doors, garage doors, and doors with locks or keys. The game calls it from Door.RPC_OpenDoor, after OnPlayerOpenedDoor and the blockage check, so the door is already open when your plugin runs. The door parameter is the exact entity, useful for reading its position, OwnerID, buildingID, or casting it to a lock-equipped type. The player parameter is the opening player, so you can apply per-player effects such as permissions, counter tracking, or chat feedback.

Because the hook fires on every player-initiated open, it is a natural place for anti-griefing rules, base entry alerts, and per-player door restrictions. Declaring Door door keeps the hook locked to door entities only; to react to a subset (e.g. code locks), inspect the entity after the fact rather than narrowing the parameter type. The return value is ignored, so this is a notification hook: you cannot cancel the open by returning anything.

Example plugin: Award permission-gated door open rewards

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

namespace Oxide.Plugins
{
    [Info("Door Reward", "RustPluginGenerator", "1.0.0")]
    [Description("Gives scrap to players with a permission when they open a door, with a cooldown.")]
    public class DoorReward : RustPlugin
    {
        private const string PermUse = "doorreward.use";

        private PluginConfig config;
        private readonly Dictionary<ulong, float> lastReward = new Dictionary<ulong, float>();

        private class PluginConfig
        {
            [JsonProperty("Reward amount")]
            public int RewardAmount = 5;

            [JsonProperty("Cooldown seconds")]
            public float CooldownSeconds = 120f;
        }

        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>
            {
                ["Reward"] = "You received {0} scrap for opening a door."
            }, 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(PermUse, this);
        }

        private void OnDoorOpened(Door door, BasePlayer player)
        {
            if (door == null || player == null || player.IsNpc || !player.IsConnected) return;
            if (!permission.UserHasPermission(player.UserIDString, PermUse)) return;

            float now = UnityEngine.Time.realtimeSinceStartup;
            float last;
            if (lastReward.TryGetValue(player.userID.Get(), out last) && now - last < config.CooldownSeconds) return;
            lastReward[player.userID.Get()] = now;

            Item item = ItemManager.CreateByName("scrap", config.RewardAmount);
            if (item != null)
            {
                player.GiveItem(item);
            }
            player.ChatMessage(Msg("Reward", player.UserIDString, config.RewardAmount));
        }

        private void Unload()
        {
            lastReward.Clear();
        }
    }
}

The plugin checks the opening player against a permission and a cooldown when they open a door. If they are allowed, it gives scrap and a chat message after a short delay using GiveItem and the language file. Cooldowns are tracked inside the plugin; the reward config is editable. The hook is a private method matching the exact signature, and it null-checks both parameters. Because non-rewarding opens are ignored, no message is sent on every door. This makes the server reward players who hold a specific permission and use doors normally.

Common use cases

  • Entry alerts for base owners

    Notify the door owner (or their team) when someone opens their door by checking door.OwnerID and sending a private message.

  • Restrict doors by permission

    Use the hook to detect limited-access doors and close them for players without the required permission, or apply a damage/teleport effect.

  • Track door usage statistics

    Count opens per player for server leaderboards, store the counts with DataFileSystem, and display them on command.

Pitfalls

  • Hook fires after the open

    The door is already open when the hook runs. If you need to block a player from opening a door, use a different vector such as the lock's CanUseLockedEntity hook.

  • NPC and non-player opens

    The player parameter can be null when the open is triggered without a real player. Always null-check before reading player.UserIDString or sending messages.

  • Do not spam chat

    Doors open often on busy servers. Restrict messages to the owner or team, or add a cooldown before sending chat/UI.

Plugin recipes that use OnDoorOpened

Build a plugin with OnDoorOpened

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

Prompt: Entry alerts for base owners using the OnDoorOpened 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 OnDoorOpened

Generate