Skip to content
RustPluginGenerator

OnStashHidden

OnStashHidden is called after a player hides a small stash (the deployable StashContainer) that was previously buried in the ground. It fires from StashContainer.RPC_HideStash, right after the entity is switched to the hidden state.

Signature
void OnStashHidden(StashContainer stashContainer, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
stashContainerStashContainerThe StashContainer entity that was just hidden. Use it to read its net.ID, position, inventory or owner and to compare it against tracked stashes.
playerBasePlayerThe BasePlayer who performed the hide interaction. It can be null-checked like any player argument, though the RPC path normally supplies a real player.

Return value

The return value is ignored; the patcher uses continue. Whatever you return, the hide has already been applied and the original method completes normally. Use CanHideStash if you need to stop a stash from being hidden.

How it works

This hook runs when a player interacts with a small stash and the server hides it. The injection point is StashContainer.RPC_HideStash: the game first calls CanHideStash; only if that conversation returns null does it record analytics, call SetHidden(isHidden: true) and then fire OnStashHidden. So by the time your method runs, the stash is already hidden and visible in the world only as a subtle marker. Practical uses are bookkeeping and anti-abuse, not cancellation: the hide has already happened, and blocking it is the job of CanHideStash.

stashContainer is the entity itself. You can read net.ID.Value, transform.position, OwnerID, the attached inventory, or check flags. player is the player who triggered the RPC.

Narrowing is not useful here because the injection already passes the concrete StashContainer and BasePlayer types, so there is nothing to widen or skip. Keep the handler cheap since it can fire whenever players bury stashes, and never print to console inside it.

Example plugin: Notify owners when their stash is hidden

StashHideNotifier.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Stash Hide Notifier", "RustPluginGenerator", "1.0.0")]
    [Description("Notifies players with chat and coordinates when they hide a stash.")]
    public class StashHideNotifier : RustPlugin
    {
        private const string PermUse = "stashhidenotifier.use";

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

        private class PluginConfig
        {
            [JsonProperty("Notify on hide")]
            public bool NotifyOnHide = true;

            [JsonProperty("Cooldown seconds between messages")]
            public float CooldownSeconds = 15f;
        }

        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>
            {
                ["Hidden"] = "Stash hidden at {0}.",
                ["Cooldown"] = "You are hiding stashes too quickly. Wait a moment."
            }, 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 OnStashHidden(StashContainer stashContainer, BasePlayer player)
        {
            if (stashContainer == null || player == null || !config.NotifyOnHide) return;
            if (!permission.UserHasPermission(player.UserIDString, PermUse)) return;

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

            lastNotify[player.userID.Get()] = now;

            Vector3 pos = stashContainer.transform.position;
            string coords = string.Format("{0:F0} {1:F0} {2:F0}", pos.x, pos.y, pos.z);
            player.ChatMessage(Msg("Hidden", player.UserIDString, coords));
        }

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

The plugin records each player's last stash-hide time and reports where the stash was hidden, so owners can keep track of placements. OnStashHidden looks up the hiding player, computes the position, and sends a localized chat message only if enough time has passed since the previous hide (a simple spam guard stored in a Dictionary<ulong, float> keyed by user ID). The cooldown comes from the config file, and messages are registered through the language API so servers can translate them. No world state is changed; the plugin is purely informational and cheap to run.

Common use cases

  • Placement audit log

    Record who hid a stash and where, and write the entries to an oxide/data file for staff review of suspicious stash patterns.

  • Raider notification

    Alert nearby players or a team chat that a stash was just buried, giving counter-play information in PvP server modes.

  • Quest and achievement tracking

    Progress a 'hide 5 stashes' objective or grant a reward the first time a player hides a stash on the server.

Pitfalls

  • Cannot cancel the hide

    OnStashHidden fires after SetHidden(true) and its return value is discarded. Use CanHideStash when you need to prevent a hide.

  • Null player edge cases

    Always null-check the player and the stash container before reading position or sending messages, even though normal RPC paths supply both.

  • Spam from repeated burials

    Players can hide and expose stashes repeatedly. Gate any chat output or data writes behind a per-player cooldown to avoid flooding.

Build a plugin with OnStashHidden

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

Prompt: Placement audit log using the OnStashHidden 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 OnStashHidden

Generate