WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Quest Select/Accept/Complete LUA (https://www.wowinterface.com/forums/showthread.php?t=59842)

Hubb777 04-02-24 08:05 AM

Quest Select/Accept/Complete LUA
 
Hi all. I wrote a code in which the automatic acceptance and delivery of quests 77244 and 70893 occurs.

The code opens the quest window, but you have to press the “turn in quest” button yourself. How can I fix this? So that it would be automatic?

Lua Code:
  1. local addonName, addon = ...
  2. local QuestIDs = {77244, 70893} -- Quest IDs to auto accept and turn in
  3.  
  4. local function IsQuestInList(questID)
  5.     for _, id in ipairs(QuestIDs) do
  6.         if questID == id then
  7.             return true
  8.         end
  9.     end
  10.     return false
  11. end
  12.  
  13. local function AcceptQuest()
  14.     local availableQuests = C_GossipInfo.GetAvailableQuests()
  15.     if availableQuests then
  16.         for _, questInfo in ipairs(availableQuests) do
  17.             if IsQuestInList(questInfo.questID) then
  18.                 C_GossipInfo.SelectAvailableQuest(questInfo.questID)
  19.                 return true
  20.             end
  21.         end
  22.     end
  23.     return false
  24. end
  25.  
  26. local function CompleteQuest()
  27.     local activeQuests = C_GossipInfo.GetActiveQuests()
  28.     if activeQuests then
  29.         for _, questInfo in ipairs(activeQuests) do
  30.             if IsQuestInList(questInfo.questID) then
  31.                 C_GossipInfo.SelectActiveQuest(questInfo.questID)
  32.                 return true
  33.             end
  34.         end
  35.     end
  36.     return false
  37. end
  38.  
  39. local function OnGossipShow()
  40.     if AcceptQuest() then
  41.         return
  42.     end
  43.  
  44.     if CompleteQuest() then
  45.         -- Auto-complete the quest when gossip window shows up
  46.         CompleteQuest()
  47.         GetQuestReward(1)
  48.         return
  49.     end
  50. end
  51.  
  52. local frame = CreateFrame("Frame")
  53. frame:RegisterEvent("GOSSIP_SHOW")
  54. frame:SetScript("OnEvent", OnGossipShow)

Xrystal 04-02-24 10:47 AM

The CompleteQuest function requires you to click the continue button.

https://warcraft.wiki.gg/wiki/API_CompleteQuest

The final stage of the quest completion is GetQuestReward but unless there was only 1 reward you would have to show the options for rewards and pass the reward id to the function.

https://warcraft.wiki.gg/wiki/API_GetQuestReward


There is also this :
https://warcraft.wiki.gg/wiki/API_C_...o.SelectOption

But, I don't know if this works on Quest related gossips.

You also might want to use a different function name for your CompleteQuest function as it is also the name of a Blizzard Function that is part of the quest completion stage,.

SDPhantom 04-02-24 02:52 PM

Xrystal already answered, but I do have a note for the posted code.

Quote:

Originally Posted by Hubb777 (Post 343677)
Lua Code:
  1. local function IsQuestInList(questID)
  2.     for _, id in ipairs(QuestIDs) do
  3.         if questID == id then
  4.             return true
  5.         end
  6.     end
  7.     return false
  8. end

This function already exists as tContains().


All times are GMT -6. The time now is 12:17 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI