Page 1 of 1

Addon superloading quest files

Posted: Wed Dec 28, 2016 10:43 pm
by Pseudoku
Currently I'm overloading quests files for my addons, but I'm trying to see if I can avoid conflicts with other addons.

Is it possible to superload the data/quests files?

Ex. The brotherhood-of-alchemists.lua file defines competition function as:

Code: Select all

competition = function(self, player, other_alchemist_nums)
	...
end

Following the wiki doesn't seem to work
(placed in superload/data/quests/brotherhood-of-alchemists.lua)

Code: Select all

local _M = loadPrevious(...)
local base_competition = _M.competition

function _M:competition(player, other_alchemist_nums)
  ...
end

return _M
Also tried assigning the competition reference like

Code: Select all

_M.competition = function(self, player, other_alchemist_nums)
or

Code: Select all

competition = function(self, player, other_alchemist_nums)

I looked at the base functions of other superloaded mods but the functions are all declared like

Code: Select all

function _M:onQuit()
Does the function have to be declared like that to superload it?

Re: Addon superloading quest files

Posted: Fri Dec 30, 2016 1:54 pm
by darkgod
Ah no you cant. Most datafiles cant be superloaded like that, but can usually be altered otherwise.

Sadly quests kinda can't :/

For 1.5 I've added Quest:init and Quest:setStatus hooks to be able to alter them. With Quest:init you'll be able to simply alter "self" as desired.

As for how to do it in 1.4; you could just superload Quest:init hook in and use that.
To do that just superload engine/Quest.lua:init() method that doest this code:

Code: Select all

	self:triggerHook{"Quest:init"}

Re: Addon superloading quest files

Posted: Mon Jan 02, 2017 3:40 am
by Zizzo
Pseudoku wrote:Currently I'm overloading quests files for my addons, but I'm trying to see if I can avoid conflicts with other addons.
Always a commendable goal. :wink:
Pseudoku wrote:Is it possible to superload the data/quests files?
No, files in data/ can't be superloaded, because that's not really how superloading works. For your particular case, my approach would probably be to superload mod.class.Player:on_quest_grant() to modify the newly installed quest table in place:

Code: Select all

local super_on_quest_grant = _M.on_quest_grant
function _M:on_quest_grant(quest)
  super_on_quest_grant(self, quest)

  if quest.name == 'The Brotherhood of Alchemists' then
    self.quests[quest.id].competition = function(self, player, other_alchemist_nums)
      ...
    end
  end
end
[Fair warning: the above pseudocode is untested. Use at your own risk. We Apologize for the Inconvenience.™]