using Newtonsoft.Json; using System; using UnityEngine; /* * Changelog: * * Version 1.0.5: * - Added ability to Raycast check if you aren't holding an item, It will output info to console and to a note. */ namespace Oxide.Plugins { [Info("Check", "Wrecks", "1.0.5")] [Description("Check Item Properties.")] public class Check : RustPlugin { #region Config static Configuration config; public class Configuration { [JsonProperty("Note SkinID")] public ulong SkinId { get; set; } public static Configuration DefaultConfig() { return new Configuration { SkinId = 3341490454 }; } } protected override void LoadConfig() { base.LoadConfig(); try { config = Config.ReadObject(); if (config == null) LoadDefaultConfig(); SaveConfig(); } catch (Exception ex) { Debug.LogException(ex); PrintWarning("Creating new configuration file."); LoadDefaultConfig(); } } protected override void LoadDefaultConfig() => config = Configuration.DefaultConfig(); protected override void SaveConfig() => Config.WriteObject(config); #endregion #region Command [ChatCommand("check")] private void CheckCommand(BasePlayer player) { if (!player.IsAdmin) return; var item = player.GetActiveItem(); if (item != null) { CheckItem(player, item); } else { CheckRaycast(player); } } #endregion #region ItemCheck private void CheckItem(BasePlayer player, Item item) { var itemName = string.IsNullOrEmpty(item.name) ? item.info.displayName.english : item.name; var itemSkinId = item.skin; var itemShortname = item.info?.shortname ?? "Invalid"; var itemId = item.info?.itemid; var itemtext = item.text ?? "No Text"; var note = ItemManager.CreateByName("note"); if (note == null) return; note.skin = config.SkinId; note.name = "Properties for " + itemName; note.text = $"Item Name: {itemName}\nSkinID: {itemSkinId}\nItemID: {itemId}\nShortname: {itemShortname}\nText: {itemtext}"; player.GiveItem(note); LogItem(itemName, itemSkinId, itemId, itemShortname, itemtext); } #endregion #region PrefabCheck private void CheckRaycast(BasePlayer player) { if (Physics.Raycast(player.eyes.HeadRay(), out var hit, 5f)) { var hitEntity = hit.GetEntity(); if (hitEntity != null) { var prefabId = hitEntity.net.ID; var prefabShortname = hitEntity.ShortPrefabName; var prefabPath = hitEntity.PrefabName; var layerMask = LayerMask.LayerToName(hitEntity.gameObject.layer); var note = ItemManager.CreateByName("note"); if (note == null) return; note.skin = config.SkinId; note.name = "Properties for " + prefabShortname; note.text = $"Prefab ID: {prefabId}\nPrefab Shortname: {prefabShortname}\nPrefab Path: {prefabPath}\nLayerMask: {layerMask}"; player.GiveItem(note); LogPrefab(prefabId, prefabShortname, prefabPath, layerMask); } else { player.ChatMessage("Entity is Invalid."); } } else { player.ChatMessage("Entity not found."); } } #endregion #region Loggers private void LogItem(string itemName, ulong itemSkinId, int? itemId, string itemShortname, string itemtext) { Puts($"\nItem Properties for {itemName}\n" + $"Item Name: {itemName}\n" + $"SkinID: {itemSkinId}\n" + $"ItemID: {itemId}\n" + $"Shortname: {itemShortname}\n" + $"Text: {itemtext}"); } private void LogPrefab(NetworkableId prefabId, string prefabShortname, string prefabPath, string layerMask) { Puts($"\nPrefab Properties\n" + $"Prefab ID: {prefabId}\n" + $"Prefab Shortname: {prefabShortname}\n" + $"Prefab Path: {prefabPath}\n" + $"LayerMask: {layerMask}"); } #endregion } }