Skip to content
RustPluginGenerator

OnDefaultItemsReceive

OnDefaultItemsReceive is called at the start of PlayerInventory.GiveDefaultItems, right before the game strips the inventory and hands out the default loadout for the player's game mode. Returning a non-null value cancels that default loadout entirely.

Signature
object OnDefaultItemsReceive(PlayerInventory playerInventory)

Parameters

Hook parameters
ParameterTypeDescription
playerInventoryPlayerInventoryThe PlayerInventory instance whose owner is about to receive the default starting loadout. Get the player with playerInventory.baseEntity (a BasePlayer); the container players hold items in is playerInventory.containerMain.

Return value

Return null to let GiveDefaultItems continue: the game strips the inventory and applies the default loadout. Return any non-null object to abort the method immediately, so no default items are given and the built-in Strip() is skipped.

How it works

This hook fires inside PlayerInventory.GiveDefaultItems, a server-side method the game runs when a player spawns into a fresh life that should get starting items. Because the call sits at the very top of the method, it fires before the game calls Strip() and before any game-mode-specific items are handed out. You get the PlayerInventory rather than the BasePlayer, so reach the owner through playerInventory.baseEntity (check for null; NPCs and odd inventories can show up) and access the containers via containerMain, containerBelt and containerWear. Parameter types cannot be narrowed here: the hook only exists with a PlayerInventory argument, and Oxide always passes the same type. To cancel the entire default loadout return any non-null object; return null to let the game proceed normally. A common pattern is to suppress defaults and give your own kit inside the hook, but note that the Strip() call happens after the hook returns, so items you add while returning non-null would survive only if you add them on the next tick or let the game finish first.

Example plugin: Replace default items with a custom server starter kit

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

namespace Oxide.Plugins
{
    [Info("Custom Starter Items", "RustPluginGenerator", "1.0.0")]
    [Description("Replaces the default loadout with a configurable starter kit")]
    public class CustomStarterItems : RustPlugin
    {
        private const string PermUse = "customstarteritems.use";

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

        private class KitEntry
        {
            [JsonProperty("Item shortname")]
            public string Shortname;
            [JsonProperty("Amount")]
            public int Amount;
        }

        private class PluginConfig
        {
            [JsonProperty("Items in the starter kit")]
            public List<KitEntry> Items = new List<KitEntry>
            {
                new KitEntry { Shortname = "rock", Amount = 1 },
                new KitEntry { Shortname = "torch", Amount = 1 },
                new KitEntry { Shortname = "bandage", Amount = 3 }
            };
            [JsonProperty("Cooldown between grants (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>
            {
                ["KitGiven"] = "You received the starter kit.",
                ["NoPermission"] = "You do not receive the starter kit."
            }, 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 object OnDefaultItemsReceive(PlayerInventory playerInventory)
        {
            if (playerInventory == null) return null;
            BasePlayer player = playerInventory.baseEntity;
            if (player == null || player.IsNpc || player.IsDead()) return null;

            ulong id = player.userID.Get();
            float now = UnityEngine.Time.realtimeSinceStartup;
            float last;
            if (lastGranted.TryGetValue(id, out last) && now - last < config.CooldownSeconds)
                return true;

            lastGranted[id] = now;

            if (!permission.UserHasPermission(player.UserIDString, PermUse))
                return true;

            BasePlayer target = player;
            NextTick(() =>
            {
                if (target == null || !target.IsConnected) return;
                GiveKit(target);
            });
            return true;
        }

        private void GiveKit(BasePlayer player)
        {
            foreach (KitEntry entry in config.Items)
            {
                if (entry == null || string.IsNullOrEmpty(entry.Shortname) || entry.Amount <= 0) continue;
                Item item = ItemManager.CreateByName(entry.Shortname, entry.Amount, 0UL);
                if (item == null) continue;
                if (!player.inventory.GiveItem(item))
                    item.Drop(player.transform.position + new Vector3(0f, 1f, 0f), Vector3.zero);
            }
            player.ChatMessage(Msg("KitGiven", player.UserIDString));
        }

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

The plugin lets admins define a list of shortnames and amounts in the config. When GiveDefaultItems would run, the hook returns a non-null value to block the vanilla loadout, then schedules the custom kit for the next tick with NextTick. Scheduling matters because the game's own Strip() would otherwise run right after the hook and wipe anything added immediately. A per-player cooldown prevents handing out the kit repeatedly when the game re-triggers the default-items path during respawns. Items are created with ItemManager.CreateByName and moved into the main container, with a chat message confirming the grant.

Common use cases

  • Give a custom starter kit

    Suppress the vanilla loadout and hand out your own configured items so every fresh spawn starts on an even footing.

  • Disable default items entirely

    Return non-null with no kit to force players to loot everything, useful for hardcore or event servers.

  • Rank-based loadouts

    Inspect playerInventory.baseEntity and check permissions to decide which loadout (if any) a player receives.

Pitfalls

  • Items added in the hook get stripped

    The game calls Strip() after the hook returns. Give items on the next tick (or via a timer) rather than inside the hook body when you are also blocking the default path.

  • It fires more than once per session

    Respawns and mode-specific flows can call GiveDefaultItems again. Track a flag or cooldown per userID to avoid duplicating kits.

  • baseEntity can be null

    Always null-check playerInventory.baseEntity and its userID before using it; not every inventory belongs to a connected player.

Build a plugin with OnDefaultItemsReceive

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

Prompt: Give a custom starter kit using the OnDefaultItemsReceive 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 OnDefaultItemsReceive

Generate