Thread Tools Display Modes
04-02-24, 08:05 AM   #1
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
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)
  Reply With Quote
04-02-24, 10:47 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
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,.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
04-02-24, 02:52 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Xrystal already answered, but I do have a note for the posted code.

Originally Posted by Hubb777 View Post
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().
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-02-24 at 03:00 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Quest Select/Accept/Complete LUA


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off