C#:
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Goldenskull", "https://topplugin.ru/", "1.5.0")]
public class Goldenskull : RustPlugin
{
#region Classes/cfg
private class Configuration
{
public Dictionary<int,CustomItem> CustomItems = new Dictionary<int, CustomItem>
{
[0] = new CustomItem
{
DisplayName = "Золотой череп",
ReplaceShortName = "skull.human",
DropChance = 20,
DropAmount = 1,
ReplaceID = 1683645276,
BarrelList = new Dictionary<string, int>
{
["loot-barrel-1"] = 50,
["loot-barrel-2"] = 20,
},
itemsrec = new List<string>
{
"weapon.mod.small.scope",
"rifle.ak",
"rifle.l96",
"smg.thompson",
"rifle.semiauto",
"pistol.revolver",
"rifle.lr300",
},
itempot = new List<string>
{
"shotgun.double",
"grenade.f1",
"smg.2",
"shotgun.pump",
"pistol.semiauto",
"pistol.python",
"weapon.mod.lasersight",
"weapon.mod.muzzlebrake",
},
}
};
}
private static Configuration Settings = new Configuration();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
Settings = Config.ReadObject<Configuration>();
if (Settings?.CustomItems == null) LoadDefaultConfig();
}
catch
{
PrintWarning("Ошибка #288 чтения конфигурации 'oxide/config/', создаём новую конфигурацию!!");
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
protected override void LoadDefaultConfig() => Settings = new Configuration();
protected override void SaveConfig() => Config.WriteObject(Settings);
public class CustomItem
{
[JsonProperty("Отображаемое имя", Order = 0)]
public string DisplayName;
[JsonProperty("Этот парамтр менять не нужно", Order = 1)]
public string ReplaceShortName;
[JsonProperty("Шанс выпадения", Order = 2)]
public int DropChance;
[JsonProperty("Кол-вл выпадения", Order = 3)]
public int DropAmount;
[JsonProperty("Скин ID черепа", Order = 4)]
public ulong ReplaceID;
[JsonProperty("Из каких бочек будет падать и процент выпадения", Order = 5)]
public Dictionary<string, int> BarrelList = new Dictionary<string, int>();
[JsonProperty("Призы за переработку", Order = 6)]
public List<string> itemsrec = new List<string>();
[JsonProperty("Призы за потрошения", Order = 7)]
public List<string> itempot = new List<string>();
public int GetItemId() => ItemManager.FindItemDefinition(ReplaceShortName).itemid;
public int GetItemAmount(BasePlayer player) => player.inventory.GetAmount(GetItemId());
public Item Copy(int amount = 1)
{
Item x = ItemManager.CreateByPartialName(ReplaceShortName, amount);
x.skin = ReplaceID;
x.name = DisplayName;
return x;
}
public void CreateItem(BasePlayer player, Vector3 position, int amount)
{
Item x = ItemManager.CreateByPartialName(ReplaceShortName, amount);
x.skin = ReplaceID;
x.name = DisplayName;
if (player != null)
{
if (player.inventory.containerMain.itemList.Count < 24)
x.MoveToContainer(player.inventory.containerMain);
else
x.Drop(player.transform.position, Vector3.zero);
return;
}
if (position != Vector3.zero)
{
x.Drop(position, Vector3.down);
return;
}
}
}
#endregion
#region Variables
[PluginReference] private Plugin ImageLibrary;
public Dictionary<string, ulong> Stacks = new Dictionary<string, ulong>();
#endregion
#region command
[ChatCommand("g.give")]
private void cmdChatEmerald(BasePlayer player, string command, string[] args)
{
if (!player.IsAdmin) return;
foreach (var check in Settings.CustomItems)
{
check.Value.CreateItem(player, Vector3.zero, 1000000);
}
}
#endregion
#region hooks
private Item CreateItem()
{
bool goodChance = UnityEngine.Random.Range(0, 100) >= (100 - Settings.CustomItems[0].DropChance);
if (goodChance)
{
return Settings.CustomItems[0].Copy(Settings.CustomItems[0].DropAmount);
}
return null;
}
void OnEntitySpawned(BaseNetworkable entity)
{
if (entity.GetComponent<LootContainer>() == null) return;
var item = (Item)CreateItem();
item?.MoveToContainer(entity.GetComponent<LootContainer>().inventory);
}
void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
{
foreach(var Barrel in Settings.CustomItems[0].BarrelList)
{
if (entity.PrefabName.Contains(Barrel.Key))
{
bool goodChance = UnityEngine.Random.Range(0, 100) >= (100 - Barrel.Value);
if (goodChance)
{
Settings.CustomItems[0].CreateItem(null, entity.transform.position, Settings.CustomItems[0].DropAmount);
}
}
}
}
void OnServerInitialized()
{
foreach (var Stac in Settings.CustomItems) { Stacks.Add(Stac.Value.ReplaceShortName, Stac.Value.ReplaceID); }
var itemInfo = ItemManager.FindItemDefinition(Settings.CustomItems[0].ReplaceShortName);
itemInfo.stackable = 1;
if (itemInfo.GetComponent<ItemModRecycleInto>() == null) itemInfo.gameObject.AddComponent<ItemModRecycleInto>();
var recycleMod = itemInfo.GetComponent<ItemModRecycleInto>();
recycleMod.recycleIntoItem = ItemManager.FindItemDefinition(Settings.CustomItems[0].ReplaceShortName);
recycleMod.numRecycledItemMin = 1;
recycleMod.numRecycledItemMax = 1;
itemInfo = ItemManager.FindItemDefinition(Settings.CustomItems[0].ReplaceShortName);
PrintWarning($"-----------------------------------");
PrintWarning($" Goldenskull ");
PrintWarning($" Author = Тopplugin.ru ");
PrintWarning($" vk.com/top__plugin ");
PrintWarning($" Version = {Version} ");
PrintWarning($"-----------------------------------");
}
object CanRecycle(Recycler recycler, Item item)
{
if (item.info.shortname == "skull.human" && item.skin != Settings.CustomItems[0].ReplaceID) return false;
if (item.info.shortname == "skull.human" && item.skin == Settings.CustomItems[0].ReplaceID)
{
var itemInfo = ItemManager.FindItemDefinition(Settings.CustomItems[0].ReplaceShortName);
var Element = Settings.CustomItems[0].itemsrec.ElementAt(UnityEngine.Random.Range(0, Settings.CustomItems[0].itemsrec.Count)); // Выбираем элемент
if (itemInfo.Blueprint == null) itemInfo.gameObject.AddComponent<ItemBlueprint>();
itemInfo.Blueprint.ingredients = new List<ItemAmount> { new ItemAmount { itemDef = ItemManager.FindItemDefinition(Element), amount = 1 } };
itemInfo.Blueprint.amountToCreate = 1;
}
return null;
}
private Item OnItemSplit(Item item, int amount)
{
var customItem = Settings.CustomItems.FirstOrDefault(p => p.Value.ReplaceShortName == item.info.shortname);
if (customItem.Value != null && customItem.Value.ReplaceID == item.skin)
{
Item x = ItemManager.CreateByPartialName(customItem.Value.ReplaceShortName, amount);
x.name = customItem.Value.DisplayName;
x.skin = customItem.Value.ReplaceID;
x.amount = amount;
item.amount -= amount;
return x;
}
return null;
}
object CanCombineDroppedItem(DroppedItem item, DroppedItem targetItem)
{
if (item.GetItem().skin != targetItem.GetItem().skin)
if (Stacks.ContainsValue(item.GetItem().skin) || Stacks.ContainsValue(targetItem.GetItem().skin)) return false;
return null;
}
object CanStackItem(Item item, Item targetItem)
{
if (item.skin != targetItem.skin)
if (Stacks.ContainsValue(item.skin) || Stacks.ContainsValue(targetItem.skin)) return false;
return null;
}
object OnItemAction(Item item, string action, BasePlayer player)
{
if (item == null || action == null || action == "")
return null;
if (action != "crush")
return null;
if (player == null)
return null;
var items = Settings.CustomItems[0];
if (item.skin != items.ReplaceID) return null;
Item itemS = ItemManager.CreateByName(Settings.CustomItems[0].itempot[UnityEngine.Random.Range(0, Settings.CustomItems[0].itempot.Count - 1)], 1, 0);
player.GiveItem(itemS);
NextTick(() => player.inventory.Take(null, ItemManager.FindItemDefinition("bone.fragments").itemid, 20));
ItemRemovalThink(item, player, 1);
return false;
}
private static void ItemRemovalThink(Item item, BasePlayer player, int itemsToTake)
{
if (item.amount == itemsToTake)
{
item.RemoveFromContainer();
item.Remove();
}
else
{
item.amount = item.amount - itemsToTake;
player.inventory.SendSnapshot();
}
}
#endregion
}
}