ToME: the Tales of Maj'Eyal
http://forums.te4.org/

Addon superloading quest files
http://forums.te4.org/viewtopic.php?f=36&t=47101
Page 1 of 1

Author:  Pseudoku [ Wed Dec 28, 2016 10:43 pm ]
Post subject:  Addon superloading quest files

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:
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:
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:
_M.competition = function(self, player, other_alchemist_nums)

or
Code:
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:
function _M:onQuit()


Does the function have to be declared like that to superload it?

Author:  darkgod [ Fri Dec 30, 2016 1:54 pm ]
Post subject:  Re: Addon superloading quest files

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:
   self:triggerHook{"Quest:init"}

Author:  Zizzo [ Mon Jan 02, 2017 3:40 am ]
Post subject:  Re: Addon superloading quest files

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:
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.™]

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/