Tutorial:Junction Patching

From PMDOWiki
This page is a tutorial on adding content to PMDO.

In order to enable multiple mods to patch ground map warps at the same time, PMDO includes some code to patch any warp in the game. This includes maps that are junctions in the vanilla game and regular warps which will become junctions if patched with new maps.

Finding a target

First, determine the warp/junction that will be edited. For the sake of this tutorial, the warp that leads to the evolution spring in Base Town will be targeted.

Open the corresponding init script file for the map in the base game. In this case from the script folder, go to the directory Script/origin/ground/base_camp_2 and open init.lua.

At the top of the file, notice the following lines of code:

-- Tables for the junctions on this map
base_camp_2.junction = {}

-- West - standard entrance
base_camp_2.junction.west =
{
	dungeons = {},
	groundmaps = {{Flag=true,Zone="guildmaster_island", ID=1, Entry=1}}
}

-- North - evolution area
base_camp_2.junction.north =
{
	dungeons = {},
	groundmaps = {{Flag=true,Zone="guildmaster_island", ID=11, Entry=0}}
}

The key thing to note is the first comment and the definition of base_camp_2.junction = {}. This is where the tables for each junction are defined, which contains all of the data of the ground maps or dungeons to be accessed. Notice how each table is defined as <namespace>.junction.<name>, with the name usually based off of the directional location of the warp. There is a comment before all of them giving a short description about the junction.

In this case, the table we want to patch is base_camp_2.junction.north. Let's note its name north - we'll need to use it later.

Preparing The Groundmap Patch

We're going to use PMDO's ability to patch a ground map script in order to patch in a ground map or dungeon entry to our target junction. We will need to target the map where the target junction is - base_camp_2. Create a init.lua file in the patching mod. (See the tutorial for more info.)

Let's prepare the file to work. We need to create a new namespace for it, preferably based on your mod and the map being patched. It needs to be unique to your mod to avoid potential compatibility issues.

To demonstrate for this file, the namespace will be base_town_patch. We'll need to include some basic boiler plate code with the name space, so based on your own chosen namespace put this code in the file:

require 'origin.common'

local base_town_patch = {}

-- This space in between is where the patching functions will go.

return base_town_patch

We are now prepared to add new groundmaps and dungeons to the junction.

Adding Entries

In common.lua, two functions have been provided to insert entries into the junction table: COMMON.AddDungeonsToJunction and COMMON.AddGroundmapsToJunction. We're going to add these after the spacing comment in order to patch. We can patch multiple entries in at once.

The function used depends on if dungeon(s) or groundmap(s) are being added. Note that when running these functions, the second argument will always be the same: The name of the target junction. In this example, we noted earlier that we are targeting north. So, the string "north" will be the second argument.

Dungeon

Dungeons are indexed and may be referenced with their defined ID. Thus, to add a dungeon, first note the ID of any dungeons you would like to add. For the sake of demonstration, we will add the dungeons Wayward Wetlands and Geode Crevice. Through the zone directory in Dev Mode, we can see that the IDs of these dungeons respectively are wayward_wetlands and geode_crevice.

To add these dungeons to the junction, add this line of code:

COMMON.AddDungeonsToJunction({"wayward_wetlands","geode_crevice"},"north")

Note that dungeons in PMDO must be unlocked to access outside of the dev menu. The simplest way to do this is to set them to unlocked on entering the map, by adding these two lines:

GAME:UnlockDungeon("wayward_wetlands")
GAME:UnlockDungeons("geode_crevice")

Groundmap

Groundmaps lack indexing. As a result, they must be added as entries with all of their information included.

Gathering data

To demonstrate, we will add the Cliff Camp and Forest Camp maps to the junction. Since these aren't ground maps we created but already existing ones, we need to locate data about them.

To do this, open PMDO in dev mode. Head to the travel tab. Since these are groundmaps on the guildmaster island, they will be found in the guildmaster_island zone. Note how grounds forest_camp and cliff_camp are present, which are the target maps we're adding. Each ground also has an index - 3 for Forest and 4 for Cliff. Note these IDs down for each map, and also note down the zone the maps were found in.

We need to determine which entrance the player will spawn at when entering the ground map. Any marker can be spawned at, but we need to determine which one. To find target markers, travel to the map in the travel menu, and then navigate to data. Click on edit ground to open the ground editor.

From here, click on entities and check Show Boxes. All entity boxes will now be visible. If you see any orange boxes, those are markers that are valid entrances. Click on them in Select/Move mode and verify this. Once finding a marker you want to use, note down it's name. For Forest we want to use entrance_south and for Cliff it will be entrance_west.

Now we have all the information needed to add these groundmaps to the junction entries.

Patching

Since we're passing COMMON.AddGroundmapsToJunction a table with two entries that have their own data, let's make a local variable to store the table to make the code easy to read and minimize future mistakes with the data collected:

local grounds = {
  {Flag=true,Zone='guildmaster_island',ID=3,Entry='entrance_south'}, --forest camp
  {Flag=true,Zone='guildmaster_island',ID=4,Entry='entrance_west'} --cliff camp
}

Then, call the function with the rest:

COMMON.AddGroundmapsToJunction(grounds, "north")