Module misn
Mission Lua bindings.
An example would be:
misn.setNPC( "Keer", "empire/unique/keer.webp", _("You see here Commodore Keer.") )
Functions
setTitle (title) | Sets the current mission title. |
setDesc (desc) | Sets the current mission description. |
setReward (reward) | Sets the current mission reward description. |
setDistance (Distance) | Sets the distance to the mission's goal. |
setIllegal (Whether) | Marks whether or not a mission should be considered illegal in the current system. |
setFaction (Faction) | Sets the faction giver of the mission. |
markerAdd (target[, type="high"]) | Adds a new marker. |
markerMove (id, sys) | Moves a marker to a new system. |
markerRm ([id]) | Removes a mission system marker. |
setNPC (name, portrait, desc) | Sets the current mission NPC. |
factions () | Gets the factions the mission is available for. |
accept () | Attempts to accept the mission. |
finish ([properly]) | Finishes the mission. |
cargoAdd (cargo, quantity) | Adds some mission cargo to the player. |
cargoRm (cargoid) | Removes the mission cargo. |
cargoJet (cargoid) | Jettisons the mission cargo. |
osdCreate (title, list) | Creates a mission OSD. |
osdDestroy () | Destroys the mission OSD. |
osdActive (n) | Sets active in mission OSD. |
osdGetActive () | Gets the active OSD element. |
osdGet (Title, List, ID) | Gets the current mission OSD information. |
npcAdd (func, name, portrait, desc[, priority=5[, background=nil]]) | Adds an NPC. |
npcRm (id) | Removes an NPC. |
claim (params[, inclusive=false]) | Tries to claim systems or strings. |
computerRefresh () | Refreshes the mission computer offerings. |
Functions
- setTitle (title)
-
Sets the current mission title.
Parameters:
- title string Title to use for mission.
- setDesc (desc)
-
Sets the current mission description.
Also sets the mission OSD unless you explicitly force an OSD, however you can't specify bullet points or other fancy things like with the real OSD.
Parameters:
- desc string Description to use for mission.
- setReward (reward)
-
Sets the current mission reward description.
Parameters:
- reward string or number Description of the reward to use. Can pass a number to signify a monetary reward, and allow for sorting.
- setDistance (Distance)
-
Sets the distance to the mission's goal. Used for sorting missions in
the mission computer. Unused otherwise.
Parameters:
- Distance number from the current player position.
- setIllegal (Whether)
-
Marks whether or not a mission should be considered illegal in the
current system. Used for filtering missions at the mission computer, unused
otherwise.
Parameters:
- Whether boolean or not the mission should be considered illegal.
- setFaction (Faction)
-
Sets the faction giver of the mission. Used mainly as metadata for
sorting and organizing missions in the mission computer.
Parameters:
- Faction faction to set the mission to or nil to disable.
- markerAdd (target[, type="high"])
-
Adds a new marker.
Parameters:
- target System or Spob System or spob to mark.
- type string Colouring scheme to use. (default "high")
Returns:
-
number
A marker ID to be used with markerMove and markerRm.
Usage:
my_marker = misn.markerAdd( system.get("Gamma Polaris"), "low" ) Valid marker types are:<br/> - "plot": Important plot marker.<br/> - "high": High importance mission marker (lower than plot).<br/> - "low": Low importance mission marker (lower than high).<br/> - "computer": Mission computer marker.<br/>
- markerMove (id, sys)
-
Moves a marker to a new system.
Parameters:
- id number ID of the mission marker to move.
- sys System System to move the marker to.
Usage:
misn.markerMove( my_marker, system.get("Delta Pavonis") )
- markerRm ([id])
-
Removes a mission system marker.
Parameters:
- id number ID of the marker to remove. If no parameter is passed, all markers associated with the mission are removed. (optional)
Usage:
misn.markerRm( my_marker )
- setNPC (name, portrait, desc)
-
Sets the current mission NPC.
This is used in bar missions where you talk to a person. The portraits are the ones found in GFX_PATH/portraits. (For GFX_PATH/portraits/none.webp you would use "none.webp".)
Note that this NPC will disappear when either misn.accept() or misn.finish() is called.
Parameters:
- name string Name of the NPC.
- portrait string File name of the portrait to use for the NPC.
- desc string Description of the NPC to use.
Usage:
misn.setNPC( "Invisible Man", "none.webp", _("You see a levitating mug drain itself.") )
- factions ()
-
Gets the factions the mission is available for.
Returns:
-
{Faction,...}
A table containing the factions for whom the
mission is available.
Usage:
f = misn.factions()
- accept ()
-
Attempts to accept the mission.
Note: there is no limit on the maximum number of missions a player can have simultaneously.
Returns:
-
boolean
true if mission was properly accepted.
Usage:
if not misn.accept() then return end
- finish ([properly])
-
Finishes the mission.
Parameters:
- properly boolean If true and the mission is unique it marks the mission as completed. If false it deletes the mission but doesn't mark it as completed. If the parameter isn't passed it just ends the mission (without removing it from the player's list of active missions). (optional)
- cargoAdd (cargo, quantity)
-
Adds some mission cargo to the player. They cannot sell it nor get rid
of it unless they abandons the mission in which case it'll get eliminated.
Parameters:
- cargo Commodity or string Type of cargo to add, either as a Commodity object or as the raw (untranslated) name of a commodity.
- quantity number Quantity of cargo to add.
Returns:
-
number
The id of the cargo which can be used in cargoRm.
- cargoRm (cargoid)
-
Removes the mission cargo.
Parameters:
- cargoid number Identifier of the mission cargo.
Returns:
-
boolean
true on success.
- cargoJet (cargoid)
-
Jettisons the mission cargo.
Parameters:
- cargoid number ID of the cargo to jettison.
Returns:
-
boolean
true on success.
- osdCreate (title, list)
-
Creates a mission OSD.
Note You can index elements by using '\\t' as first character of an element. Note Destroys an osd if it already exists.
Parameters:
- title string Title to give the OSD.
- list {string,...} List of elements to put in the OSD.
Usage:
misn.osdCreate( "My OSD", {"Element 1", "Element 2"})
- osdDestroy ()
- Destroys the mission OSD.
- osdActive (n)
-
Sets active in mission OSD.
Note Uses Lua indexes, so 1 is first member, 2 is second and so on.
Parameters:
- n number Element of the OSD to make active.
- osdGetActive ()
-
Gets the active OSD element.
Returns:
-
string
Th ename of the active element or nil if none.
- osdGet (Title, List, ID)
-
Gets the current mission OSD information.
Parameters:
- npcAdd (func, name, portrait, desc[, priority=5[, background=nil]])
-
Adds an NPC.
Parameters:
- func string Name of the function to run when approaching, gets passed the npc_id when called.
- name string Name of the NPC
- portrait string Portrait file name to use for the NPC (from GFX_PATH/portraits/).
- desc string Description associated to the NPC.
- priority number Optional priority argument (highest is 0, lowest is 10). (default 5)
- background string Background file name to use (from GFX_PATH/portraits/). (default nil)
Returns:
-
number
The ID of the NPC to pass to npcRm.
Usage:
npc_id = misn.npcAdd( "my_func", "Mr. Test", "none.webp", "A test." ) -- Creates an NPC.
- npcRm (id)
-
Removes an NPC.
Parameters:
- id number ID of the NPC to remove.
Usage:
misn.npcRm( npc_id )
- claim (params[, inclusive=false])
-
Tries to claim systems or strings.
Claiming systems and strings is a way to avoid mission collisions preemptively.
Note it does not actually perform the claim if it fails to claim. It also does not work more than once.
Parameters:
- params System, String or {System,String...} Table of systems/strings to claim or a single system/string.
- inclusive boolean Whether or not to allow the claim to include other inclusive claims. Multiple missions/events can inclusively claim the same system, but only one system can exclusively claim it. (default false)
Returns:
-
boolean
true if was able to claim, false otherwise.
Usage:
if not misn.claim( { system.get("Gamma Polaris") } ) then misn.finish( false ) end
if not misn.claim( system.get("Gamma Polaris") ) then misn.finish( false ) end
if not misn.claim( 'some_string' ) then misn.finish( false ) end
if not misn.claim( { system.get("Gamma Polaris"), 'some_string' } ) then misn.finish( false ) end
- computerRefresh ()
-
Refreshes the mission computer offerings.
Do not use from a mission 'create' function.