Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 59 additions & 38 deletions Quests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -51,10 +51,10 @@ public class Quests : RustPlugin
private Dictionary<ulong, bool> AddVendor = new Dictionary<ulong, bool>();

private Dictionary<QuestType, List<string>> AllObjectives = new Dictionary<QuestType, List<string>>();
private Dictionary<uint, Dictionary<ulong, int>> HeliAttackers = new Dictionary<uint, Dictionary<ulong, int>>();
private Dictionary<NetworkableId, Dictionary<ulong, float>> VehicleAttackers = new Dictionary<NetworkableId, Dictionary<ulong, float>>();

private Dictionary<ulong, List<string>> OpenUI = new Dictionary<ulong, List<string>>();
private Dictionary<uint, ulong> Looters = new Dictionary<uint, ulong>();
private Dictionary<ItemId, ulong> Looters = new Dictionary<ItemId, ulong>();

private List<ulong> StatsMenu = new List<ulong>();
private List<ulong> OpenMenuBind = new List<ulong>();
Expand Down Expand Up @@ -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<BaseHelicopter>() != 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)
{
Expand All @@ -361,21 +359,21 @@ void OnEntityDeath(BaseCombatEntity entity, HitInfo info)

void OnEntityTakeDamage(BaseCombatEntity victim, HitInfo info)
{
if (victim.GetComponent<BaseHelicopter>() != 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<BaseHelicopter>();
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<ulong, int>());
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<ulong, float>());
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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -822,8 +820,8 @@ private void GetAllKillables()
"player",
"scientist",
"murderer",
"tunneldweller",
"underwaterdweller",
"npc_tunneldweller",
"npc_underwaterdweller",
"scarecrow",
"simpleshark"
};
Expand All @@ -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");
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down