Today's forced wipe update 08/03/2023 appears to have broken the plugin. I have unloaded, reloaded... does not randomize the skins on craft anymore.
Latest Update, plugin isn't working anymore...
same problem
This is the error recieved
Error while compiling: ItemSkinRandomizer.cs(136,72): error CS1061: Type `ItemCraftTask' does not contain a definition for `owner' and no extension method `owner' of type `ItemCraftTask' could be found. Are you missing an assembly reference?
ditto
edit lines 40~55 so they like this:
private void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter itemCrafter)
{
if (task.skinID != 0)
{
return;
}
if (permission.UserHasPermission(itemCrafter.owner.UserIDString, permUse) == false)
{
return;
}
if (config.blockedItems.Contains(item.info.shortname))
{
return;
}
DanHedit lines 40~55 so they like this:
private void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter itemCrafter)
{
if (task.skinID != 0)
{
return;
}
if (permission.UserHasPermission(itemCrafter.owner.UserIDString, permUse) == false)
{
return;
}
if (config.blockedItems.Contains(item.info.shortname))
{
return;
}
Updating the .cs plugin file, from lines 40 - 55 ... overwriting the below (this is what's at line 40 - 55), will resolve the issue?
[JsonProperty("Blocked skin id's")] public ulong[] BlockedSkins =
{
12,
345,
6789
};
[JsonProperty("Blocked items")] public string[] BlockedItems =
{
"grenade.f1",
"explosive.satchel"
};
[JsonProperty("Set random skins for entities?")]
public bool UseEntities = true;
You change[code] private void OnItemCraftFinished(ItemCraftTask task, Item item) { if (task.skinID != 0 || !permission.UserHasPermission(task.owner.UserIDString, permUse) || _config.BlockedItems.Contains(item.info.shortname)) return; SetRandomSkin(null, item); }[/code]to[code] private void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter itemCrafter) { if (task.skinID != 0 || !permission.UserHasPermission(itemCrafter.owner.UserIDString, permUse) || _config.BlockedItems.Contains(item.info.shortname)) return; SetRandomSkin(null, item); }[/code]
Any idea when we will see an update?
thx damizum that worked for me.
Look for:
private void OnItemCraftFinished(ItemCraftTask task, Item item)
{
if (task.skinID != 0 || !permission.UserHasPermission(task.owner.UserIDString, permUse) ||
_config.BlockedItems.Contains(item.info.shortname)) return;
SetRandomSkin(null, item);
}And Chnage to:
private void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter itemCrafter)
{
if (task.skinID != 0 || !permission.UserHasPermission(itemCrafter.owner.UserIDString, permUse) ||
_config.BlockedItems.Contains(item.info.shortname)) return;
SetRandomSkin(null, item);
} Worked for me Thx. THANKS! WORKED!m3dus4thx damizum that worked for me.
Look for:private void OnItemCraftFinished(ItemCraftTask task, Item item) { if (task.skinID != 0 || !permission.UserHasPermission(task.owner.UserIDString, permUse) || _config.BlockedItems.Contains(item.info.shortname)) return; SetRandomSkin(null, item); }And Chnage to:
Worked for me Thx.private void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter itemCrafter) { if (task.skinID != 0 || !permission.UserHasPermission(itemCrafter.owner.UserIDString, permUse) || _config.BlockedItems.Contains(item.info.shortname)) return; SetRandomSkin(null, item); }
@NO1B4ME sorry, i use a different version. But yes just change the code like danmizu posted its all the same
I had changed the code, it worked ... with a little hesitation. It did not change the item skin in inventory, when placed it changed. But that aside, I noticed console wigging out with some errors. Sorry I didn't copy them, I simply removed the plugin and went to bed. lol
Anyone else noticing console errors with the changes above, thinking something still not right even though its kinda working now wit that change.
Any update on getting this plugin fixed, it is a great simple plugin.
Tatra813Any update on getting this plugin fixed, it is a great simple plugin.
follow the instructions above you. It worked for me.
I have made some changes to the plugins core, you can use this. works for me properly. Maybe the owner sometime will update this plugin...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Rust.Workshop;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Item Skin Randomizer", "edited by Maybe, Origin by Mevent", "1.6.4")]
[Description("Selects a random approved skin for crafted items and optionally deployable entities.")]
public class ItemSkinRandomizer : RustPlugin
{
private const string PermUse = "itemskinrandomizer.use";
private const string PermUseEntities = "itemskinrandomizer.useentities";
private const string PermReSkin = "itemskinrandomizer.reskin";
private readonly Dictionary<string, List<ulong>> _skins = new Dictionary<string, List<ulong>>();
private bool _skinsReady;
private static ConfigData _config;
private class ConfigData
{
[JsonProperty("Commands")]
public string[] Commands =
{
"reskin",
"rskin",
"randomskin"
};
[JsonProperty("Blocked skin id's")]
public ulong[] BlockedSkins =
{
12,
345,
6789
};
[JsonProperty("Blocked items")]
public string[] BlockedItems =
{
"grenade.f1",
"explosive.satchel"
};
[JsonProperty("Set random skins for entities?")]
public bool UseEntities = true;
[JsonProperty("Blocked entities")]
public string[] BlockedEntities =
{
"grenade.f1",
"explosive.satchel"
};
[JsonProperty("Delay skin generation after server init (seconds)")]
public float SkinGenerationDelay = 10f;
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
_config = Config.ReadObject<ConfigData>();
if (_config == null)
LoadDefaultConfig();
}
catch
{
PrintError("Configuration file is corrupt. Generating default config.");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig()
{
_config = new ConfigData();
}
protected override void SaveConfig()
{
Config.WriteObject(_config, true);
}
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Permission"] = "You don't have permission to use that.",
["NoObject"] = "Hold an item or look at a valid object.",
["ChangedTo"] = "Skin changed to {0}.",
["CantBuild"] = "You need building privilege to use that."
}, this);
}
private void Init()
{
permission.RegisterPermission(PermUse, this);
permission.RegisterPermission(PermUseEntities, this);
permission.RegisterPermission(PermReSkin, this);
AddCovalenceCommand(_config.Commands, nameof(CmdControl));
if (!_config.UseEntities)
Unsubscribe(nameof(OnEntitySpawned));
}
private void OnServerInitialized()
{
_skinsReady = false;
timer.Once(Mathf.Max(1f, _config.SkinGenerationDelay), GenerateSkinsSafe);
}
private void Unload()
{
_skins.Clear();
_skinsReady = false;
_config = null;
}
private void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter crafter)
{
if (!_skinsReady)
return;
if (task == null || item?.info == null || crafter?.owner == null)
return;
if (task.skinID != 0)
return;
if (!permission.UserHasPermission(crafter.owner.UserIDString, PermUse))
return;
if (_config.BlockedItems != null && _config.BlockedItems.Contains(item.info.shortname))
return;
SetRandomSkin(null, item);
}
private void OnEntitySpawned(BaseEntity entity)
{
if (!_skinsReady || !_config.UseEntities)
return;
if (entity == null || entity.OwnerID == 0 || entity.skinID != 0)
return;
if (!permission.UserHasPermission(entity.OwnerID.ToString(), PermUseEntities))
return;
if (_config.BlockedEntities != null && _config.BlockedEntities.Contains(entity.ShortPrefabName))
return;
SetRandomSkin(null, entity);
}
private void CmdControl(IPlayer cov, string command, string[] args)
{
var player = cov?.Object as BasePlayer;
if (player == null)
return;
if (!cov.HasPermission(PermReSkin))
{
Message(player, "Permission");
return;
}
if (!_skinsReady)
{
player.ChatMessage("Skins are still loading. Try again in a few seconds.");
return;
}
var item = player.GetActiveItem();
if (item != null)
{
SetRandomSkin(player, item);
return;
}
if (!player.CanBuild())
{
Message(player, "CantBuild");
return;
}
var entity = GetLookEntity<BaseEntity>(player, 5f);
if (entity != null)
{
SetRandomSkin(player, entity);
return;
}
Message(player, "NoObject");
}
private void GenerateSkinsSafe()
{
try
{
GenerateSkins();
_skinsReady = true;
Puts($"Loaded random skins for {_skins.Count} item shortnames.");
}
catch (Exception ex)
{
PrintError($"Failed to generate skin cache: {ex.Message}");
}
}
private void GenerateSkins()
{
_skins.Clear();
if (Approved.All == null)
return;
foreach (var entry in Approved.All.Values)
{
if (entry == null || entry.Skinnable == null)
continue;
var skinId = entry.WorkshopdId;
if (skinId == 0)
continue;
if (_config.BlockedSkins != null && _config.BlockedSkins.Contains(skinId))
continue;
var key = entry.Skinnable.ItemName;
if (string.IsNullOrEmpty(key))
continue;
if (key.Contains("lr300"))
key = "rifle.lr300";
if (!_skins.TryGetValue(key, out var list))
{
list = new List<ulong>();
_skins[key] = list;
}
if (!list.Contains(skinId))
list.Add(skinId);
}
foreach (var pair in _skins.Where(p => p.Value.Count == 0).ToList())
_skins.Remove(pair.Key);
}
private void SetRandomSkin(BasePlayer player, Item item)
{
if (item?.info == null)
return;
var skin = GetRandomSkin(item.info.shortname);
if (skin == 0)
return;
item.skin = skin;
item.MarkDirty();
var held = item.GetHeldEntity();
if (held != null)
{
held.skinID = skin;
held.SendNetworkUpdate();
}
Message(player, "ChangedTo", skin);
}
private void SetRandomSkin(BasePlayer player, BaseEntity entity)
{
if (entity == null)
return;
var shortname = entity.ShortPrefabName;
switch (shortname)
{
case "sleepingbag_leather_deployed":
shortname = "sleepingbag";
break;
case "vendingmachine.deployed":
shortname = "vending.machine";
break;
case "woodbox_deployed":
shortname = "box.wooden";
break;
case "reactivetarget_deployed":
shortname = "target.reactive";
break;
default:
shortname = Regex.Replace(shortname, "\\.deployed|_deployed", "");
shortname = FixNames(shortname);
break;
}
var def = ItemManager.FindItemDefinition(shortname);
if (def == null)
return;
var skin = GetRandomSkin(def.shortname);
if (skin == 0)
return;
entity.skinID = skin;
entity.SendNetworkUpdate();
Message(player, "ChangedTo", skin);
}
private ulong GetRandomSkin(string key)
{
if (string.IsNullOrEmpty(key))
return 0;
return _skins.TryGetValue(key, out var list) && list != null && list.Count > 0
? list.GetRandom()
: 0;
}
private static string FixNames(string name)
{
switch (name)
{
case "wall.external.high.wood": return "wall.external.high";
case "electric.windmill.small": return "generator.wind.scrap";
case "graveyardfence": return "wall.graveyard.fence";
case "coffinstorage": return "coffin.storage";
default: return name;
}
}
private static T GetLookEntity<T>(BasePlayer player, float maxDistance) where T : class
{
if (player == null)
return null;
if (!Physics.Raycast(player.eyes.HeadRay(), out var hit, maxDistance))
return null;
var entity = hit.GetEntity();
return entity as T;
}
private void Message(BasePlayer player, string key, params object[] args)
{
if (player == null)
return;
player.ChatMessage(string.Format(lang.GetMessage(key, this, player.UserIDString), args));
}
}
}