я делаю плагин для сервера, где я создаю уникальный ящик, в котором будут спавнятся ресурсы, ну металл камень и тд.
можете помочь?
можете помочь?
Код:
using System;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("BoxPlugin", "Bratura", "1.0.0")]
[Description("Spawns resources in a box placed by a player")]
public class BoxPlugin : RustPlugin
{
private const string Permission_Use = "boxplugin.use";
private void Init()
{
permission.RegisterPermission(Permission_Use, this);
AddCovalenceCommand("box", "CmdBox");
Subscribe<Action<Deployer, BaseEntity>>(nameof(OnItemDeployed));
Puts("BoxPlugin: Initialized");
}
private void CmdBox(IPlayer player, string command, string[] args)
{
if (!player.HasPermission(Permission_Use))
{
player.Reply("You don't have permission to use this command.");
return;
}
var basePlayer = player.Object as BasePlayer;
if (basePlayer != null)
{
var boxDefinition = ItemManager.FindItemDefinition("box.wooden.large");
if (boxDefinition != null)
{
var boxItem = ItemManager.CreateByItemID(boxDefinition.itemid, 1);
if (boxItem != null)
{
basePlayer.GiveItem(boxItem);
}
}
}
Puts($"BoxPlugin: {player.Name} used /box command");
}
private void OnItemDeployed(Deployer deployer, BaseEntity deployedEntity)
{
var storageContainer = deployedEntity as StorageContainer;
if (storageContainer == null) return;
if (deployedEntity.PrefabName.Contains("box.wooden.large"))
{
Puts("Player placed a box");
if (storageContainer != null)
{
Puts("Box built! Spawning resources...");
SpawnResourceInBox(storageContainer);
}
}
}
private void SpawnResourceInBox(StorageContainer boxEntity)
{
if (boxEntity == null || boxEntity.IsDestroyed) return;
var resourceItem = ItemManager.CreateByName("sulfur.ore", 10);
if (resourceItem != null)
{
if (!resourceItem.MoveToContainer(boxEntity.inventory))
{
resourceItem.Remove();
return;
}
boxEntity.SendNetworkUpdate();
}
UnityEngine.Debug.Log("BoxPlugin: Resource spawned in the box");
}
}
}