C#:
using System.Collections.Generic;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("NoDroneExplo", "Trash ", "1.0.0")]
[Description("Prevents players from placing explosives or grenades into player drones.")]
public class NoDroneExplo : RustPlugin
{
private readonly HashSet<string> _blockedItems = new HashSet<string>
{
"explosive.timed.deployed",
"explosive.timed.entity",
"grenade.f1.deployed",
"grenade.f1.entity",
"explosive.timed",
"grenade.f1"
};
object CanMoveItem(Item item, PlayerInventory playerLoot, ItemContainerId targetContainerId, int targetSlot, int amount)
{
if (item == null || playerLoot == null)
return null;
if (!_blockedItems.Contains(item.info.shortname))
return null;
ItemContainer targetContainer = playerLoot.FindContainer(targetContainerId);
if (targetContainer == null)
return null;
if (!IsAttachedToDrone(targetContainer))
return null;
BasePlayer player = playerLoot.GetComponent<BasePlayer>();
if (player != null)
SendReply(player, lang.GetMessage("Blocked", this, player.UserIDString));
return false;
}
object CanAcceptItem(ItemContainer container, Item item, int targetPos)
{
if (container == null || item == null)
return null;
if (!_blockedItems.Contains(item.info.shortname))
return null;
if (!IsAttachedToDrone(container))
return null;
BasePlayer player = item.GetOwnerPlayer();
if (player != null)
SendReply(player, lang.GetMessage("Blocked", this, player.UserIDString));
return ItemContainer.CanAcceptResult.CannotAccept;
}
private bool IsAttachedToDrone(ItemContainer container)
{
BaseEntity owner = container.entityOwner;
if (owner == null)
return false;
if (owner is Drone)
return true;
BaseEntity parent = owner.GetParentEntity();
if (parent is Drone)
return true;
return false;
}
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Blocked"] = "<color=#ff4444>[Drone]</color> You cannot place explosives or grenades inside a drone."
}, this);
}
}
}