Jump to content

How to make a proper "API" mod?

Recommended Posts

Hi :)

I'm currently working on a "Quests mod", to introduce small tasks like bring xy to pigking and get a small reward.
Since I'm not very ingenious, I thought it would be best to allow other modders to add custom quests and also rewards to the mod by an API.

The reward system is mostly a "shop". You get dubloons for completing tasks and then you can go to the shopkeeper to buy some stuff.
The shop is made as a new Techtree.

So first task is:
How can other mods add their items to the shop techtree?

Second task:
How can other mods make use of functions I implement in the API mod?

Make first and second compatible to each other.

My thoughts were: making a new script and class "QuestAPI". Then use


local QuestAPI = GLOBAL.require("questapi")
QuestAPI = QuestAPI()

local function AddShopItems()


in the Quest mod, while the content of the QuestAPI script is:


local QuestAPI = Class(function(self)
	self.questfunctions = require("scenarios/questfunctions")

function QuestAPI:AddShopItem(prefab,cost)
	local recipe = nil
    recipe = AddRecipe(prefab.."_shop_stuff", {Ingredient("dubloon", cost, "images/slotm_inventory.xml")}, shoptab, TECH.SHOPPING_ONE, nil, nil, true, nil, nil, nil, prefab..".tex");recipe.product = prefab;

return QuestAPI


But this does not work, since "AddRecipe" is unknown outside of modmain =/

Another thought was to make a TUNING list with stuff that should be added by API mod, but in that case the Quest mods must load before the API mod, to fill the list. But with using that loading order, the Questmods can't use any other functions of the API mod.

Link to comment
Share on other sites

create a class and add it to GLOBAL , Although there is small issue with mod load order. You can make a event that fires when mod is finished loading and have "other" mods use that to detect when class is loaded and then they can access it and use its features.

Link to comment
Share on other sites

thank you for the suggestion :)

I found an easier way now:
- The API mod loads last.
- Every other quest mod can define/fill a GLOBAL.TUNING.QUESTMOD table with their quests, their functions and other stuff.

The API mod then just reads this table and acts accordingly :)
Important is the fact, that this table can also include functions, so the modders can just define a "rewardfunction", which is called after the quest is finished (same for intifn and checkfn) and that way they are totally free to create custom quests :)

Edited by Serpens
Link to comment
Share on other sites

3 hours ago, SuperDavid said:

I really can't wait for this mod to be done :DOne of the reasons cuz I want to add a shop & quest stuff for one of char's modes for a while but had no idea how...

I'm making good progress. I'm sure first version will be released at latest end of next week :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...