Mod:Nebula's Mission Board/Basic setup
Despite it being created to be as easy to add inside mods as possible, it still takes a bit of work to get the Mission Generation Library up and running. This page will run through all the necessary steps, from file placement to function hooks and require calls.
Importing the files
- Download Nebula's Mission Board from github and extract the zip's content wherever you like.
- Go to the mod's
Data/Scriptfolder and copy themissiongen_libfolder. - Paste the
missiongen_libfolder inside your own mod'sData/Scriptfolder.
Note that the library files expect to be placed exactly inside Data/Script/missiongen_lib. If you place them anywhere else, you will need to adjust all of the files' include calls accordingly, as well as all of the include calls present in this guide.
Don't forget to also copy all of the strings inside the strings.resx and stringsEx.resx files over to your mod, as well as the mission items inside the Data/Item folder!
Initializing the library
With the files imported in your mod, it's time to load it:
- Add
MissionGen = require("missiongen_lib.missiongen_lib")inside your mod'scommon.luafile. You can rename this variable however you want, but it must be a global variable. - If your global variable is not named "MissionGen", open missiongen_service.lua and change the
library_namestring into your global variable's name. Doing this will ensure that the service will be able to find the library when it needs to interact with it. - Add
require 'missiongen_lib.missiongen_service'inside your mod'smain.luafile.
These steps will take care of most of the initialization process all by themselves. All of the library files will be loaded, and the SV structure will be automatically have the library's save data added to it. This, however, does nothing in terms of gameplay, and more steps are needed for the library to actually function.
Hooking up functions
This is the lengthiest part of the guide. There are a lot of functions that need to be set up in order for the library to work correctly, as highlighted by the many files inside Nebula's Mission Board mod. Luckily, they're pretty easy to port: All you need to do is copy-paste all functions in their respective files in your mod. For example, all functions inside Nebula's Mission Board's common.lua will need to go inside your mod's common.lua. Remember to also change any reference to the nebula_mission_board namespace into a reference to your mod's namespace.
These are the files containing code that needs to be copied over:
common.luacommon_vars.luaevent.lua(therequirestatements)event.battle.luaevent_mapgen.luaevent.single.lua
You now need to hook up the dungeon generation code to the game. Open your mod in Dev Mode, go to the Constants tab and open the Universal menu. Here, in Zone Steps, add a new Script Zone Step. Set its Script parameter to GenerateJobInFloor.
Now save your changes, and that's it! This function will be responsible for dynamically adding the necessary steps and events whenever a destination floor is reached.
Everything we did up until now takes care of everything when it comes to generating and handling jobs inside dungeons, but there is still nothing that allows players to take new jobs, or to hand in completed ones. Not to worry: all you need to do is to add a call to MissionGen:BoardInteract(board_id), and your players will be able to access your job board of choice and take its contents. board_ids will be discussed in the page about Settings.
As for how handing in missions works, you will need to write a cutscene for it. Nebula's Mission Board mod already has one inside Data/Script/nebula_mission_board/ground/base_camp_2 if you want to copy it, but here's a basic rundown of how the job completion cutscene is handled:
- If any mission has been completed in the last dungeon run, the library will send the player to the location set inside the
end_dungeon_day_destinationsetting. This location will need to call theMissionGen:PlayJobsCompletedCutscene(callback)function. If you have multiple maps with job boards, this function will also handle switching between maps as needed. You will have to provide the callback. (see step 3 for more details) PlayJobsCompletedCutscenewill generate a list of characters, that will be passed to the callback along with the job struct itself.- the callback is ran. This is a modder-defined function with the following arguments:
- a job table
- a list of
GroundChars. The first one is always the client, while the second, if present, is always the target. Third and fourth are only generated for law enforcement jobs, and represent the background officers that would normally keep the outlaw restrained during the cutscene.
The callback is supposed to handle the cutscene itself, moving the characters where they need to be and displaying dialogue. It also needs to call
MissionGen:RewardPlayer(job, speaker, line1, line2), otherwise the player will not actually receive any rewards for the job they completed. - Once the cutscene is finished, control goes back to
PlayJobsCompletedCutscene, which will get rid of the current job and keep scanning for other completed ones until the end of the list, repeating steps 2 and 3 for each of them. - Finally, the function stored in the <>after_rewards_function<> settings is called, the boards are refreshed, and control is returned to the player.
That said, what you need to do is:
- call
MissionGen:PlayJobsCompletedCutscene(callback)in any and all maps that have a board assigned to it. - write the callback for the function above; it needs to use the current job's data and the given list of characters to actually implement the cutscene itself, and call
MissionGen:RewardPlayer(job, speaker, line1, line2)so that players will receive their reward.
When that is done, the library will finally be fully set up and ready to use, though you will still need to edit its Settings to make sure that it generates jobs for your mod's dungeons.
