Skip to content
RustPluginGenerator

CanLootPlayer

CanLootPlayer is called when a player tries to open the loot of another player, before BasePlayer.CanBeLooted decides whether the looting is allowed.

Signature
object CanLootPlayer(BasePlayer player, BasePlayer player2)

Parameters

Hook parameters
ParameterTypeDescription
playerBasePlayerThe player being looted, i.e. the owner of the lootable body. In Oxide dispatch this is the instance the game method is called on, so declaring it as BasePlayer matches any player corpse or wounded player being targeted.
player2BasePlayerThe player attempting to open the loot. Compare it against player to allow or deny self-looting, or inspect team membership to permit squadmates.

Return value

Return false to deny the loot attempt and true to allow it, bypassing the vanilla check. Return null (or nothing) to let the default logic run and decide whether looting proceeds.

How it works

The hook fires inside BasePlayer.CanBeLooted, which the game calls when a player presses use on a lootable player body (sleeping/wounded players and player corpses). Both parameters are BasePlayer: player is the body being looted and player2 is the person who initiated the loot. The game first asks the hook, and only if the hook returns nothing does it run its own check (rejecting when player2 is the same as player).

Declaring both parameters as BasePlayer matches every call, since both arguments are always players. There is no more specific type to narrow here. Because the hook sits at the entry of CanBeLooted, it also gates the rest of the vanilla logic, so returning false blocks looting regardless of distance, team, or death state.

Use it to enforce server rules: block looting teammates, block looting sleeping bodies in safe zones, block looting of bodies that belong to a protected group, or allow looting only when the owner is dead. Return true to allow and to skip the vanilla check (including the self-loot guard), false to deny, or null to fall through to normal behavior.

Example plugin: Block looting of teammates

TeamLootGuard.cs
using System.Collections.Generic;
using System;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Team Loot Guard", "RustPluginGenerator", "1.0.0")]
    [Description("Blocks or allows looting of teammates' bodies through the CanLootPlayer hook.")]
    public class TeamLootGuard : RustPlugin
    {
        private const string PermBypass = "teamlootguard.bypass";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Block looting of teammates")]
            public bool BlockTeamLoot { get; set; } = true;

            [JsonProperty("Notify the looter when blocked")]
            public bool NotifyLooter { get; set; } = true;
        }

        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>
            {
                ["NoTeamLoot"] = "You cannot loot the body of a teammate."
            }, this);
        }

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

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

        private object CanLootPlayer(BasePlayer player, BasePlayer player2)
        {
            if (player == null || player2 == null) return null;
            if (player == player2) return null; // vanilla self-loot guard handles this

            if (!config.BlockTeamLoot) return null;
            if (permission.UserHasPermission(player2.UserIDString, PermBypass)) return null;

            ulong ownerTeam = player.currentTeam;
            ulong looterTeam = player2.currentTeam;
            if (ownerTeam == 0 || looterTeam == 0 || ownerTeam != looterTeam) return null;

            if (config.NotifyLooter)
            {
                player2.ChatMessage(Msg("NoTeamLoot", player2.UserIDString));
            }

            return false;
        }
    }
}

The plugin adds a config flag that controls whether a player may loot a body belonging to a teammate. In CanLootPlayer it ignores self-looting (that is handled by vanilla) and otherwise checks currentTeam on both players. If either has no team, or the teams differ, it returns null so normal behavior applies. When both share a team and BlockTeamLoot is on, it returns false and sends the looter a localized chat message. If team looting is allowed, true is returned so the vanilla self-loot guard is skipped for squadmates.

Common use cases

  • Prevent squad looting

    Stop teammates from looting each other's sleeping bodies, preventing griefing inside a team without affecting enemy looting.

  • Safe-zone body protection

    Deny looting of bodies that lie inside a monument or event zone by checking the owner's position before allowing the open.

  • Owner-only corpse access

    Return false for everyone but the owner so a player's corpse loot is reserved for a limited time.

Pitfalls

  • Returning true skips the self-loot guard

    The vanilla check rejects looting yourself when player and player2 are the same. Returning true disables that, so handle player == player2 explicitly before allowing.

  • Corpses and waking players share the path

    CanBeLooted is used for sleeping/wounded players and their corpses. If you want to protect only corpses, check for LootableCorpse or the death state inside the hook.

  • No self-loot message from the hook

    Denying here shows no message on its own; send your own chat or UI feedback, but keep logging out of this hook since it fires on every loot attempt.

Plugin recipes that use CanLootPlayer

Build a plugin with CanLootPlayer

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

Prompt: Prevent squad looting using the CanLootPlayer 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 CanLootPlayer

Generate