From e81131d6852c3212bf5ea4d196c097d3897df8ca Mon Sep 17 00:00:00 2001 From: smariot Date: Sat, 29 Mar 2008 14:25:38 -0400 Subject: [PATCH] Using new 2.4 functions to record the IDs of NPCs and quests, and since I was doing that; items as well. This data will be used in a far off future release. (Maybe.) --- main.lua | 28 ++++++++++++++++++++++++++++ objective.lua | 2 +- questlog.lua | 2 ++ utility.lua | 14 ++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/main.lua b/main.lua index 4a80c08..544590d 100644 --- a/main.lua +++ b/main.lua @@ -139,6 +139,8 @@ function QuestHelper:OnEvent(event) self:RegisterEvent("PARTY_MEMBERS_CHANGED") self:RegisterEvent("CHAT_MSG_ADDON") self:RegisterEvent("CHAT_MSG_SYSTEM") + self:RegisterEvent("BAG_UPDATE") + self:RegisterEvent("GOSSIP_SHOW") self:SetScript("OnUpdate", self.OnUpdate) @@ -218,7 +220,21 @@ function QuestHelper:OnEvent(event) end end + if event == "GOSSIP_SHOW" then + local name, id = UnitName("npc"), self:GetUnitID("npc") + if name and id then + self:GetObjective("monster", name).o.id = id + --self:TextOut("NPC: "..name.." = "..id) + end + end + if event == "PLAYER_TARGET_CHANGED" then + local name, id = UnitName("target"), self:GetUnitID("target") + if name and id then + self:GetObjective("monster", name).o.id = id + --self:TextOut("Target: "..name.." = "..id) + end + if UnitExists("target") and UnitIsVisible("target") and UnitCreatureType("target") ~= "Critter" and not UnitIsPlayer("target") and not UnitPlayerControlled("target") then local index, x, y = self:UnitPosition("target") @@ -448,6 +464,18 @@ function QuestHelper:OnEvent(event) if event == "PLAYER_CONTROL_LOST" then self:flightBegan() end + + if event == "BAG_UPDATE" then + for slot = 1,GetContainerNumSlots(arg1) do + local link = GetContainerItemLink(arg1, slot) + if link then + local id, name = select(3, string.find(link, "|Hitem:(%d+):.-|h%[(.-)%]|h")) + if name then + self:GetObjective("item", name).o.id = tonumber(id) + end + end + end + end end local map_shown_decay = 0 diff --git a/objective.lua b/objective.lua index 5a0633c..9656f09 100644 --- a/objective.lua +++ b/objective.lua @@ -102,7 +102,7 @@ local function ItemKnown(self) if self.fb.contained then for item in pairs(self.fb.contained) do if self.qh:GetObjective("item", item):Known() then - return true + return true end end end diff --git a/questlog.lua b/questlog.lua index d58d156..7eb5ba6 100644 --- a/questlog.lua +++ b/questlog.lua @@ -195,6 +195,8 @@ function QuestHelper:ScanQuestLog() end + quest.o.id = self:GetQuestID(index) + -- Can't add the objective here, if we don't have it depend on the objectives -- first it'll get added and possibly not be doable. -- We'll add it after the objectives are determined. diff --git a/utility.lua b/utility.lua index 223f1be..ff080a9 100644 --- a/utility.lua +++ b/utility.lua @@ -125,6 +125,20 @@ function QuestHelper:HighlightText(text) theme.message_highlight[3]*255, text) end +function QuestHelper:GetUnitID(unit) + local id = UnitGUID(unit) + + if id then + return (string.sub(id, 5, 5) == "3") and tonumber(string.sub(id, 6, 12), 16) or nil + end + + return nil +end + +function QuestHelper:GetQuestID(index) + return tonumber(select(3, string.find(GetQuestLink(index), "|Hquest:(%d+):"))) +end + -- For future reference: -- Hearthstone = 6948 -- Rune of Teleportation = 17031 -- 2.11.4.GIT