diff --git a/Quests.cs b/Quests.cs index d66cf59..1902493 100644 --- a/Quests.cs +++ b/Quests.cs @@ -14,7 +14,7 @@ namespace Oxide.Plugins { - [Info("Quests", "Gonzi", "2.4.2")] + [Info("Quests", "Gonzi", "2.4.4")] [Description("Creates quests for players to go on to earn rewards, complete with a GUI menu")] public class Quests : RustPlugin { @@ -51,10 +51,10 @@ public class Quests : RustPlugin private Dictionary AddVendor = new Dictionary(); private Dictionary> AllObjectives = new Dictionary>(); - private Dictionary> HeliAttackers = new Dictionary>(); + private Dictionary> VehicleAttackers = new Dictionary>(); private Dictionary> OpenUI = new Dictionary>(); - private Dictionary Looters = new Dictionary(); + private Dictionary Looters = new Dictionary(); private List StatsMenu = new List(); private List OpenMenuBind = new List(); @@ -327,23 +327,21 @@ void OnEntityDeath(BaseCombatEntity entity, HitInfo info) try { if (entity == null || info == null) return; - string entname = entity?.ShortPrefabName; - if (entname == "testridablehorse") - { - entname = "horse"; - } - if ((entname.Contains("scientist")) && (!entname.Contains("corpse"))) - { - entname = "scientist"; - } + string entname = getEntityName(entity); + if (entname == null) return; BasePlayer player = null; - if (info.InitiatorPlayer != null) - player = info.InitiatorPlayer; - else if (entity.GetComponent() != null) + if (entname == "patrolhelicopter" || entname == "bradleyapc") + { player = BasePlayer.FindByID(GetLastAttacker(entity.net.ID)); + VehicleAttackers.Remove(entity.net.ID); + } + else if (info.InitiatorPlayer != null) + { + player = info.InitiatorPlayer; + } if (player != null) { @@ -361,21 +359,21 @@ void OnEntityDeath(BaseCombatEntity entity, HitInfo info) void OnEntityTakeDamage(BaseCombatEntity victim, HitInfo info) { - if (victim.GetComponent() != null && info?.Initiator?.ToPlayer() != null) + var entname = getEntityName(victim); + if (entname == null || (entname != "patrolhelicopter" && entname != "bradleyapc")) return; + + var attacker = info?.Initiator?.ToPlayer(); + if (attacker == null) return; + + NextTick(() => { - var heli = victim.GetComponent(); - var player = info.Initiator.ToPlayer(); - if (isPlaying(player)) return; - NextTick(() => - { - if (heli == null) return; - if (!HeliAttackers.ContainsKey(heli.net.ID)) - HeliAttackers.Add(heli.net.ID, new Dictionary()); - if (!HeliAttackers[heli.net.ID].ContainsKey(player.userID)) - HeliAttackers[heli.net.ID].Add(player.userID, 0); - HeliAttackers[heli.net.ID][player.userID]++; - }); - } + if (victim?.net?.ID == null) return; + if (!VehicleAttackers.ContainsKey(victim.net.ID)) + VehicleAttackers.Add(victim.net.ID, new Dictionary()); + if (!VehicleAttackers[victim.net.ID].ContainsKey(attacker.userID)) + VehicleAttackers[victim.net.ID].Add(attacker.userID, 0); + VehicleAttackers[victim.net.ID][attacker.userID] += info.damageTypes.Total(); + }); } // Gather @@ -405,9 +403,9 @@ void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player) } //Craft - void OnItemCraftFinished(ItemCraftTask task, Item item) + void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter itemCrafter) { - var player = task.owner; + var player = itemCrafter.owner; if (player != null) if (hasQuests(player.userID) && isQuestItem(player.userID, item.info.shortname, QuestType.Craft)) ProcessProgress(player, QuestType.Craft, item.info.shortname, item.amount); @@ -822,8 +820,8 @@ private void GetAllKillables() "player", "scientist", "murderer", - "tunneldweller", - "underwaterdweller", + "npc_tunneldweller", + "npc_underwaterdweller", "scarecrow", "simpleshark" }; @@ -839,8 +837,8 @@ private void GetAllKillables() DisplayNames.Add("player", "Player"); DisplayNames.Add("scientist", "Scientist"); DisplayNames.Add("murderer", "Murderer"); - DisplayNames.Add("tunneldweller", "Tunneldweller"); - DisplayNames.Add("underwaterdweller", "Underwater Dweller"); + DisplayNames.Add("npc_tunneldweller", "Tunnel Dweller"); + DisplayNames.Add("npc_underwaterdweller", "Underwater Dweller"); DisplayNames.Add("scarecrow", "Scarecrow"); DisplayNames.Add("simpleshark", "Shark"); } @@ -849,6 +847,29 @@ private void GetAllKillables() #region Functions + private string getEntityName(BaseEntity entity) + { + string entname = entity?.ShortPrefabName ?? null; + if (entname == null) return null; + + if (entname == "testridablehorse") + { + entname = "horse"; + } + + if ((entname.Contains("scientist")) && (!entname.Contains("corpse"))) + { + entname = "scientist"; + } + + if (entname.Contains("wolf")) + { + entname = "wolf"; + } + + return entname; + } + private bool isAdmin(BasePlayer player) { if (configData.UseOxidePermissions == true && permission.UserHasPermission(player.UserIDString, permission_manage) || player.IsAdmin && configData.UsePlayerIsAdmin == true) return true; @@ -1180,13 +1201,13 @@ private void RemoveQuest(string questName) SaveVendorData(); } - private ulong GetLastAttacker(uint id) + private ulong GetLastAttacker(NetworkableId id) { int hits = 0; ulong majorityPlayer = 0U; - if (HeliAttackers.ContainsKey(id)) + if (VehicleAttackers.ContainsKey(id)) { - foreach (var score in HeliAttackers[id]) + foreach (var score in VehicleAttackers[id]) { if (score.Value > hits) majorityPlayer = score.Key;