MISSIONS SYSTEM MANUAL
FILES

missions.lua
Editable mission configuration.

missions_mechanics.lua
Internal system. Usually do not edit.

mapXXXXX.lua
Map script. It loads missions.lua.

MAP FILE USAGE

In your map Lua file, use:

local missions=require("missions")

function OnGameStart()
missions.OnGameStart()
end

function CompleteMissionBox(id)
missions.CompleteMissionBox(id)
end

function FailMissionBox(id)
missions.FailMissionBox(id)
end

MISSION STRUCTURE

Each mission is defined inside prepared_missions:

[1]={
mision_id=10,
player=0,

closed={x=50,y=50},
open={x=50,y=55},
heart_slot=1,

text_id=1000,
tooltip_id=1001,

closed_slab_type=nil,
open_slab_type=nil,

started=false,
completed=false,
failed=false

}

[1] is the internal mission index.

Use this index with:

CompleteMissionBox(1)
FailMissionBox(1)

MISSION VARIABLES

mision_id
Special Box ID used by KeeperFX. Each mission should use a different one.

player
Player number. Example: player=0 means PLAYER0.

closed
Position of the closed scroll, MISSION_OFF.
x and y are SUBTILES.

open
Manual position of the opened scroll, MISSION_ON.
x and y are SUBTILES.
Used only when heart_slot=nil.

heart_slot
Automatic OPEN position around the Dungeon Heart.

1 2 3
4 X 5
6 7 8

X is the center and is not used.
Use heart_slot=nil to disable this.

text_id
Message shown when the mission scroll is activated.

tooltip_id
Tooltip shown for the Special Box.

closed_slab_type
Optional slab change under MISSION_OFF.
Use nil to disable it.

open_slab_type
Optional slab change under MISSION_ON.
Use nil to disable it.

started
completed
failed
Mission state values.
Usually leave them as false.

CALLBACK FUNCTIONS

Each mission can run custom code when it starts, completes, or fails:

function Mission1_Started(player,owner,m)
end

function Mission1_Completed(player,owner,m)
end

function Mission1_Failed(player,owner,m)
end

player
Player number. Example: 0.

owner
KeeperFX owner string. Example: PLAYER0.

m
Full mission table.

ADDING MORE MISSIONS

To add mission 4:

Add a new [4] block inside prepared_missions.
Create:

function Mission4_Started(player,owner,m)
end

function Mission4_Completed(player,owner,m)
end

function Mission4_Failed(player,owner,m)
end

Register them in the callback tables:

started={
[4]=Mission4_Started
}

completed={
[4]=Mission4_Completed
}

failed={
[4]=Mission4_Failed
}

BASIC FLOW
MISSION_OFF appears at the closed position.
The player activates it.
The message is shown.
MISSION_ON appears at the open position or heart_slot position.
Clicking MISSION_ON shows the message again.
Slapping or destroying MISSION_ON resets the mission to MISSION_OFF.
Completed or failed missions do not reset.
CompleteMissionBox(id) completes a mission.
FailMissionBox(id) fails a mission.