Can you add shortname, item id, and skin id?
I have cash and token that needs to be put in to the tc.
Thank you!
I was wondering if you could add...Suggestion
sure i have been meaning to update this for a while now
i am finally getting around to this right now . expect a pretty big update either later today or tomorrow . sorry for the delay
I made this to get me by, so that I could have this items inside the Tool Cupboard.
using System;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using UnityEngine;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("TcAddItems", "JustANoob", "1.0.0")]
[Description("Add loot (with skins) to tool cupboards when placed")]
public class TcAddItems : RustPlugin
{
private const string PermissionUse = "tcadditems.use";
#region [Load/Unload]
private void Init()
{
permission.RegisterPermission(PermissionUse, this);
}
private void OnServerInitialized()
{
LoadConfig();
}
#endregion
#region [Hooks]
void OnEntitySpawned(BaseEntity ent)
{
var container = ent.GetComponent<StorageContainer>();
if (container == null) return;
if (ent.OwnerID == 0 || ent.IsDestroyed) return;
if (!permission.UserHasPermission(ent.OwnerID.ToString(), PermissionUse)) return;
var prefab = container.ShortPrefabName;
if (config.Settings.AddLoot && config.Tc.TryGetValue(prefab, out var items))
{
SpawnTcLoot(container, items);
}
}
#endregion
#region [Config]
private Configuration config;
protected override void LoadDefaultConfig() => config = Configuration.DefaultConfig();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<Configuration>() ?? Configuration.DefaultConfig();
}
catch (Exception)
{
PrintWarning("Creating new config file.");
config = Configuration.DefaultConfig();
}
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(config, true);
public class Configuration
{
[JsonProperty("Settings")]
public SettingsData Settings = new SettingsData();
[JsonProperty("Loot for")]
public Dictionary<string, List<Loot>> Tc = new Dictionary<string, List<Loot>>();
public class SettingsData
{
[JsonProperty("Add loot to toolcupboard ?")]
public bool AddLoot = true;
}
public static Configuration DefaultConfig()
{
var defaultLoot = new List<Loot>
{
new Loot { ShortName = "wood", SkinId = 0, Amount = 2000 },
new Loot { ShortName = "stones", SkinId = 0, Amount = 3000 },
new Loot { ShortName = "metal.fragments", SkinId = 0, Amount = 1000 },
new Loot { ShortName = "metal.refined", SkinId = 0, Amount = 100 },
new Loot { ShortName = "redidtag", SkinId = 3210845912, Amount = 1 },
new Loot { ShortName = "paper", SkinId = 2420097877, Amount = 8000 },
};
return new Configuration
{
Settings = new SettingsData
{
AddLoot = true
},
Tc = new Dictionary<string, List<Loot>>
{
["cupboard.tool.deployed"] = defaultLoot,
["cupboard.tool.retro.deployed"] = new List<Loot>(defaultLoot),
["cupboard.tool.shockbyte.deployed"] = new List<Loot>(defaultLoot),
}
};
}
}
public class Loot
{
[JsonProperty("ShortName")]
public string ShortName;
[JsonProperty("SkinId")]
public ulong SkinId;
[JsonProperty("Amount")]
public int Amount;
}
#endregion
#region [Methods]
private void SpawnTcLoot(StorageContainer container, List<Loot> items)
{
var inv = container.inventory;
if (inv == null) return;
foreach (var loot in items)
{
var item = ItemManager.CreateByName(loot.ShortName, loot.Amount);
if (item == null) continue;
if (loot.SkinId > 0)
item.skin = loot.SkinId;
item.MoveToContainer(inv, -1, true, true);
item.parent = inv;
item.MarkDirty();
}
}
#endregion
}
} the version im working on now has different loot depending on what permission you have . it also lets you spawn guns with attachments if you really wanted to . you can also give the items custom names ,skinids and set the condition of the item if it has condition . there is also a option to auto auth team mates on the tc when placed
Awesome Job!