using System; using System.Linq; using System.Reflection; using System.Collections.Generic; using UnityEngine; using Oxide.Core.Plugins; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Rust; using Rust.Ai.Gen2; using Facepunch; #region Changelogs and ToDo /********************************************************************** * * 1.0.0 - Release * 1.0.1 - Added support for the new wolf AI (wolf2) * **********************************************************************/ #endregion namespace Oxide.Plugins { [Info("NotifyAnimalFeed", "Krungh Crow", "1.0.1")] [Description("Simplified Animal killfeed for Notify")] class NotifyAnimalFeed : RustPlugin { [PluginReference] Plugin Notify, UINotify; #region Variables const string Use_Perm = "notifyanimalfeed.use"; string _MSG; string prefix; #endregion #region Configuration void Init() { if (!LoadConfigVariables()) { Puts("Config file issue detected. Please delete file, or check syntax and fix."); return; } permission.RegisterPermission(Use_Perm, this); } private ConfigData configData; class ConfigData { [JsonProperty(PropertyName = "Notify profile ID")] public int PiD = 0; } private bool LoadConfigVariables() { try { configData = Config.ReadObject(); } catch { return false; } SaveConf(); return true; } protected override void LoadDefaultConfig() { Puts("Fresh install detected Creating a new config file."); configData = new ConfigData(); SaveConf(); } void SaveConf() => Config.WriteObject(configData, true); #endregion #region LanguageAPI protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["FeedAnimal"] = "{Killer} killed a {Victim} with a {Weapon} from {_Distance}m", ["Bear"] = "Bear", ["PolarBear"] = "Polar Bear", ["Boar"] = "Boar", ["Chicken"] = "Chicken", ["Horse"] = "Wild Horse", ["Stag"] = "Stag", ["Wolf"] = "Wolf", ["SimpleShark"] = "Shark" }, this); } #endregion #region Hooks object OnEntityDeath(BaseAnimalNPC npc, HitInfo info) { if (npc == null || info.InitiatorPlayer == null) return true; if (info.InitiatorPlayer.userID.IsSteamId()); { BasePlayer attacker = info.InitiatorPlayer; int _Distance = (int)Vector3.Distance(attacker.transform.position, npc.transform.position); var WeaponName = GetWeaponName(info); var Killer = attacker.displayName.ToString(); var Victim = GetAnimalType(npc); Puts($"{Killer} killed A {Victim} with a {WeaponName}"); string _MSG = msginfo("FeedAnimal").Replace("{Killer}", Killer).Replace("{Victim}", Victim).Replace("{Weapon}", WeaponName).Replace("{_Distance}", _Distance.ToString()); if (Notify || UINotify) foreach (var player in BasePlayer.activePlayerList) { if (permission.UserHasPermission(player?.UserIDString, Use_Perm)) { if (Notify) Notify.Call("SendNotify", player, configData.PiD, _MSG); if (UINotify) UINotify.Call("SendNotify", player, configData.PiD, _MSG); } } return true; } return null; } object OnEntityDeath(BaseNPC2 npc , HitInfo info) { if (npc == null || info.InitiatorPlayer == null) return true; if (info.InitiatorPlayer.userID.IsSteamId()) ; { BasePlayer attacker = info.InitiatorPlayer; int _Distance = (int)Vector3.Distance(attacker.transform.position , npc.transform.position); var WeaponName = GetWeaponName(info); var Killer = attacker.displayName.ToString(); var Victim = GetAnimalType(npc); Puts($"{Killer} killed A {Victim} with a {WeaponName}"); string _MSG = msginfo("FeedAnimal").Replace("{Killer}" , Killer).Replace("{Victim}" , Victim).Replace("{Weapon}" , WeaponName).Replace("{_Distance}" , _Distance.ToString()); if (Notify || UINotify) foreach (var player in BasePlayer.activePlayerList) { if (permission.UserHasPermission(player?.UserIDString , Use_Perm)) { if (Notify) Notify.Call("SendNotify" , player , configData.PiD , _MSG); if (UINotify) UINotify.Call("SendNotify" , player , configData.PiD , _MSG); } } return true; } return null; } object OnEntityDeath(SimpleShark shark, HitInfo info) { if (shark == null || info.InitiatorPlayer == null) return true; if (info.InitiatorPlayer.userID.IsSteamId()) ; { BasePlayer attacker = info.InitiatorPlayer; int _Distance = (int)Vector3.Distance(attacker.transform.position, shark.transform.position); var WeaponName = GetWeaponName(info); var Killer = attacker.displayName.ToString(); var Victim = GetAnimalType(shark); Puts($"{Killer} killed A {Victim} with a {WeaponName}"); string _MSG = msginfo("FeedAnimal").Replace("{Killer}", Killer).Replace("{Victim}", Victim).Replace("{Weapon}", WeaponName).Replace("{_Distance}", _Distance.ToString()); if (Notify || UINotify) foreach (var player in BasePlayer.activePlayerList) { if (permission.UserHasPermission(player?.UserIDString, Use_Perm)) { if (Notify) Notify.Call("SendNotify", player, configData.PiD, _MSG); if (UINotify) UINotify.Call("SendNotify", player, configData.PiD, _MSG); } } return true; } return null; } #endregion #region Helpers private string GetAnimalType(BaseEntity npc) { var Animal = npc.ShortPrefabName.ToString(); if (Animal == "bear") Animal = msginfo("Bear"); if (Animal == "polarbear") Animal = msginfo("PolarBear"); if (Animal == "chicken") Animal = msginfo("Chicken"); if (Animal == "boar") Animal = msginfo("Boar"); if (Animal == "horse") Animal = msginfo("Horse"); if (Animal == "stag") Animal = msginfo("Stag"); if (Animal == "wolf") Animal = msginfo("Wolf"); if (Animal == "wolf2") Animal = msginfo("Wolf"); if (Animal == "simpleshark") Animal = msginfo("SimpleShark"); return Animal; } private string GetWeaponName(HitInfo hitInfo) { var _WeaponName = "??Unknown??"; if (hitInfo.Weapon == null) { if (hitInfo.WeaponPrefab.prefabID == 3898309212) _WeaponName = "C4";//3898309212 if (hitInfo.WeaponPrefab.prefabID == 3046924118) _WeaponName = "Rocket";//3046924118 if (hitInfo.WeaponPrefab.prefabID == 1217937936) _WeaponName = "HV Rocket";//1217937936 if (hitInfo.WeaponPrefab.prefabID == 2742759844) _WeaponName = "Satchel";//1217937936 if (hitInfo.WeaponPrefab.prefabID == 2144399804) _WeaponName = "Beancan";//2144399804 if (hitInfo.WeaponPrefab.prefabID == 1859672190) _WeaponName = "Shell";//1217937936 if (hitInfo.WeaponPrefab.prefabID == 1128089209) _WeaponName = "Grenade";//1128089209 if (hitInfo.WeaponPrefab.prefabID == 3717106868) _WeaponName = "Flamethrower";//3717106868 if (hitInfo.Initiator is GunTrap) _WeaponName = "GunTrap"; if (hitInfo.Initiator is FlameTurret) _WeaponName = "FlameTurret"; if (hitInfo.Initiator is AutoTurret) _WeaponName = "AutoTurret"; else if (hitInfo.damageTypes.GetMajorityDamageType() == DamageType.Heat) _WeaponName = "Fire"; else if (hitInfo.damageTypes.GetMajorityDamageType() == DamageType.Fun_Water) _WeaponName = "WaterGun"; Puts(hitInfo.WeaponPrefab.prefabID.ToString()); return _WeaponName; } if (hitInfo.Weapon != null) { //Puts(hitInfo.WeaponPrefab.prefabID.ToString()); var _Weapon = hitInfo.Weapon; var item = _Weapon.GetItem(); if (item != null) _WeaponName = item.info.displayName.english; if (hitInfo.WeaponPrefab.prefabID == 1233562048) _WeaponName = "Grenade Launcher"; } if (hitInfo.Initiator is GunTrap) _WeaponName = "GunTrap"; if (hitInfo.Initiator is FlameTurret) _WeaponName = "FlameTurret"; if (hitInfo.Initiator is AutoTurret) _WeaponName = "AutoTurret"; if (hitInfo.Initiator is HotAirBalloon) _WeaponName = "Hot Air Balloon"; return _WeaponName; } #endregion #region messages private string msginfo(string key, string id = null) => lang.GetMessage(key, this, id); #endregion } }