Probably best to make separate threads for each question as the code is getting pretty messy even for just one (hopefully Xrystal has answered your timer question).
Having multiple item links and locales in your addon.db texts complicates things because the order you want the links to display might be different in german to the order displayed in french and might be different again for english.
This requires identifying the order each link needs to be in for every locale text. With that in mind, the structure of addon.db needs to change so this is one way you could do it (my german in non-existant so it didn't even try):
NOTE: the number if items in each
itemOrder should be the same as the number of
%s tokens that are in the corresponding
text field.
(This is probably overkill as it's replacing all the locale texts and you probably only need the ones that will be actually be used but that depends on what the end addon requires so...)
Lua Code:
local addonName, addon = ...
addon.db = {
{
name = {
enUS = "Herb-Infused Water",
deDE = "Mit Kräutern aromatisiertes Wasser"
},
questID = 75612,
icon = "interface/icons/inv_mushroom_11",
announce = {
enUS = { -- the text to display for english
text = "Awarded for %s outstanding service %s to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the Wellspring \nOverlook in the Emerald %s Dream to receive powerful \nequipment for your efforts",
itemOrder = { -- the order to display the items in english
210399,
210400,
210401,
210402,
},
},
deDE = { -- the text to display for german
text = "The items %s might be %s in a different %s order of items %s in german",
itemOrder = { -- the order to display the items in german
210401,
210402,
210399,
210400,
},
},
},
},
{
name = "Emerald Mark of Mastery",
questID = 75624,
icon = "interface/icons/inv_mushroom_11",
announce = {
enUS = { -- the text to display for english
text = "Awarded for outstanding service to Dragonkind.\n%s\nBring it to Theozhaklos the Curious at the Wellspring \nOverlook in the Emerald Dream to receive powerful \nequipment for your efforts",
itemOrder = { -- the order to display the items in english
20897,
},
},
deDE = { -- the text to display for german
text = "Only one %s in this entry",
itemOrder = { -- the order to display the items in german
20897,
},
},
}
},
}
---------------------------------------------------------------------------------------------------
-- Code to replace %s in announce texts with item links. Replaces the GetItemLinkById(...) function
local itemList = {} -- table to save the itsmID to
for index, v in ipairs(addon.db) do -- get/save every itmeID in addon.db announce
for k, itemID in pairs(v.announce.enUS.itemOrder) do -- assumes all announce entries will use all the same itemIDs
if not itemList[itemID] then
itemList[itemID] = true
end
end
end
local function FormatTexts() -- fill addon.db with the item links
for index, v in ipairs(addon.db) do
for locale, settings in pairs(v.announce) do
local order = {}
for i, link in ipairs(settings.itemOrder) do -- get the links in order from addon.db
order[i] = itemList[link] -- and save them into a tmporary table
end
settings.text = format(settings.text, unpack(order)) -- replace %s with the ordered item links (unpack(table) returns a number keyed tables entries in order eg. order[1], order[2], order[3] etc.)
end
end
end
local function LoadItem(item) -- Get the links for all the saved itemIDs
if item then
itemList[item:GetItemID()] = item:GetItemLink()
end
local key = next(itemList, item and item.Next or nil)
if not key then -- when we have all the links for all the items
FormatTexts() -- Run FormatTexts() to do the text replacements
return
end
local nextItem = Item:CreateFromItemID(key)
nextItem.Next = key
nextItem:ContinueOnItemLoad(function() LoadItem(nextItem) end)
end
LoadItem()