Episodic Scripting
The episodic scripting interface is one of the two main interface provided by the campaign model to script. Unlike the Model Hierarchy
, which is used to query the state of the model, the episodic scripting interface is primarily used to make changes to the model.
Loaded in Campaign |
This interface is automatically created and cached by the campaign_manager
when the NewSession
event is triggered. This happens very early in the loading sequence. Once created, functions on the episodic scripting interface may be called by calling the campaign manager.
Example - Specification:
-- assumes a campaign manager object called cm
cm:dismiss_advice()
Many function on the campaign manager perform actions on a character and/or the military force he or she commands. The character to perform the action on is commonly specified by a character lookup string. A character lookup string must be composed from one or more filters. See the table below for a list of filter types.
filter name | description |
---|---|
faction | Faction key, from the factions table. |
type | Agent type, from the agent_types table. |
ability | Agent ability, from the abilities table. |
forename | Forename, from the names table. |
surname | Surname, from the names table. |
x | Display x co-ordinate - must be used in conjection with a y display co-ordinate and a radius. |
y | Display y co-ordinate - must be used in conjection with an x display co-ordinate and a radius. |
r | Radius around specified x/y display position. |
garrison | Settlement name of a garrison to look in, from the campaign_map_settlements table. |
character_cqi | The command queue index of a character. This is always unique. |
Should the filters specified in the character lookup string return more than one eligible character then only the first of these is used in the function call. Generally, it's a good idea to ensure that filters will only return one character, so it's strongly recommended to solely use the character_cqi
filter which will only ever match one character.
A filter may be specified in the lookup string in the form <filter_name>:<filter_value>
. Multiple filters may be specified in a lookup string, separated by a comma. Furthermore, the campaign manager function campaign_manager:char_lookup_str
can also be used to convert a character object, or its cqi number, into a character lookup string.
Example - Add trait to a character from the Empire faction at a display position [123,456]:
cm:force_add_trait("faction:wh_main_emp_empire,x:123,y:456,r:1", "trait_general_good", true)
Example - Remove all action points from a character with cqi 45:
cm:zero_action_points("character_cqi:45")
Example - Use the char_lookup_str
function to disable movement for the faction leader of the Greenskins:
local char_grn_faction_leader = cm:get_faction("wh_main_grn_greenskins"):faction_leader()
cm:disable_movement_for_character(cm:char_lookup_str(char_grn_faction_leader))
-
cm:is_new_game()
-
Returns
true
if this a new campaign game, orfalse
otherwise. A new game is one that has yet to be saved and reloaded.Returns:
is new gameboolean
-
cm:is_benchmark_mode()
-
Returns
true
if this campaign is running in benchmark mode, meaning it was launched from the benchmark section in the graphics options.Returns:
is benchmark modeboolean
-
cm:model()
-
Returns a handle to the campaign model object.
Returns:
userdata
campaign model
-
cm:filesystem_lookup(
pathstring
)
-
Perform a VFS lookup in the specified path (root is the data folder) for files matching the pattern. Returns a comma-delimited list of files found.
Parameters:
1
path
Returns:
file liststring
-
cm:compare_localised_string(
uicomponentuicomponent
,
label stringstring
)
-
Returns whether the supplied label string matches the text of a supplied uicomponent, taking localisation into account.
Parameters:
1
uicomponent
2
label string
Returns:
localisation matchesboolean
-
cm:is_dlc_flag_enabled(
dlc keystring
)
-
Returns whether the dlc with the specified key is activated.
Parameters:
1
dlc key
Returns:
dlc
flag enabled
-
cm:save_named_value(
value namestring
, data
value to save, context
context object)
-
Write a value to the savegame. This should only be called when the
SavingGame
event is received, and must be passed the context object supplied by that event.
It's recommended to use the saving functions provided by the campaign manager, listed in theSaving Game
section of this documentation, instead of directly calling this function.Parameters:
1
Value name.
2
data
3
context
context object
Returns:
nil
-
cm:load_named_value(
value namestring
, data
default value, context
context object)
-
Reads a value from a loading game. Should only be called when the
LoadingGame
event is received, and must be passed the context object supplied by that event.
It's recommended to use the loading functions provided by the campaign manager, listed in theLoading Game
section of this documentation, instead of directly calling this function.Parameters:
1
Value name.
2
data
This defines the type of the value to load from the savegame and also a default value which will be returned if no value with the specified name could be found in the savegame. Can be a
boolean
,number
orstring
.3
context
context object
Returns:
-
cm:disable_saving_game(
should disableboolean
)
-
Prevents or allows the saving of the game.
Parameters:
1
should disable
Returns:
nil
-
cm:autosave_at_next_opportunity()
-
Autosave the game at the next opportunity.
Returns:
nil
The functions described in this section grant raw access to the creation and removal of time triggers in campaign. While it's possible to use them directly it is highly recommended to use the wrapper functions provided by the campaign_manager
object in script. These are listed in the Timer Callbacks
section of this documentation.
-
cm:add_time_trigger(
idstring
,
intervalnumber
, [
repeatboolean
])
-
Register a time trigger, in seconds. This will cause a
TimeTrigger
event to trigger after the specified interval.Parameters:
1
ID for this time trigger. This will be supplied with the
TimeTrigger
event when it is triggered.2
Interval after which to trigger the
TimeTrigger
event, in seconds.3
optional, default value=false
Repeats the time trigger if set to
true
.Returns:
nil
-
cm:remove_time_trigger(
idstring
)
-
Removes a time trigger by
string
id.Parameters:
1
id
Returns:
nil
-
cm:disable_end_turn(
should disableboolean
)
-
Prevents or allows ending turn.
Parameters:
1
should disable
Returns:
nil
-
cm:end_turn([
forceboolean
])
-
Ends the turn for the current faction, optionally forcing at the next opportunity. This optional flag should only be set for a player faction.
Parameters:
1
optional, default value=false
force
Returns:
nil
-
cm:set_ai_uses_human_display_speed(
use human speedboolean
)
-
Forces or un-forces any characters visible to humans to move at normal speed during the end-turn sequence. Overrides set using this function are saved into the savegame.
Parameters:
1
use human speed
Returns:
nil
-
cm:dismiss_advice()
-
Dismisses the advisor panel.
Returns:
nil
-
cm:dismiss_advice_at_end_turn(
should dismissboolean
)
-
Set whether or not advice should be dismissed on ending turn.
Parameters:
1
should dismiss
Returns:
nil
-
cm:trigger_campaign_vo(
campaign voiceover audio at a character's 3D position. The character specified also partially specifies the path by which the voiceover sound is looked up.
Triggers,
sound event
string
,
character lookup
string
,
delay
number
) -
Parameters:
1
Triggers
campaign voiceover audio at a character's 3D position. The character specified also partially specifies the path by which the voiceover sound is looked up.
2
Sound event name.
3
Character lookup string - see
Character Lookups
for more information.4
Delay in seconds before triggering the vo.
Returns:
nil
The functions in this section make use of camera co-ordinates. These are specified by five numeric components:
- display x co-ordinate of camera target
- display y co-ordinate of camera target
- horizontal distance from target to camera
- horizontal bearing in radians of target from camera
- height of camera
Example - scroll_camera_with_direction usage:
Example ofcm:scroll_camera_with_direction
usage showing multiple groups of co-ordinates supplied in table
containers.
cm:scroll_camera_with_direction(true, 7, {490.8, 276.6, 5.6, 1.01, 4.0}, {491.0, 276.0, 5.6, 1.59, 4.0})
-
cm:set_camera_position(
xnumber
,
ynumber
,
dnumber
,
bnumber
,
hnumber
)
-
Repositions the camera to the specified co-ordinates.
Parameters:
1
Display x co-ordinate of camera target.
2
Display y co-ordinate of camera target.
3
Horizontal distance from camera to target.
4
Horizontal bearing in radians of target from camera.
5
Height of camera.
Returns:
nil
-
cm:get_camera_position()
-
Returns the current position of the camera.
Returns:
-
cm:scroll_camera_with_direction(
adjust endpointboolean
,
scroll timenumber
, vararg
co-ordinate list)
-
Scroll the camera along a list of co-ordinates that define a spline.
Parameters:
1
Adjust the endpoint to be valid for gameplay. Set this to
true
if control is to be restored to the player after this camera movement finishes. Set tofalse
if another camera movement follows this one.2
Scroll time in seconds
3
vararg
Vararg list of co-ordinates. Each co-ordinate must be specified in a
table
containing fivenumber
co-ordinate components.Returns:
nil
-
cm:stop_camera()
-
Stops a scrolling camera.
Returns:
nil
-
cm:fade_scene(
brightnessnumber
,
durationnumber
)
-
Fades the scene to black or back to picture over a specified period.
Parameters:
1
Brightness, as a unary value. Supply a value of
0
to fade to black, supply a value of1
to fade to picture, or supply a value in between to transition to a partially-faded picture.2
Duration of the fade effect in seconds.
Returns:
nil
-
cm:register_instant_movie(
movie pathstring
)
-
Plays a fullscreen movie, by path from the
data/Movies
directory.Parameters:
1
movie path
Returns:
nil
-
cm:register_outro_movie(
movie pathstring
)
-
Plays a fullscreen movie for an outro, by path from the
data/Movies
directory. The campaign will exit once playback has completed.Parameters:
1
movie path
Returns:
nil
-
cm:play_movie_in_ui(
movie pathstring
)
-
Plays a movie in the movie panel, by path from the
data/Movies
directory.Parameters:
1
movie path
Returns:
nil
-
cm:cinematic()
-
Returns a cinematic script interface.
Returns:
cinematic interfacecinematics
-
cm:override_ui(
ui override namestring
,
activate overrideboolean
)
-
Activates or deactivates a ui override.
Parameters:
1
ui override name
2
activate override
Returns:
nil
-
cm:stop_user_input(
stop inputboolean
)
-
Stops or allows user input.
Parameters:
1
stop input
Returns:
nil
-
cm:steal_user_input(
steal inputboolean
)
-
Steals user input, so that input notifications are redirected to script. When keypresses are stolen by script the game calls a function called
OnKeyPressed
when a keypress occurs. This function can be declared in script to receive these notifications.Parameters:
1
steal input
Returns:
nil
-
cm:steal_escape_key(
steal escape keyboolean
)
-
Steals the ESC key, so that keypresses on it are redirected to script. When keypresses are stolen by script the game calls a function called
OnKeyPressed
when a keypress occurs. This function can be declared in script to receive these notifications.Parameters:
1
steal escape key
Returns:
nil
-
cm:enable_ui(
enable uiboolean
)
-
Enables or disables the user interface.
Parameters:
1
enable ui
Returns:
nil
-
cm:disable_shortcut(
component idstring
,
function idstring
,
should disableboolean
)
-
Disables or re-enables a shortcut by name. Shortcuts can be looked up in
data/text/default_keys.xml
.Parameters:
1
Component id, specified by the
component
attibute of afunc
element.2
Function id, specified by the
name
attribute of afunc
element.3
Should disable.
Returns:
nil
-
cm:add_unit_model_overrides(
character lookupstring
,
model keystring
)
-
Swap a model for a certain character. This needs to be set up at a new session.
Parameters:
1
Character lookup string - see
Character Lookups
for more information.2
model key
Returns:
nil
-
cm:highlight_movement_extents(
should highlightboolean
)
-
Causes movement extents surrounded a selected character in the game to flash or not.
Parameters:
1
should highlight
Returns:
nil
-
cm:highlight_selected_character_zoc(
should highlightboolean
)
-
Causes the zone of control surrounding a selected character in the game to flash or not.
Parameters:
1
should highlight
Returns:
nil
-
cm:add_marker(
marker idstring
,
marker typestring
,
xnumber
,
ynumber
,
heightnumber
)
-
Add a marker at a specified display position, using a specified marker type. These markers are distinct from VFX in that they are generally 2D, clickable UI elements at a position on the battlefield.
Parameters:
1
Unique id for this marker, by which it may be later removed.
2
Marker type. Supported marker types are
move_to
,select
,pointer
,move_to_vfx
,select_vfx
,look_at_vfx
andobjective
.3
x display position.
4
y display position.
5
height above water plane.
Returns:
nil
-
cm:remove_marker(
marker idstring
)
-
Removes a marker previously added using
cm:add_marker
, by marker id.Parameters:
1
marker id
Returns:
nil
-
cm:add_interactable_campaign_marker(
unique id
string
,
marker info
string
,
x
number
,
y
number
,
radius
number
,
faction key
string
,
subculture key
string
) -
Add an interactable campaign marker of a specified type to the campaign map at a specified location. A radius around the marker is specified. As matching campaign characters enter or leave this radius then
AreaEntered
/AreaExited
events will be triggered.
Subculture and faction keys can be specified in order to filter what campaign characters should trigger the proximity events.
Interactable campaign markers can be used for game features such as encounters at sea.Parameters:
1
Unique id for this campaign marker, by which it may be later removed with
cm:remove_interactable_campaign_marker
.2
Marker info key. This should match a record from the
campaign_interactable_marker_infos
table.3
Logical x position for the marker.
4
Logical y position for the marker.
5
Radius around the position at which to trigger
AreaEntered
/AreaExited
events.6
Faction key filter. A blank string can be supplied to omit this.
7
Subculture key filter. A blank string can be supplied to omit this.
Returns:
nil
-
cm:remove_interactable_campaign_marker(
unique idstring
)
-
Removes an interactable campaign marker that was previously added with
cm:add_interactable_campaign_marker
, by unique id.Parameters:
1
unique id
Returns:
nil
-
cm:add_vfx(
vfx idstring
,
vfxstring
,
xnumber
,
ynumber
,
heightnumber
)
-
Adds a vfx of a specified type at a specified display position. VFX are distinct from markers in that they are generally 3D graphical effects.
Parameters:
1
Unique id for this vfx, by which it may later be removed with
cm:remove_vfx
.2
VFX type. This must be an entry from the
vfx_event
field of thecampaign_vfx_lookups
table.3
x display position.
4
y display position.
5
height above water plane.
Returns:
nil
-
cm:remove_vfx(
vfx idstring
)
-
Removes a vfx previously added with
cm:add_vfx
, by vfx id.Parameters:
1
vfx id
Returns:
nil
-
cm:add_character_vfx(
character cqinumber
,
vfxstring
,
show in shroudboolean
)
-
Adds a vfx to a specified character.
Parameters:
1
Command queue index of the character.
2
VFX type. This must be an entry from the
vfx_event
field of thecampaign_vfx_lookups
table.3
Show this vfx even when the character is under the shroud.
Returns:
nil
-
cm:remove_character_vfx(
character cqinumber
,
vfxstring
)
-
Removes a vfx from a specified character.
Parameters:
1
Command queue index of the character.
2
VFX type. This must be an entry from the
vfx_event
field of thecampaign_vfx_lookups
table.Returns:
nil
-
cm:add_garrison_residence_vfx(
garrison residence cqinumber
,
vfxstring
,
show in shroudboolean
)
-
Adds a vfx to a specified garrison residence/settlement.
Parameters:
1
Command queue index of the garrison residence.
2
VFX type. This must be an entry from the
vfx_event
field of thecampaign_vfx_lookups
table.3
Show this vfx even when the garrison residence is under the shroud.
Returns:
nil
-
cm:remove_garrison_residence_vfx(
character cqinumber
,
vfxstring
)
-
Removes a vfx from a specified character.
Parameters:
1
Command queue index of the character.
2
VFX type. This must be an entry from the
vfx_event
field of thecampaign_vfx_lookups
table.Returns:
nil
-
cm:add_scripted_composite_scene_to_logical_position(
name
string
,
composite scene
string
,
x
number
,
x
number
,
facing x
number
,
facing y
number
,
one shot
boolean
,
show in seen shroud
boolean
,
show in unseen shroud
boolean
) -
Adds a composite scene at a specified logical position.
Parameters:
1
Unique name for this composite scene, by which it may later be removed with
cm:remove_scripted_composite_scene
.2
Composite scene key from the
campaign_composite_scenes
table.3
Logical x co-ordinate.
4
Logical y co-ordinate.
5
Logical x co-ordinate of a position this composite scene faces.
6
Logical y co-ordinate of a position this composite scene faces.
7
One shot - if set to
true
, this composite scene is not added to the internal list of scenes and can't later be removed withcm:remove_scripted_composite_scene
. However, the name of one-shot scenes does not have to be unique.8
Sets whether this composite scene should be drawn when in thin shroud over previously-seen terrain.
9
Sets whether this composite scene should be drawn when in thick shroud over unseen terrain.
Returns:
action successfulboolean
-
cm:add_scripted_composite_scene_to_settlement(
name
string
,
composite scene
string
,
settlement key
string
,
facing x
number
,
facing y
number
,
one shot
boolean
,
show in seen shroud
boolean
,
show in unseen shroud
boolean
) -
Adds a composite scene to a specified settlement.
Parameters:
1
Unique name for this composite scene, by which it may later be removed with
cm:remove_scripted_composite_scene
.2
Composite scene key from the
campaign_composite_scenes
table.3
Key of settlement to add the scene to, from the
campaign_map_settlements
table.4
Logical x co-ordinate of a position this composite scene faces.
5
Logical y co-ordinate of a position this composite scene faces.
6
One shot - if set to
true
, this composite scene is not added to the internal list of scenes and can't later be removed withcm:remove_scripted_composite_scene
. However, the name of one-shot scenes does not have to be unique.7
Sets whether this composite scene should be drawn when in thin shroud over previously-seen terrain.
8
Sets whether this composite scene should be drawn when in thick shroud over unseen terrain.
Returns:
action successfulboolean
-
cm:add_scripted_composite_scene_to_settlement_port(
name
string
,
composite scene
string
,
settlement key
string
,
facing x
number
,
facing y
number
,
one shot
boolean
,
show in seen shroud
boolean
,
show in unseen shroud
boolean
) -
Adds a composite scene to the port slot of a specified settlement.
Parameters:
1
Unique name for this composite scene, by which it may later be removed with
cm:remove_scripted_composite_scene
.2
Composite scene key from the
campaign_composite_scenes
table.3
Key of settlement to add the scene to, from the
campaign_map_settlements
table.4
Logical x co-ordinate of a position this composite scene faces.
5
Logical y co-ordinate of a position this composite scene faces.
6
One shot - if set to
true
, this composite scene is not added to the internal list of scenes and can't later be removed withcm:remove_scripted_composite_scene
. However, the name of one-shot scenes does not have to be unique.7
Sets whether this composite scene should be drawn when in thin shroud over previously-seen terrain.
8
Sets whether this composite scene should be drawn when in thick shroud over unseen terrain.
Returns:
action successfulboolean
-
cm:remove_scripted_composite_scene(
namestring
)
-
Removes a composite scene previously added by script, by the unique name given.
Parameters:
1
name
Returns:
nil
The shroud is the fog of war covering areas on the campaign map that have yet to be seen. The shroud on a region - the area surrounding and associated with a settlement - may be either covered, seen or visible.
- Covered regions are shown with thick shroud which obscures land features, settlements and characters.
- Seen regions are shown with thin shroud through which settlements and land features are shown, but not characters.
- Visible regions are fully displayed.
The following functions allow some manipulation of the shroud. In all cases, the shroud is recalculated during the end-turn sequence, so modifications to the shroud are lost and have to re-applied at the start of the round or player's turn.
-
cm:show_shroud(
showboolean
)
-
Enables or disables the shroud.
Parameters:
1
show
Returns:
nil
-
cm:take_shroud_snapshot()
-
Caches the state of the shroud across the map, so that it may later be recalled with
cm:restore_shroud_from_snapshot
.Returns:
nil
-
cm:restore_shroud_from_snapshot()
-
Restores the state of the shroud across the map after it has been cached with
cm:take_shroud_snapshot
.Returns:
nil
-
cm:make_neighbouring_regions_visible_in_shroud()
-
Makes all neighbouring regions visible in the shroud, for all factions. This effect will persist until the next round.
Returns:
nil
-
cm:make_neighbouring_regions_seen_in_shroud()
-
Makes all neighbouring regions seen in the shroud, for all factions. This effect will persist until the next round.
Returns:
nil
-
cm:make_region_visible_in_shroud(
faction keystring
,
region keystring
)
-
Removes the shroud from a specified land region for a specific faction. The region specified must be a land region.
Parameters:
1
Faction key, from the
factions
table.2
Region key, from the
campaign_map_regions
table.Returns:
nil
-
cm:make_region_seen_in_shroud(
faction keystring
,
region keystring
)
-
Sets the shroud state of a specified land region to seen, for a specific faction. The region specified must be a land region.
Parameters:
1
Faction key, from the
factions
table.2
Region key, from the
campaign_map_regions
table.Returns:
nil
-
cm:make_sea_region_visible_in_shroud(
region keystring
)
-
Removes the shroud from a specified sea region for all factions.
Parameters:
1
Region key, from the
campaign_map_regions
table.Returns:
nil
-
cm:make_sea_region_seen_in_shroud(
region keystring
)
-
Sets the shroud state of a specified sea region for all factions to seen. The specified region must be a sea region.
Parameters:
1
Region key, from the
campaign_map_regions
table.Returns:
nil
-
cm:disable_movement_for_ai_under_shroud(
player faction keystring
,
ai faction keystring
)
-
Removes all action points for characters from the specified target faction if they are hidden under the shroud of the specified player faction. This is a one-time action, and should be called each turn if it's desired that AI movement for a faction be stopped until 'discovered' by the player.
Parameters:
1
player faction key
2
ai faction key
Returns:
nil
-
cm:disable_shopping_for_ai_under_shroud(
should disableboolean
)
-
Prevents all factions hidden under the shroud from constructing or repairing buildings. Unlike other functions documented here this is a game-wide toggle and does not need to be set each turn. This should only be used in a singleplayer game.
Parameters:
1
should disable
Returns:
nil
-
cm:create_force(
faction key
string
,
unit list
string
,
region key
string
,
x
number
,
y
number
,
id
string
,
exclude unique characters
boolean
,
command queue
boolean
) -
Creates an army or a navy at the specified position, belonging to the specified faction, with the specified list of units. If the faction doesn't exist on the campaign map then it will also be created.
Parameters:
1
Faction key from the
factions
table.2
Unit list. This should be a comma-separated list of unit keys from the
main_units
table.3
Region in which the force is created, from the
campaign_map_regions
table.4
Logical x co-ordinate.
5
Logical y co-ordinate.
6
ID of force. A
ScriptedForceCreated
event is triggered once the military force is created, and this ID is included in the context of the event so that listening scripts can differentiate between multiple created forces.7
Prevent this force from having a unique character appointed as its general.
8
Send this command via the command queue. Setting this to
true
will cause a delay of a game tick or two before the force is created.Returns:
nil
-
cm:create_force_with_general(
faction key
string
,
unit list
string
,
region key
string
,
x
number
,
y
number
,
character type
string
,
character subtype
string
,
forename
string
,
clanname
string
,
surname
string
,
other name
string
,
id
string
,
make faction leader
boolean
) -
Creates an army or a navy commanded by a specified character at the specified position, belonging to the specified faction, with the specified list of units. If the faction doesn't exist on the campaign map then it will also be created.
Parameters:
1
Faction key from the
factions
table.2
Unit list. This should be a comma-separated list of unit keys from the
main_units
table.3
Region in which the force is created, from the
campaign_map_regions
table.4
Logical x co-ordinate.
5
Logical y co-ordinate.
6
Character type key, from the
agents
table.7
Character subtype key, from the
agent_subtypes
table.8
Forename id. This should be a value from the
id
field of thenames
table.9
Clan name id. This should be a value from the
id
field of thenames
table. This can be used to grant a title such as "Admiral" or "Emperor". A blank string may be supplied to omit this.10
Surname id. This should be a value from the
id
field of thenames
table. A blank string may be supplied to omit this.11
Other name id. This should be a value from the
id
field of thenames
table. This is currently unused and should be set to a blank string.12
ID of force. A
ScriptedForceCreated
event is triggered once the military force is created, and this ID is included in the context of the event so that listening scripts can differentiate between multiple created forces.13
Make this character the faction leader.
Returns:
nil
-
cm:create_force_with_existing_general(
character lookup
string
,
faction key
string
,
unit list
string
,
region key
string
,
x
number
,
y
number
,
id
string
) -
Creates an army or a navy commanded by a specified existing character at the specified position, belonging to the specified faction, with the specified list of units.
Parameters:
1
Character lookup string specifying the character to appoint as force commander. See
Character Lookups
for more information.2
Faction key from the
factions
table.3
Unit list. This should be a comma-separated list of unit keys from the
main_units
table.4
Region in which the force is created, from the
campaign_map_regions
table.5
Logical x co-ordinate.
6
Logical y co-ordinate.
7
ID of force. A
ScriptedForceCreated
event is triggered once the military force is created, and this ID is included in the context of the event so that listening scripts can differentiate between multiple created forces.Returns:
nil
-
cm:create_force_with_full_diplomatic_discovery(
faction key
string
,
unit list
string
,
region key
string
,
x
number
,
y
number
,
id
string
,
exclude unique characters
boolean
,
command queue
boolean
) -
Creates an army or a navy commanded by a specified existing character at the specified position, belonging to the specified faction, with the specified list of units.
This command is distinct fromcm:create_force
in that it forces factions who can see the created force to be diplomatically aware of the force's faction.Parameters:
1
Faction key from the
factions
table.2
Unit list. This should be a comma-separated list of unit keys from the
main_units
table.3
Region in which the force is created, from the
campaign_map_regions
table.4
Logical x co-ordinate.
5
Logical y co-ordinate.
6
ID of force. A
ScriptedForceCreated
event is triggered once the military force is created, and this ID is included in the context of the event so that listening scripts can differentiate between multiple created forces.7
Prevent this force from having a unique character appointed as its general.
8
Send this command via the command queue. Setting this to
true
will cause a delay of a game tick or two before the force is created.Returns:
nil
-
cm:create_agent(
faction key
string
,
agent type
string
,
agent subtype
string
,
x
number
,
y
number
,
id
string
,
command queue
boolean
) -
Create an agent/hero character at a specified position.
Parameters:
1
Faction key from the
factions
table.2
Agent type from the
agents
table.3
Agent subtype from the
agent_subtypes
table.4
Logical x co-ordinate.
5
Logical y co-ordinate.
6
ID of agent. A
ScriptedAgentCreated
event is triggered once the character is created, and this ID is included in the context of the event so that listening scripts can differentiate between multiple created agents.7
Send this command via the command queue. Setting this to
true
will cause a delay of a game tick or two before the force is created.Returns:
nil
-
cm:spawn_agent_at_position(
faction
FACTION_SCRIPT_INTERFACE,
x
number
,
y
number
,
agent type
string
,
agent subtype
[string
]
) -
Spawns an agent of the specified type at the specified logical position.
See theModel Hierarchy
documentation for more information on theFACTION_SCRIPT_INTERFACE
interface.Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction interface for the agent's faction.
2
x logical co-ordinate.
3
y logical co-ordinate.
4
Agent type key, from the
agents
table.5
optional, default value=""
Agent subtype key, from the
agent_subtypes
table. This can be omitted.Returns:
nil
-
cm:spawn_agent_at_settlement(
faction
FACTION_SCRIPT_INTERFACE,
settlement
SETTLEMENT_SCRIPT_INTERFACE,
agent type
string
,
agent subtype
[string
]
) -
Spawns an agent of the specified type next to the specified settlement.
See theModel Hierarchy
documentation for more information on theFACTION_SCRIPT_INTERFACE
orSETTLEMENT_SCRIPT_INTERFACE
interfaces.Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction interface for the agent's faction.
2
SETTLEMENT_SCRIPT_INTERFACE
Settlement at which to spawn the agent.
3
Agent type key, from the
agents
table.4
optional, default value=""
Agent subtype key, from the
agent_subtypes
table. This can be omitted.Returns:
nil
-
cm:spawn_agent_at_military_force(
faction
FACTION_SCRIPT_INTERFACE,
force
MILITARY_FORCE_SCRIPT_INTERFACE,
agent type
string
,
agent subtype
[string
]
) -
Spawns an agent of the specified type next to the specified military force.
See theModel Hierarchy
documentation for more information on theFACTION_SCRIPT_INTERFACE
orMILITARY_FORCE_SCRIPT_INTERFACE
interfaces.Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction interface for the agent's faction.
2
MILITARY_FORCE_SCRIPT_INTERFACE
Military force at which to spawn the agent.
3
Agent type key, from the
agents
table.4
optional, default value=""
Agent subtype key, from the
agent_subtypes
table. This can be omitted.Returns:
nil
-
cm:embed_agent_in_force(CHARACTER_SCRIPT_INTERFACE
agent, MILITARY_FORCE_SCRIPT_INTERFACE
military force)
-
Instantly embed the specified agent in the specified force. The agent will teleport into the force, disregarding normal restrictions other than that force being under siege. See the
Model Hierarchy
documentation for more information on theCHARACTER_SCRIPT_INTERFACE
orMILITARY_FORCE_SCRIPT_INTERFACE
interfaces.Parameters:
1
CHARACTER_SCRIPT_INTERFACE
agent
2
MILITARY_FORCE_SCRIPT_INTERFACE
military force
Returns:
nil
-
cm:spawn_unique_agent(
faction cqinumber
,
agent keystring
,
forceboolean
)
-
Creates a unique agent.
Parameters:
1
Faction cqi.
2
Agent record key, from the
unique_agents
table.3
Force agent to spawn even if invalid.
Returns:
nil
-
cm:spawn_unique_agent_at_region(
faction cqinumber
,
agent keystring
,
region cqinumber
,
forceboolean
)
-
Creates a unique agent in a specified region.
Parameters:
1
Faction cqi.
2
Agent record key, from the
unique_agents
table.3
The cqi of the target region.
4
Force agent to spawn even if invalid.
Returns:
nil
-
cm:spawn_unique_agent_at_character(
faction cqi
number
,
agent key
string
,
character cqi
number
,
force
boolean
) -
Creates a unique agent at or near the position of a specified character.
Parameters:
1
Faction cqi.
2
Agent record key, from the
unique_agents
table.3
The cqi of the target character.
4
Force agent to spawn even if invalid.
Returns:
nil
-
cm:spawn_rogue_army(
xnumber
,
ynumber
)
-
Spawns a rogue army of a specified rogue army faction, at a specified position. This command will fail if the rogue army is already alive or is flagged to naturally spawn.
string
faction key, Faction key, from thefactions
database table.Parameters:
1
Logical x co-ordinate.
2
Logical y co-ordinate.
Returns:
nil
-
cm:spawn_character_to_pool(
faction
string
,
forename
string
,
surname
string
,
clanname
string
,
othername
string
,
age
number
,
male
boolean
,
agent key
string
,
agent subtype key
string
,
immortal
boolean
,
art set
string
) -
Spawns a new character in the specified faction's recruitment pool.
Parameters:
1
Faction key, from the
factions
table.2
Forename key. This should be a value from the
id
field of thenames
table.3
Surname key. This should be a value from the
id
field of thenames
table. A blank string may be supplied to omit this.4
Clan name key. This should be a value from the
id
field of thenames
table. This can be used to grant a title such as "Admiral" or "Emperor". A blank string may be supplied to omit this.5
Other name key. This should be a value from the
id
field of thenames
table. This is currently unused and should be set to a blank string.6
Age of character.
7
Set this character to be male or female.
8
Agent record key, from the
agents
table.9
Agent subtype key, from the
agent_subtypes
table.10
Sets whether this character is immortal.
11
Art set override id, from the
campaign_character_art_sets
table. A blank string may be supplied to omit this.Returns:
nil
-
cm:spawn_character_into_family_tree(
faction
string
,
forename
string
,
surname
string
,
clanname
string
,
othername
string
,
age
number
,
male
boolean
,
father
string
,
mother
string
,
immortal
boolean
,
art set
string
,
make heir
boolean
) -
Spawns a new character into a position in the family tree of the specified faction.
Parameters:
1
Faction key, from the
factions
table.2
Forename key. This should be a value from the
id
field of thenames
table.3
Surname key. This should be a value from the
id
field of thenames
table. A blank string may be supplied to omit this.4
Clan name key. This should be a value from the
id
field of thenames
table. This can be used to grant a title such as "Admiral" or "Emperor". A blank string may be supplied to omit this.5
Other name key. This should be a value from the
id
field of thenames
table. This is currently unused and should be set to a blank string.6
Age of character.
7
Set this character to be male or female.
8
Character lookup string specifying the father of the spawned character. For more information see the documentation on
Character Lookups
.9
Character lookup string specifying the mother of the spawned character. For more information see the documentation on
Character Lookups
.10
Sets whether this character is immortal.
11
Art set override id, from the
campaign_character_art_sets
table. A blank string may be supplied to omit this.12
Make this character the faction heir.
Returns:
nil
-
cm:find_valid_spawn_location_for_character_from_settlement(
faction key
string
,
region key
string
,
on sea
boolean
,
in same region
boolean
,
preferred spawn distance
[number
]
) -
Utilises the pathfinder to locate and return a valid spawn point for a character, based around a settlement. Returns
-1, -1
if invalid.Parameters:
1
Faction key, from the
factions
table.2
Region key of settlement, from the
campaign_map_regions
table.3
Specifies whether the position should be on the sea.
4
Specifies whether the spawn location should be in the same region as the specified settlement.
5
optional, default value=0
Specifies the distance at which the character should spawn.
Returns:
logical
x co-ordinatelogical
y co-ordinate
-
cm:find_valid_spawn_location_for_character_from_position(
faction key
string
,
x
number
,
y
number
,
in same region
boolean
,
preferred distance
[number
]
) -
Utilises the pathfinder to locate and return a valid spawn point for a character, based around a position. Returns
-1, -1
if invalid.Parameters:
1
Faction key, from the
factions
table.2
Logical x co-ordinate of position around which to search.
3
Logical y co-ordinate of position around which to search.
4
Specifies whether the spawn location should be in the same region as the specified position.
5
optional, default value=0
Preferred spawn distance, in logical hexes.
Returns:
logical
x co-ordinatelogical
y co-ordinate
-
cm:find_valid_spawn_location_for_character_from_character(
faction key
string
,
character lookup
string
,
in same region
boolean
,
preferred distance
[number
]
) -
Utilises the pathfinder to locate and return a valid logical spawn point for a character, based around another character. Returns
-1, -1
if invalid.Parameters:
1
Faction key, from the
factions
table.2
Character lookup string of subject character. For more information see the documentation on
Character Lookups
.3
Specifies whether the spawn location should be in the same region as the specified character.
4
optional, default value=0
Preferred spawn distance, in logical hexes.
Returns:
logical
x co-ordinatelogical
y co-ordinate
-
cm:appoint_character_to_force(
character lookupstring
,
mf cqinumber
)
-
Appoints the specified character to the command of the specified military force. The character must be available (e.g. not dead or wounded, and not commanding another military force) for the appointment to work.
Parameters:
1
Character lookup string of subject character. For more information see the documentation on
Character Lookups
.2
Command-queue index of the military force to appoint the character to.
Returns:
nil
-
cm:appoint_character_to_most_expensive_force(
character lookupstring
)
-
Appoints the specified character to the command of the most expensive military force in their faction.
Parameters:
1
Character lookup string of subject character. For more information see the documentation on
Character Lookups
.Returns:
nil
-
cm:lock_starting_general_recruitment(
startpos idstring
,
faction keystring
)
-
Locks recruitment of a starting general, preventing them from being created from the recruitment pool. This also works for characters that are convalescing. The character must be specified by startpos id.
Parameters:
1
Startpos id of the target character. This is looked up from the
ID
field of thestart_pos_characters
table. This function cannot be used to lock recruitment of a character not present in the startpos data.2
Faction key of the character, from the
factions
table.Returns:
nil
-
cm:unlock_starting_general_recruitment(
startpos idstring
,
faction keystring
)
-
Unlocks recruitment of a starting general, allowing them to be recruited. This also works for characters that are convalescing. The character must be specified by startpos id.
Parameters:
1
Startpos id of the target character. This is looked up from the
ID
field of thestart_pos_characters
table. This function cannot be used to unlock recruitment of a character not present in the startpos data.2
Faction key of the character, from the
factions
table.Returns:
nil
The functions in this section all give order or manipulate the state of characters in the game. They make extensive use of Character Lookups
.
-
cm:add_agent_experience(
character lookupstring
,
pointsnumber
)
-
Adds experience points to a specified character.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Experience points to award.
Returns:
nil
-
cm:add_agent_experience_through_family_member(FAMILY_MEMBER_SCRIPT_INTERFACE
character,
pointsnumber
)
-
Adds experience points to a character specified by FAMILY_MEMBER_SCRIPT_INTERFACE. This interface is provided because if a character is in the process of dying, their FAMILY_MEMBER_SCRIPT_INTERFACE will exist where the CHARACTER_SCRIPT_INTERFACE may not.
Parameters:
1
FAMILY_MEMBER_SCRIPT_INTERFACE
FAMILY_MEMBER_SCRIPT_INTERFACE related to the character to apply experience points to.
2
Experience points to award.
Returns:
nil
-
cm:add_experience_to_units_commanded_by_character(
character lookupstring
,
levelnumber
)
-
Increases the experience of all units commanded by a specified character, by a specified level.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Level to increase experience of units by.
Returns:
nil
-
cm:set_character_experience_disabled(
disableboolean
)
-
Disables or re-enables characters gaining experience across the whole campaign. This restriction is saved into the savegame, so only needs to be set once.
Parameters:
1
Disable experience. Set to
false
to re-enable.Returns:
nil
-
cm:grant_unit_to_character(
character lookupstring
,
unit keystring
)
-
Create and add a specifiec unit to a military force commanded by a specified character. The unit will only be created if there is room for it in the force.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Key of unit to create, from the
main_units
table.Returns:
nil
-
cm:move_to(
character lookupstring
,
xnumber
,
ynumber
,
command queueboolean
)
-
Orders the specified character to move to a specified logical position. This is equivalent to the player or AI issuing the same order, and as such should only be done on that faction's turn.
Note that if the character is in a settlement, or the intended destination is a settlement, an enemy army, or another kind of special obstacle then it's likely that a different type of order is required - seecm:join_garrison
,cm:leave_garrison
andcm:attack
, for example.Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Logical x co-ordinate of target position.
3
Logical y co-ordinate of target position.
4
Send the order via the command queue. This causes a short delay before the order is actually given.
Returns:
nil
-
cm:move_to_queued(
character lookupstring
,
xnumber
,
ynumber
)
-
Enqueues an order for the specified character to move to a specified logical position. This action will happen once the current action completes.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Logical x co-ordinate of target position.
3
Logical y co-ordinate of target position.
Returns:
nil
-
cm:cancel_actions_for(
character lookupstring
)
-
Immediately cancels the current actions of a specified character.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.Returns:
nil
-
cm:teleport_to(
character lookupstring
,
xnumber
,
ynumber
,
command queueboolean
)
-
Orders the specified character to immediately teleport to a specified logical position. This order should only be given on that faction's turn.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Logical x co-ordinate of target position.
3
Logical y co-ordinate of target position.
4
Send the order via the command queue. This causes a short delay before the order is actually given.
Returns:
nil
-
cm:join_garrison(
character lookupstring
,
settlementstring
)
-
Orders the specified character to move into a specified garrison residence. The garrison is specified by settlement key. This is equivalent to the player or AI issuing the same order, and as such should only be done on that faction's turn.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Key of settlement containing the garrison residence, from the
campaign_map_settlements
table.Returns:
nil
-
cm:leave_garrison(
character lookupstring
,
xnumber
,
ynumber
)
-
Make the specified garrisoned character leave their garrison and move to a specified logical positon.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Logical x co-ordinate of target position.
3
Logical y co-ordinate of target position.
Returns:
nil
-
cm:attack(
character lookupstring
,
target character lookupstring
,
lay siegeboolean
)
-
Orders the specified character to attack a target character. This is equivalent to the player or AI issuing the same order, and as such should only be done on that faction's turn.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Target character lookup string. For more information, see
Character Lookups
.3
Instructs the character to lay siege to the target. This is useful if the target character is in a garrison.
Returns:
nil
-
cm:attack_queued(
character lookupstring
,
target character lookupstring
,
lay siegeboolean
)
-
Enqueues an order for the specified character to attack a target character. This action will happen once the current action completes.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Target character lookup string. For more information, see
Character Lookups
.3
Instructs the character to lay siege to the target. This is useful if the target character is in a garrison.
Returns:
nil
-
cm:attack_region(
character lookupstring
,
region keystring
,
command queueboolean
)
-
Orders the specified character to initiate an attack on the settlement in a target region. If the character cannot initiate a battle (for example he or she currently has no method to defeat the fortifications) then nothing will happen.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Region key containing the target settlement, from the
campaign_map_regions
table.3
Send the order via the command queue. This causes a short delay before the order is actually given.
Returns:
nil
-
cm:force_attack_of_opportunity(
attacker cqinumber
,
target cqinumber
,
is ambushboolean
)
-
Orders the specified character to attack a target character through an attack of opportunity - either an interception or an ambush. Note that this function requires character cqis to be passed in as arguments and not lookup strings.
The two characters must be of different factions that are at war and neither may be garrisoned for the action to succeed.Parameters:
1
Command-queue index of the attacking character.
2
Command-queue index of the target character.
3
Set to
true
to ambush, orfalse
to intercept.Returns:
nil
-
cm:seek_exchange(
character lookup
string
,
target character lookup
string
,
show ui
boolean
,
command queue
boolean
) -
Orders one character to seek a unit exchange with a target character, allowing troops to be swapped between the two armies they command.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Target character lookup string. For more information, see
Character Lookups
.3
Shows the seek exchange UI.
4
Send the order via the command queue. This causes a short delay before the order is actually given.
Returns:
nil
-
cm:replenish_action_points(
character lookupstring
)
-
Replenishes the action points of a specified character.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.Returns:
nil
-
cm:zero_action_points(
character lookupstring
)
-
Removes all action points from a specified character.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.Returns:
nil
-
cm:kill_character(
character lookupstring
,
destroy forceboolean
,
command queueboolean
)
-
Kills a specified character, and optionally also the entire military force they command.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Destroy the character and the entire military force they command.
3
Send the order via the command queue. This causes a short delay before the order is actually given.
Returns:
nil
-
cm:kill_character_and_commanded_unit(
character lookup
string
,
destroy force
boolean
,
command queue
boolean
) -
Kills a specified character and their associated unit, and optionally also the entire military force they command.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Destroy the character and the entire military force they command.
3
Send the order via the command queue. This causes a short delay before the order is actually given.
Returns:
nil
-
cm:wound_character(
character lookupstring
,
convalescence timenumber
,
command queueboolean
)
-
Wounds a specified character, forcing them to convalesce for a specified number of turns before they can be re-appointed.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Number of turns this character should convalesce for until they can be re-appointed.
3
Send the order via the command queue. This causes a short delay before the order is actually given.
Returns:
nil
-
cm:force_agent_action_success_for_human(
force successboolean
)
-
Force the local player's faction to succeed at all agent actions.
Parameters:
1
force success
Returns:
nil
-
cm:force_character_force_into_stance(
character lookupstring
,
stance keystring
)
-
Forces the military force commanded by the specified character into the specified stance.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Stance key, from the
campaign_stances
table.Returns:
nil
-
cm:set_only_allow_basic_recruit_stance(
force basic recruitment stancesboolean
)
-
Stops all military forces from entering non-default recruitment stances, such as raiding camp stance.
Parameters:
1
force basic recruitment stances
Returns:
nil
-
cm:remove_unit_from_character(
character lookupstring
,
unit keystring
)
-
Remove the first instance of the specified unit from the force commanded by the specified character.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Key of unit to remove, from the
main_units
table.Returns:
nil
-
cm:set_character_immortality(
character lookupstring
,
is immortalboolean
)
-
Sets whether the specified character can die or not.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
is immortal
Returns:
nil
-
cm:set_character_unique(
character lookupstring
,
is uniqueboolean
)
-
Sets whether the specified character is unique or not. This affects several aspects about how the game might treat that character such as when they might be available to recruit.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
is unique
Returns:
nil
-
cm:stop_character_convalescing(
character cqinumber
)
-
Instantly returns a convalescing (wounded) character to the available pool of recruitable characters for their faction.
Parameters:
1
character cqi
Returns:
nil
-
cm:modify_character_personal_loyalty_factor(
character lookupstring
,
loyalty modifiernumber
)
-
Modifies the loyalty of a specified character.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Amount to modify the loyalty by. This may be positive or negative.
Returns:
nil
-
cm:add_attack_of_opportunity_overrides(
character lookupstring
,
force attackboolean
)
-
Forces a specified character to always or never perform an attack of opportunity, meaning they will always/never intercept when they get the chance. Once in place, this override can be removed with
cm:remove_attack_of_opportunity_overrides
.Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Force an attack - if set to
true
the target character will always intercept, if set tofalse
the character will always decline to intercept.Returns:
nil
-
cm:remove_attack_of_opportunity_overrides(
character lookupstring
)
-
Removes any attack of opportunity override previously placed on the target character with
cm:add_attack_of_opportunity_overrides
.Parameters:
1
Character lookup string. For more information, see
Character Lookups
.Returns:
nil
-
cm:convert_force_to_type(MILITARY_FORCE_SCRIPT_INTERFACE
force,
typestring
)
-
Converts a military force to a specific type. The military force is specified by
MILITARY_FORCE_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information. The military force type is specified bystring
key, from themilitary_force_types
database table.Parameters:
1
MILITARY_FORCE_SCRIPT_INTERFACE
Military force.
2
Military force type, from the
military_force_types
table.Returns:
nil
-
cm:set_unit_hp_to_unary_of_maximum(UNIT_SCRIPT_INTERFACE
unit,
unary hpnumber
)
-
Sets the hit points/number of men to the given unary proportion of the maximum for that unit. The unit is specified by
UNIT_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information.Parameters:
1
UNIT_SCRIPT_INTERFACE
Unit.
2
Unary proportion (0-1) of max hp value to set unit health to.
Returns:
nil
-
cm:set_army_trespass_disabled(
should disableboolean
)
-
Globally disables or re-enables the penalties for army trespassing.
Parameters:
1
should disable
Returns:
nil
-
cm:add_circle_area_trigger(
x
number
,
y
number
,
radius
number
,
trigger name
string
,
character lookup
string
,
trigger on enter
boolean
,
trigger on exit
boolean
,
trigger once
boolean
) -
Establishes a circular area trigger monitor around a specified display position, with a specified character lookup string filter. This monitor will trigger an
AreaEntered
orAreaExited
script event if a character that matches the specified filter moves through the specified circular area boundary.Parameters:
1
x display co-ordinate.
2
y display co-ordinate.
3
Radius of circle.
4
Trigger name. Multiple trigger areas with the same name behave as a single trigger.
5
Character lookup string, specifying characters for which this trigger area will fire events. For more information, see
Character Lookups
.6
Specifies whether an
AreaEntered
event is fired when a matching character enters the trigger area.7
Specifies whether an
AreaExited
event is fired when a matching character exits the trigger area.8
Specifies whether the trigger continues monitoring after it fires its first event.
Returns:
nil
-
cm:add_outline_area_trigger(
trigger name
string
,
character lookup
string
,
trigger on enter
boolean
,
trigger on exit
boolean
,
trigger once
boolean
,
co-ordinates
...
) -
Establishes a area trigger monitor around a specified display position, with a specified character lookup string filter. The shape of the trigger area is specified by a series of supplied points. This monitor will trigger an
AreaEntered
orAreaExited
script event if a character that matches the specified filter moves through the specified circular area boundary.Parameters:
1
Trigger name. Multiple trigger areas with the same name behave as a single trigger.
2
Character lookup string, specifying characters for which this trigger area will fire events. For more information, see
Character Lookups
.3
Specifies whether an
AreaEntered
event is fired when a matching character enters the trigger area.4
Specifies whether an
AreaExited
event is fired when a matching character exits the trigger area.5
Specifies whether the trigger continues monitoring after it fires its first event.
6
...
Variable number of display co-ordinates, each supplied as an indexed table containing an x and y co-ordinate.
Returns:
nil
Example:
cm:add_outline_area_trigger(
"test_trigger",
"character_cqi:123",
true,
false,
true,
true,
{0, 0},
{0, 100},
{100, 100},
{100, 0}
);
-
cm:remove_area_trigger(
trigger namestring
)
-
Removes any area triggers established with
cm:add_circle_area_trigger
orcm:add_outline_area_trigger
with the supplied name.Parameters:
1
trigger name
Returns:
nil
-
cm:add_hex_area_trigger(
trigger name
string
,
x
number
,
y
number
,
radius
number
,
faction key
[string
],
subculture key
[string
]
) -
Establishes a area trigger monitor around a specified logical position, with a faction or subculture filter. This monitor will trigger an
AreaEntered
orAreaExited
script event if a character that matches the filter moves through the area boundary.Parameters:
1
Unique name for this area trigger.
2
Logical x co-ordinate for the hex area.
3
Logical y co-ordinate for the hex area.
4
Radius in hexes (max of 20).
5
optional, default value=""
Key of faction to which the area trigger should apply, from the
factions
table. This may be a blank string if a subculture key is supplied.6
optional, default value=""
Key of subculture to which the area trigger should apply, from the
Returns:
nil
-
cm:remove_hex_area_trigger(
trigger namestring
)
-
Removes any area triggers established with
cm:add_hex_area_trigger
with the supplied trigger name.Parameters:
1
trigger name
Returns:
nil
-
cm:force_add_trait(
character lookup
string
,
trait key
string
,
trait points
[number
],
command queue
[boolean
]
) -
Grant the specified trait to the specified character. If the character already has the trait, a trait point will be added.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Trait key, from the
character_traits
table.3
optional, default value=1
Number of trait points to add.
4
optional, default value=true
Issue this command via the command queue.
Returns:
nil
-
cm:force_remove_trait(
character lookupstring
,
trait keystring
)
-
Removes the specified trait from the specified character. If the character is past the point of no return in the trait, it will be removed anyway.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Trait key, from the
character_traits
table.Returns:
nil
-
cm:force_add_ancillary(
target_character
CHARACTER_SCRIPT_INTERFACE,
ancillary key
string
,
force equip
boolean
,
suppress event feed
boolean
) -
Grant the specified ancillary to the specified character.
Parameters:
1
CHARACTER_SCRIPT_INTERFACE
target_character
2
Ancillary key, from the
ancillaries
table.3
if true the ancillary will be equipped and bypass any cooldowns or pre-conditions
4
if true no event feed events will be generated by this action
Returns:
nil
-
cm:force_remove_ancillary(
target_character
CHARACTER_SCRIPT_INTERFACE,
ancillary key
string
,
remove to pool
boolean
,
suppress event feed
boolean
) -
Remove the specified ancilliary from the specified character.
Parameters:
1
CHARACTER_SCRIPT_INTERFACE
target_character
2
Ancillary key, from the
ancillaries
table.3
Removes the ancillary from the character but leaves it in the pool of available ancillaries.
4
if true no event feed events will be generated by this action
Returns:
nil
-
cm:add_ancillary_to_faction(
target faction
FACTION_SCRIPT_INTERFACE,
ancillary key
string
,
suppress event feed
boolean
) -
Grants the specified ancillary to the specified faction. The ancillary goes into that faction's ancillary pool, from where it may be equipped by a character.
Parameters:
1
FACTION_SCRIPT_INTERFACE
target faction
2
Ancillary key, from the
ancillaries
table.3
if true no event feed events will be generated by this action
Returns:
nil
-
cm:force_remove_ancillary_from_faction(FACTION_SCRIPT_INTERFACE
faction,
ancillary keystring
)
-
Remove all instances of the specified ancillary from every character, and the shared ancillary pool, of the specified faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
faction
2
Ancillary key, from the
ancillaries
table.Returns:
nil
-
cm:force_add_skill(
character lookupstring
,
skill keystring
)
-
Grant the specified skill to the specified character, or adds a point if they already have it.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Skill key, from the
character_skills
table.Returns:
nil
-
cm:remove_skill_point(
character lookupstring
,
skill keystring
)
-
Remove a skill point from the specified character and skill. Returns
true
if successful.Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Skill key, from the
character_skills
table.Returns:
skill point was removedboolean
-
cm:force_reset_skills(
character lookupstring
)
-
Completely resets the skill points of the target character. Does not remove background skills.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.Returns:
nil
-
cm:remove_all_background_skills(
character lookupstring
)
-
Forcibly remove all background skills for the specified character.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.Returns:
nil
-
cm:set_non_scripted_traits_disabled(
disableboolean
)
-
Prevents or allows the application of traits by
effect.trait
, which is intended to be the general-purpose trait-adding function.cm:force_add_trait
will still work even with this restriction in place.Parameters:
1
disable
Returns:
nil
-
cm:set_non_scripted_ancillaries_disabled(
disableboolean
)
-
Prevents or allows the application of ancillaries by
effect.ancillary
, which is intended to be the general-purpose ancillary-adding function.cm:force_add_ancillary
will still work even with this restriction in place.Parameters:
1
disable
Returns:
nil
-
cm:change_localised_faction_name(
faction keystring
,
name keystring
)
-
Changes the name of a faction. The new name is specified by full localised text key, in the [table]_[key]_[field] format.
Parameters:
1
Faction key, from the
factions
table.2
Localised name key, in the [table]_[key]_[field] format.
Returns:
nil
-
cm:change_custom_faction_name(
faction keystring
,
namestring
)
-
Changes the name of a faction. The new name is specified directly as a string.
Parameters:
1
Faction key, from the
factions
table.2
New name for the faction.
Returns:
nil
-
cm:change_custom_settlement_name(SETTLEMENT_SCRIPT_INTERFACE
settlement,
name keystring
)
-
Changes the name of a settlement. The new name is specified by full localised text key, in the [table]_[key]_[field] format.
Parameters:
1
SETTLEMENT_SCRIPT_INTERFACE
Settlement object - see the
Model Hierarchy
documentation for more information about this interface.2
Localised name key, in the [table]_[key]_[field] format.
Returns:
nil
-
cm:change_localised_settlement_name(SETTLEMENT_SCRIPT_INTERFACE
settlement,
namestring
)
-
Changes the name of a faction. The new name is specified directly as a string.
Parameters:
1
SETTLEMENT_SCRIPT_INTERFACE
Settlement object - see the
Model Hierarchy
documentation for more information about this interface.2
New name for the faction.
Returns:
nil
-
cm:change_custom_region_name(REGION_SCRIPT_INTERFACE
region,
name keystring
)
-
Changes the name of a region. The new name is specified by full localised text key, in the [table]_[key]_[field] format. Note that the region name is not currently used for display - see
cm:change_custom_settlement_name
instead.Parameters:
1
REGION_SCRIPT_INTERFACE
Region object - see the
Model Hierarchy
documentation for more information about this interface.2
Localised name key, in the [table]_[key]_[field] format.
Returns:
nil
-
cm:change_localised_region_name(REGION_SCRIPT_INTERFACE
region,
namestring
)
-
Changes the name of a region. The new name is specified directly as a string. Note that the region name is not currently used for display - see
cm:change_localised_settlement_name
instead.Parameters:
1
REGION_SCRIPT_INTERFACE
Region object - see the
Model Hierarchy
documentation for more information about this interface.2
New name for the region.
Returns:
nil
-
cm:change_custom_unit_name(UNIT_SCRIPT_INTERFACE
unit,
name keystring
)
-
Changes the name of a unit. The new name is specified by full localised text key, in the [table]_[key]_[field] format.
Parameters:
1
UNIT_SCRIPT_INTERFACE
Unit object - see the
Model Hierarchy
documentation for more information about this interface.2
Localised name key, in the [table]_[key]_[field] format.
Returns:
nil
-
cm:change_localised_unit_name(UNIT_SCRIPT_INTERFACE
unit,
namestring
)
-
Changes the name of a unit. The new name is specified directly as a string.
Parameters:
1
UNIT_SCRIPT_INTERFACE
Unit object - see the
Model Hierarchy
documentation for more information about this interface.2
New name for the unit.
Returns:
nil
-
cm:set_tax_rate(
faction keystring
,
tax ratenumber
)
-
Sets the tax rate for a specified faction. The tax rate may be one of the following integer values:
Value Description
0
minimal 1
low 2
normal 3
high 4
extortionate Parameters:
1
Faction key, from the
factions
table.2
Tax rate, from the table above.
Returns:
nil
-
cm:exempt_region_from_tax(
region keystring
,
exemptboolean
)
-
Exempts, or un-exempts, the province containing specified region from tax contributions.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Exempt province from tax.
Returns:
nil
-
cm:exempt_province_from_tax_for_all_factions_and_set_default(
region keystring
,
exemptboolean
)
-
Exempt the province containing specified region from tax for all factions that own a settlement within it, and set the default for future factions.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Exempt province from tax.
Returns:
nil
-
cm:disable_rebellions_worldwide(
disableboolean
)
-
Disables or re-enables all rebellions across the map.
Parameters:
1
disable
Returns:
nil
-
cm:force_rebellion_in_region(
region keystring
,
unitsnumber
,
xnumber
,
ynumber
,
suppress messageboolean
)
-
Force a rebellion of a specified size in the specified region.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Maximum number of units in the spawned rebellion.
3
Logical x co-ordinate of target position.
4
Logical y co-ordinate of target position.
5
Suppress the event message related to the rebellion.
Returns:
nil
-
cm:treasury_mod(
faction keystring
,
amountnumber
)
-
Immediately modifies the treasury of the specified faction by the specified amount. The supplied value can be positive or negative.
Parameters:
1
Faction key, from the
factions
table.2
Treasury modification.
Returns:
nil
-
cm:set_public_order_of_province_for_region(
region keystring
,
public ordernumber
)
-
Sets the public order value for the province containing the specified region.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Public order value.
Returns:
nil
-
cm:set_public_order_disabled_for_province_for_region(
region keystring
,
disableboolean
)
-
Disables or re-enables public order in the province containing the specified region.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Disable public order.
Returns:
nil
-
cm:set_public_order_disabled_for_province_for_region_for_all_factions_and_set_default(
region key
string
,
disable
boolean
) -
Disables or re-enables public order in the province containing the specified region, for all factions that own settlements within the province, including factions that capture territory there in the future.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Disable public order.
Returns:
nil
-
cm:add_development_points_to_region(
region keystring
,
development pointsnumber
)
-
Adds development points to the province containing the specified region.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Developments points to add.
Returns:
nil
-
cm:set_imperium_level_change_disabled(
disableboolean
)
-
Disables or re-enables imperium level changes across the whole campaign.
Parameters:
1
disable
Returns:
nil
-
cm:set_region_abandoned(
region keystring
)
-
Immediately sets the specified to be abandoned. Nothing will happen if an already-abandoned region is specified.
Parameters:
1
Region key, from the
campaign_map_regions
table.Returns:
nil
-
cm:transfer_region_to_faction(
region keystring
,
faction keystring
)
-
Immediately transfers ownership of the specified region to the specified faction.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Faction key, from the
factions
table.Returns:
nil
-
cm:create_storm_for_region(
region keystring
,
storm strengthnumber
,
durationnumber
, [
storm typestring
])
-
Creates a storm of a given type in a given region.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Storm strength. The strength of existing storm instances can be looked up in the
campaign_storms
table.3
Duration of the storm in turns.
4
optional, default value=false
Storm type, looked up from the
campaign_storm_types
table. By default, this is set to"land_storm"
for a land region and"wandering_decaying_sea_storm"
for a sea region.Returns:
nil
-
cm:heal_garrison(
region cqinumber
)
-
Heals the garrison army (and navy, where applicable) in the specified region back to full health. The region is specified by cqi.
Parameters:
1
Command-queue index of the target region.
Returns:
nil
-
cm:set_liberation_options_disabled(
disableboolean
)
-
Disables or re-enables post-battle liberation options for the player.
Parameters:
1
disable
Returns:
nil
-
cm:force_religion_factors(
region key
string
,
religion key
string
,
religion proportion
number
,
extra religions
...
) -
Forces the balance of religions in a specified province to specified values. The key of a region within the target province must be specified, along with one or more argument pairs specifying a religion key and a proportion for that religion. The sum of all specified religion proportions must equal 1. At least one religion/religion proportion pair of arguments must therefore be specified. Religions not specified in the arguments of this function call will not be present in the target province.
The religion system in Warhammer is repurposed to represent corruption. Use this function to override the setup of corruption within a province.
Note that this function will only work if called on turn one.Parameters:
1
Key of a region within the target province, from the
campaign_map_regions
table.2
Key of a religion, from the
religions
table.3
Unary proportion (0-1) of the religion specified by the previous argument. The unary proportion of all specified religions should add up to 1.
4
...
Extra religion key/religion proportion pairs of arguments, if desired.
Returns:
nil
Example - Force a 60/40 untainted/undead corruption setup in Altdorf on turn one:
cm:force_religion_factors("wh_main_reikland_altdorf", "wh_main_religion_untainted", 0.6, "wh_main_religion_undeath", 0.40);
-
cm:add_unit_to_faction_mercenary_pool(
faction
FACTION_SCRIPT_INTERFACE,
unit
string
,
count
number
,
replenishment chance
number
,
max units
number
,
max per turn
number
,
xp
number
,
faction restriction
string
,
subculture restriction
string
,
tech restriction
string
,
partial replenishment
boolean
) -
Adds one or more units of a specified type to a faction's mercenary pool. These units can then be recruitable by that faction (or potentially other factions) using gameplay mechanics such as Regiments of Renown or Wulfhart's Mercenaries.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction whose pool the unit(s) should be added to. For more information about the
FACTION_SCRIPT_INTERFACE
interface see theModel Hierarchy
documentation.2
Key of unit to add to the mercenary pool, from the
main_units
table.3
Number of units to add to the mercenary pool.
4
Replenishment chance, as a percentage. This is the chance per-turn that the number of available units in the pool of the supplied type will be increased, if not already at its maximum.
5
The maximum number of units of the supplied type that the pool is allowed to contain.
6
The maximum number of units of the supplied type that may be added by replenishment per-turn.
7
The experience level of the units when recruited. This should be an integer value between
0-9
.8
The key of the faction who can actually recruit the units, from the
factions
database table. This may be different from the faction whose pool the unit is added to. An empty string""
may be supplied to omit this, which will usually be the case.9
The key of the subculture who can actually recruit the units, from the
cultures_subcultures
database table. An empty string""
may be supplied to omit this, which will usually be the case.10
The key of a technology that must be researched in order to recruit the units, from the
technologies
database table.11
Allow replenishment of partial units.
Returns:
nil
-
cm:add_units_to_faction_mercenary_pool(
faction cqinumber
,
unit keystring
,
countnumber
)
-
Adds one or more of a specified unit to the specified faction's mercenary pool. Unlike with
cm:add_units_to_faction_mercenary_pool
, the unit type must already be represented in the pool.Parameters:
1
CQI of the subject faction.
2
Unit key, from the
main_units
table.3
Number of units to add.
Returns:
nil
-
cm:add_unit_to_province_mercenary_pool(
region
REGION_SCRIPT_INTERFACE,
unit
string
,
count
number
,
replenishment chance
number
,
max units
number
,
max per turn
number
,
xp
number
,
faction restriction
string
,
subculture restriction
string
,
tech restriction
string
) -
Adds one or more units of a specified type to the mercenary pool in a province. These units can then be recruitable by that faction (or potentially other factions) using gameplay mechanics such as Raising Dead.
Parameters:
1
REGION_SCRIPT_INTERFACE
Region within the province to which the unit(s) should be added. For more information about the
REGION_SCRIPT_INTERFACE
interface see theModel Hierarchy
documentation.2
Key of unit to add to the mercenary pool, from the
main_units
table.3
Number of units to add to the mercenary pool.
4
Replenishment chance, as a percentage. This is the chance per-turn that the number of available units in the pool of the supplied type will be increased, if not already at its maximum.
5
The maximum number of units of the supplied type that the pool is allowed to contain.
6
The maximum number of units of the supplied type that may be added by replenishment per-turn.
7
The experience level of the units when recruited. This should be an integer value between
0-9
.8
The key of the faction who can actually recruit the units, from the
factions
database table. This may be different from the faction whose pool the unit is added to. An empty string""
may be supplied to omit this, which will usually be the case.9
The key of the subculture who can actually recruit the units, from the
cultures_subcultures
database table. An empty string""
may be supplied to omit this, which will usually be the case.10
The key of a technology that must be researched in order to recruit the units, from the
technologies
database table.Returns:
nil
-
cm:add_units_to_province_mercenary_pool_by_region(
region keystring
,
unit keystring
,
countnumber
)
-
Adds one or more of a specified unit to the specified province mercenary pool. The province is specified by a region within it. Unlike with
cm:add_unit_to_province_mercenary_pool
, the unit type must already be represented in the pool.Parameters:
1
Region key of a region within the target province, from the
campaign_map_regions
table.2
Unit key, from the
main_units
table.3
Number of units to add.
Returns:
nil
-
cm:trigger_mission(
faction key
string
,
mission key
string
,
fire immediately
boolean
,
use command queue
[boolean
]
) -
Instructs the campaign director to attempt to trigger a mission of a particular type, based on a mission record from the database. The mission will be triggered if its conditions, defined in the
cdir_events_mission_option_junctions
, pass successfully. The function returns whether the mission was successfully triggered or not. Note that if the command is sent via the command queue thentrue
will always be returned, regardless of whether the mission successfully triggers.Parameters:
1
Faction key, from the
factions
table.2
Mission key, from the
missions
table.3
Set the mission to fire immediately, instead of waiting for the start of the faction's turn. This also overrides any delay set in the mission data.
4
optional, default value=false
Trigger the mission via the command queue or not.
Returns:
mission triggered successfullyboolean
-
cm:trigger_custom_mission(
faction keystring
,
mission keystring
, [
use command queueboolean
])
-
Triggers a specific custom mission from its database record key. This mission must be defined in the missions.txt file that accompanies each campaign.
Parameters:
1
Faction key, from the
factions
table.2
Mission key, from missions.txt file.
3
optional, default value=false
Trigger the mission via the command queue or not.
Returns:
nil
-
cm:trigger_custom_mission_from_string(
faction keystring
,
missionstring
, [
use command queueboolean
])
-
Triggers a custom mission from a string passed into the function. The mission string must be supplied in a custom format - see the missions.txt that commonly accompanies a campaign for examples.
Parameters:
1
Faction key, from the
factions
table.2
Mission definition string.
3
optional, default value=false
Trigger the mission via the command queue or not.
Returns:
nil
-
cm:cancel_custom_mission(
faction keystring
,
mission keystring
, [
use command queueboolean
])
-
Cancels an active custom mission.
Parameters:
1
Faction key, from the
factions
table.2
Mission key, from the
missions
table.3
optional, default value=false
Sends the command via the command queue or not.
Returns:
nil
-
cm:trigger_mission_with_targets(
faction cqi
number
,
mission key
string
,
target faction cqi
number
,
secondary faction cqi
number
,
character cqi
number
,
military force cqi
number
,
region cqi
number
,
settlement cqi
number
) -
Attempts to trigger a mission from database records with one or more target game objects. The game object or objects to associate the mission with are specified by command-queue index. The mission will need to pass any conditions set up in the
cdir_events_mission_option_junctions
table in order to trigger.
A value of0
may be supplied to omit a particular type of target.Parameters:
1
Command-queue index of the faction to which the mission is issued. This must be supplied.
2
Mission key, from the
missions
table.3
Command-queue index of a target faction.
0
may be specified to omit this target (and other target arguments following this one).4
Command-queue index of a second target faction. May be
0
.5
Command-queue index of a target character. May be
0
.6
Command-queue index of a target military force. May be
0
.7
Command-queue index of a target region. May be
0
.8
Command-queue index of a target settlement. May be
0
.Returns:
nil
-
cm:toggle_mission_generation(
can generateboolean
)
-
Sets whether the campaign director system can generate missions or not.
Parameters:
1
can generate
Returns:
nil
Campaign missions may be set up with a mission type of SCRIPTED
. In this case, it is the responsibility of script to manage and complete the mission's objectives. The scripted mission_manager
object provides an interface for the easy creation of missions of this type. The functions listed here are the code functions that the mission manager and other scripts can use to manage scripted missions.
-
cm:set_scripted_mission_text(
mission keystring
,
script keystring
,
text keystring
)
-
Updates the text shown for a particular objective of a specified scripted mission. This can be used to update a representation of mission progress on the panel.
Parameters:
1
Mission key, from the
missions
table.2
Key of the particular scripted objective associated with the mission.
3
Localised text key, in the full [table]_[field]_[key] format.
Returns:
nil
-
cm:set_scripted_mission_position(
mission keystring
,
script keystring
,
xnumber
,
ynumber
)
-
Updates the map position related to a particular objective of a specified scripted mission. This can be used to update a mission's zoom-to target.
Parameters:
1
Mission key, from the
missions
table.2
Key of the particular scripted objective associated with the mission.
3
Logical x co-ordinate of the updated position.
4
Logical y co-ordinate of the updated position.
Returns:
nil
-
cm:complete_scripted_mission_objective(
mission keystring
,
script keystring
,
is successboolean
)
-
Marks a particular objective associated with a specified scripted mission as either succeeded or failed. Once all objectives for a scripted mission are completed, the mission itself is completed.
Parameters:
1
Mission key, from the
missions
table.2
Key of the particular scripted objective associated with the mission.
3
Objective was completed successfully.
Returns:
nil
-
cm:trigger_incident(
faction keystring
,
incident keystring
,
fire immediatelyboolean
)
-
Instructs the campaign director to attempt to trigger a specified incident, based on record from the database. The incident will be triggered if its conditions, defined in the
cdir_events_incident_option_junctions
, pass successfully. The function returns whether the incident was successfully triggered or not.Parameters:
1
Faction key, from the
factions
table.2
Incident key, from the
incidents
table.3
Set the incident to fire immediately.
Returns:
incident was triggeredboolean
-
cm:trigger_custom_incident(
faction key
string
,
incident key
string
,
fire immediately
boolean
,
payload
string
) -
Forces an incident to trigger. A payload string fragment specifying the incident consequences must be supplied.
Parameters:
1
Faction key, from the
factions
table.2
Incident key, from the
dilemmas
table.3
Set the incident to fire immediately.
4
Payload string. Check
missions.txt
for examples of how to structure a payload string.Returns:
nil
Example:
cm:trigger_custom_incident("wh_main_emp_empire", "wh_main_test_incident", true, "payload{money 1000;}");
-
cm:trigger_incident_with_targets(
faction cqi
number
,
incident key
string
,
target faction cqi
string
,
secondary faction cqi
string
,
character cqi
string
,
military force cqi
string
,
region cqi
string
,
settlement cqi
string
) -
Attempts to trigger an incident from database records with one or more target game objects. The game object or objects to associate the incident with are specified by command-queue index. The incident will need to pass any conditions set up in the
cdir_events_incident_option_junctions
table in order to trigger.
A value of0
may be supplied to omit a particular type of target.Parameters:
1
Command-queue index of the faction to which the incident is issued. This must be supplied.
2
Incident key, from the
incidents
table.3
Command-queue index of a target faction.
0
may be specified to omit this target (and other target arguments following this one).4
Command-queue index of a second target faction. May be
0
.5
Command-queue index of a target character. May be
0
.6
Command-queue index of a target military force. May be
0
.7
Command-queue index of a target region. May be
0
.8
Command-queue index of a target settlement. May be
0
.Returns:
nil
-
cm:toggle_incident_generation(
can generateboolean
)
-
Sets whether the campaign director system can generate dilemmas or not.
Parameters:
1
can generate
Returns:
nil
-
cm:trigger_dilemma(string
faction key, string
dilemma key,
fire immediatelyboolean
)
-
Instructs the campaign director to attempt to trigger a dilemma with a particular key, based on dilemma records from the database. The dilemma will be triggered if its conditions, defined in the
cdir_events_dilemma_option_junctions
, pass successfully. The function returns whether the dilemma was successfully triggered or not.Parameters:
1
string
Faction key.
2
string
Dilemma key, from the dilemma table.
3
Set the incident to fire immediately.
Returns:
dilemma was triggeredboolean
-
cm:trigger_custom_dilemma(
faction key
string
,
dilemma key
string
,
first choice payload
string
,
second choice payload
string
) -
Triggers a custom dilemma with two choices, with the specified faction as the dilemma target.
Parameters:
1
Faction key, from the
factions
table.2
Dilemma key, from the
dilemmas
table.3
Payload key for the first choice of the dilemma, from the
cdir_events_dilemma_payloads
table.4
Payload key for the second choice of the dilemma, from the
cdir_events_dilemma_payloads
table.Returns:
nil
-
cm:trigger_custom_dilemma_for_character(
character lookup
string
,
dilemma key
string
,
first choice payload
string
,
second choice payload
string
) -
Triggers a custom dilemma with two choices, with the specified character as the dilemma target.
Parameters:
1
Character lookup string. For more information, see
Character Lookups
.2
Dilemma key, from the
dilemmas
table.3
Payload key for the first choice of the dilemma, from the
cdir_events_dilemma_payloads
table.4
Payload key for the second choice of the dilemma, from the
cdir_events_dilemma_payloads
table.Returns:
nil
-
cm:trigger_dilemma_with_targets(
faction cqi
number
,
dilemma key
string
,
target faction cqi
number
,
secondary faction cqi
number
,
character cqi
number
,
military force cqi
number
,
region cqi
number
,
settlement cqi
number
) -
Attempts to trigger a dilemma from database records with one or more target game objects. The game object or objects to associate the dilemma with are specified by command-queue index. The dilemma will need to pass any conditions set up in the
cdir_events_dilemma_option_junctions
table in order to trigger.
A value of0
may be supplied to omit a particular type of target.Parameters:
1
Command-queue index of the faction to which the dilemma is issued. This must be supplied.
2
Dilemma key, from the
dilemmas
table.3
Command-queue index of a target faction.
0
may be specified to omit this target (and other target arguments following this one).4
Command-queue index of a second target faction. May be
0
.5
Command-queue index of a target character. May be
0
.6
Command-queue index of a target military force. May be
0
.7
Command-queue index of a target region. May be
0
.8
Command-queue index of a target settlement. May be
0
.Returns:
nil
-
cm:toggle_dilemma_generation(
can generateboolean
)
-
Sets whether the campaign director system can generate dilemmas or not.
Parameters:
1
can generate
Returns:
nil
-
cm:trigger_intrigue(
issuing faction
string
,
faction a key
string
,
faction b key
string
,
improve
boolean
,
exempt from cost
boolean
) -
Triggers an intrigue (the High Elf game mechanic) incident which improves or worsens diplomatic relations between two supplied factions.
Parameters:
1
Key of the faction issuing the intrigue, from the
factions
database table.2
Key of the first target faction, from the
factions
database table.3
Key of the second target faction, from the
factions
database table.4
Specifies that the intrigue should improve rather than worsen diplomatic relations between the target factions.
5
Specifies that the intrigue should not cost influence points for issuing faction.
Returns:
nil
-
cm:set_event_generation_enabled(
enableboolean
)
-
Enables or disables random event generation by the campaign director system.
Parameters:
1
enable
Returns:
nil
-
cm:show_message_event(
faction key
string
,
title loc key
string
,
primary loc key
string
,
secondary loc key
string
,
persistent
boolean
,
index
number
) -
Constructs and displays an event message.
Parameters:
1
Key of the faction to whom the event is targeted, from the
factions
table.2
Localisation key for the event title. This should be supplied in the full [table]_[field]_[key] localisation format, or can be a blank string.
3
Localisation key for the primary detail of the event. This should be supplied in the full [table]_[field]_[key] localisation format, or can be a blank string.
4
Localisation key for the secondary detail of the event. This should be supplied in the full [table]_[field]_[key] localisation format, or can be a blank string.
5
Sets this event to be persistent instead of transient. Persistent events are saved to the event history which is accessible to the player.
6
Index indicating the type of event. This can be looked up by first finding a record in
event_feed_message_events
which relates to the event message being shown, then looking up the value in thecampaign_groups
field of this record in thecampaign_group_member_criteria_values
. This will provide one or more possible index values that may be used here.Returns:
nil
-
cm:show_message_event_located(
faction key
string
,
title loc key
string
,
primary loc key
string
,
secondary loc key
string
,
x
number
,
y
number
,
persistent
boolean
,
index
number
) -
Constructs and displays a event message with a zoom-to location.
Parameters:
1
Key of the faction to whom the event is targeted, from the
factions
table.2
Localisation key for the event title. This should be supplied in the full [table]_[field]_[key] localisation format, or can be a blank string.
3
Localisation key for the primary detail of the event. This should be supplied in the full [table]_[field]_[key] localisation format, or can be a blank string.
4
Localisation key for the secondary detail of the event. This should be supplied in the full [table]_[field]_[key] localisation format, or can be a blank string.
5
Logical x co-ordinate of event target.
6
Logical y co-ordinate of event target.
7
Sets this event to be persistent instead of transient. Persistent events are saved to the event history which is accessible to the player.
8
Index indicating the type of event. This can be looked up by first finding a record in
event_feed_message_events
which relates to the event message being shown, then looking up the value in thecampaign_groups
field of this record in thecampaign_group_member_criteria_values
. This will provide one or more possible index values that may be used here.Returns:
nil
-
cm:suppress_all_event_feed_event_types(
activate suppressionboolean
)
-
Activates or deactivates the episodic scripting event feed suppression system. Once activated, event messages of all types will be withheld from triggering until they are either whitelisted with
cm:whitelist_event_feed_event_type
or until suppression is lifted again with a subsequent call to this function. Once one of these two actions occurs, any event messages previously blocked will be triggered.
See also the equivalent UI-side suppression functionCampaignUI.SuppressAllEventTypesInUI
. This function should be used with care, as it can cause softlocks if dilemmas are suppressed. The UI-side functions are generally safer to use.
Message suppression using this system should not be maintained over the end-turn sequence.Parameters:
1
activate suppression
Returns:
nil
-
cm:whitelist_event_feed_event_type(
event typestring
)
-
Whitelists an event type, allowing it to be shown despite suppression being activated with
cm:suppress_all_event_feed_event_types
. Event types are specified by a compound key from theevent_feed_targeted_events
table, by concatenating the values from theevent
andtarget
fields from that table. See the documentation for the ui-side equivalent of this function,CampaignUI.WhiteListEventTypeInUI
, for more information.
This function has no effect if suppression has not been activated withcm:suppress_all_event_feed_event_types
.Parameters:
1
Event type, specified with a compound key from the
event_feed_targeted_events
table.Returns:
nil
-
cm:event_feed_event_type_pending(
event typestring
)
-
Returns whether any event messages of the supplied type are currently being blocked/withheld by event feed suppression. If this function returns
true
for a specified event type, then the withheld event messages may be shown by callingcm:whitelist_event_feed_event_type
to lift the suppression on that event type, or by callingcm:suppress_all_event_feed_event_types
to lift all suppression.Parameters:
1
Event type, specified with a compound key from the
event_feed_targeted_events
table.Returns:
event is currently pendingboolean
-
cm:disable_event_feed_events(
should disable
boolean
,
category
string
,
subcategory
string
,
subcategory
string
) -
Enable or disable event feed events by category, subcategory or event. Any of these types can be empty. This differs from event feed suppression in that messages blocked by this function will be discarded, never to be shown. This function is of most use for temporarily or momentarily blocking certain event messages that the game produces naturally for some reason. This function should be used with care, as it can cause a softlock if a dilemma is triggered while disabled.
Note that the event type lists are independent of one another, so if an event message is blocked by category, this restriction will not be lifted by unblocking by subcategory, for example.Parameters:
1
Disable the event messages specified by the supplied filters. Supply
false
here to re-enable previously disabled event messages.2
Event feed category to block, from the
event_feed_categories
table. Supply a blank string to not filter by category.3
Event feed subcategory to block, from the
event_feed_subcategories
table. Supply a blank string to not filter by subcategory.4
Event feed subcategory to block, from the
event_feed_events
table. Supply a blank string to not filter by event.Returns:
nil
-
cm:region_slot_instantly_dismantle_building(SLOT_SCRIPT_INTERFACE
slot)
-
Instantly dismantle the building in the supplied region slot. The slot is specified by
SLOT_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information.Parameters:
1
SLOT_SCRIPT_INTERFACE
slot
Returns:
nil
-
cm:region_slot_instantly_upgrade_building(SLOT_SCRIPT_INTERFACE
slot,
building keystring
)
-
Instantly upgrade the building in the supplied region slot to the supplied building. The slot is specified by
SLOT_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information. The building specified must be a valid upgrade for the building chain present in the slot.Parameters:
1
SLOT_SCRIPT_INTERFACE
Slot script interface.
2
Building key, from the
building_levels
database table.Returns:
nil
-
cm:region_slot_instantly_repair_building(SLOT_SCRIPT_INTERFACE
slot)
-
Instantly repair the building in the specified slot. Slots are specified by
SLOT_SCRIPT_INTERFACE
, see theModel Hierarchy
documentation for more information.Parameters:
1
SLOT_SCRIPT_INTERFACE
slot
Returns:
nil
-
cm:foreign_slot_instantly_dismantle_building(
foreign slot cqinumber
)
-
Instantly dismantles the building in the specified foreign slot. The slot is specified by slot cqi, which can be obtained from the foreign slot script interface on the model hierarchy.
Parameters:
1
foreign slot cqi
Returns:
nil
-
cm:foreign_slot_instantly_upgrade_building(
foreign slot cqinumber
,
building keystring
)
-
Instantly upgrades the building in the specified foreign slot. The slot is specified by slot cqi, which can be obtained from the foreign slot script interface on the model hierarchy.
Parameters:
1
Foreign slot cqi.
2
Building key, from the
building_levels
table.Returns:
nil
-
cm:remove_faction_foreign_slots_from_region(
faction cqinumber
,
region cqinumber
)
-
Removes the specified foreign slot set from the target region, for the target faction.
Parameters:
1
Command-queue index value of the target faction.
2
Command-queue index value of the target region.
Returns:
nil
-
cm:instant_set_building_health_percent(
region keystring
,
building keystring
,
health percentnumber
)
-
Instantly set the health of a building.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Building level or chain key, from either the
building_levels
orbuilding_chains
tables.3
New health value of building, expressed as a number from 0 to 100.
Returns:
nil
-
cm:override_building_chain_display(
building chain key
string
,
override chain key
string
,
region key
[string
]
) -
Override the display of a building chain so that it appears as another building chain in the ui. A region key may optionally be specified to only override the building chain there. The override building chain must contain the same number of buildings as the chain being overridden.
Parameters:
1
Building chain key, from the
building_chains
table.2
Override building chain key, also from the
building_chains
table.3
optional, default value=nil
Region key, from the
campaign_map_regions
table.Returns:
nil
-
cm:add_building_to_force(
force cqinumber
,
building keystring
,
operation was successfulboolean
)
-
Attempts to add a horde building to a military force. A slot must be available, or the force must contain a building that can be upgraded to the building specified.
Parameters:
1
Military force command-queue index value.
2
Building key, from the
building_levels
table.3
operation was successful
Returns:
nil
-
cm:add_building_to_settlement(
region keystring
,
building keystring
,
operation was successfulboolean
)
-
Attempts to add a building to a settlement. A slot must be available, or the settlement must contain a building that can be upgraded to the building specified.
Parameters:
1
Key of the region containing the target settlement, from the
campaign_map_regions
table.2
Building key, from the
building_levels
table.3
operation was successful
Returns:
nil
-
cm:add_foreign_slot_set_to_region_for_faction(
faction cqinumber
,
region cqinumber
,
slot set keystring
)
-
Adds the specified foreign slot set to the target region, for the target faction. The foreign slot manager of the faction is returned, or a null script interface if parameters are invalid.
Parameters:
1
Command-queue index value of the target faction.
2
Command-queue index value of the target region.
3
Slot set key, from the
slot_sets
table.Returns:
FOREIGN_SLOT_MANAGER_SCRIPT_INTERFACE
foreign slot manager
-
cm:instantly_set_settlement_primary_slot_level()
-
Instantly sets the primary slot level of the supplied settlement. The settlement is specified by
SETTLEMENT_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information. The supplied level Will be clamped to the maximum level of the chain.
The new primary slot building will be returned, as aBUILDING_SCRIPT_INTERFACE
object.Returns:
nil
Effects and effect bundles are the primary method by which campaign systems make gameplay balance modifications. The in-game benefits which technologies, buildings, rites and faction effects, amongst many other examples, are delivered through the activation of effect bundles.
-
cm:apply_effect_bundle(
effect bundle keystring
,
faction keystring
,
turnsnumber
)
-
Apply an effect bundle to a faction for a number of turns, or indefinitely.
Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
Faction key, from the
factions
table.3
Number of turns to apply the effect bundle for.
-1
may be supplied to apply the effect indefinitely.Returns:
nil
-
cm:remove_effect_bundle(
effect bundle keystring
,
faction keystring
)
-
Removes a previously-applied effect bundle from a faction.
Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
Faction key, from the
factions
table.Returns:
nil
-
cm:apply_effect_bundle_to_force(
effect bundle keystring
,
force cqinumber
,
turnsnumber
)
-
Apply an effect bundle to a military force for a number of turns, or indefinitely.
Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
Command-queue index of the military force.
3
Number of turns to apply the effect bundle for.
-1
may be supplied to apply the effect indefinitely.Returns:
nil
-
cm:remove_effect_bundle_from_force(
effect bundle keystring
,
force cqinumber
)
-
Removes a previously-applied effect bundle from a military force.
Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
Command-queue index of the military force.
Returns:
nil
-
cm:apply_effect_bundle_to_characters_force(
effect bundle key
string
,
character cqi
number
,
turns
number
,
command queue
boolean
) -
Apply an effect bundle to a military force for a number of turns, or indefinitely. The military force is specified by its commanding character.
Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
Command-queue index of the character commanding the military force.
3
Number of turns to apply the effect bundle for.
-1
may be supplied to apply the effect indefinitely.4
Send this command via the command queue.
Returns:
nil
-
cm:remove_effect_bundle_from_characters_force(
effect bundle keystring
,
character cqinumber
)
-
Removes a previously-applied effect bundle from a military force, specified by its commanding character.
Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
Command-queue index of the character commanding the military force.
Returns:
nil
-
cm:apply_effect_bundle_to_character(
effect bundle
string
,
character
CHARACTER_SCRIPT_INTERFACE,
turns
number
) -
Applies an effect bundle to a character. The character is specified by
CHARACTER_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information.Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
CHARACTER_SCRIPT_INTERFACE
Target character.
3
Number of turns to apply the effect bundle for.
-1
may be supplied to apply the effect indefinitely.Returns:
nil
-
cm:remove_effect_bundle_from_character(
effect bundlestring
, CHARACTER_SCRIPT_INTERFACE
character)
-
Removes an effect bundle from a character. The character is specified by
CHARACTER_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information.Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
CHARACTER_SCRIPT_INTERFACE
Target character.
Returns:
nil
-
cm:apply_effect_bundle_to_region(
effect bundle keystring
,
region keystring
,
turnsnumber
)
-
Apply an effect bundle to a campaign map region for a number of turns, or indefinitely.
Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
Region key, from the
campaign_map_regions
table.3
Number of turns to apply the effect bundle for.
-1
may be supplied to apply the effect indefinitely.Returns:
nil
-
cm:remove_effect_bundle_from_region(
effect bundle keystring
,
region keystring
)
-
Removes a previously-applied effect bundle from a campaign map region.
Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
Region key, from the
campaign_map_regions
table.Returns:
nil
-
cm:apply_effect_bundle_to_faction_province(
effect bundle
string
,
region
REGION_SCRIPT_INTERFACE,
turns
number
) -
Applies an effect bundle to a province. The province is specified by
REGION_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information. The effect bundle will be applied to the portion of the province owned by the owner of the specified region - this can be the whole province if one faction controls it all.Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
REGION_SCRIPT_INTERFACE
Target region.
3
Number of turns to apply the effect bundle for.
-1
may be supplied to apply the effect indefinitely.Returns:
nil
-
cm:remove_effect_bundle_from_faction_province(
effect bundlestring
, REGION_SCRIPT_INTERFACE
region)
-
Removes an effect bundle from a province. The province is specified by
REGION_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information. The effect bundle will be removed from the portion of the province owned by the owner of the specified region - this can be the whole province if one faction controls it all.Parameters:
1
Effect bundle key, from the
effect_bundles
table.2
REGION_SCRIPT_INTERFACE
Target region.
Returns:
nil
Custom effect bundles may be created, customised, and then applied them to factions, regions, characters etc. While CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
objects may be created and applied using the functions listed here, the interface to customise them is described in the Model Hierarchy
documentation.
-
cm:create_new_custom_effect_bundle(
base effect bundlestring
)
-
Creates a new custom effect bundle, using the specified effect bundle record as a base. The custom effect bundle is returned as a
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information.Parameters:
1
Base effect bundle key, from the
effect_bundles
table.Returns:
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
custom effect bundle
-
cm:apply_custom_effect_bundle_to_region(
custom effect bundle
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE,
region
REGION_SCRIPT_INTERFACE
) -
Applies a custom effect bundle to a region. This replaces any existing effect bundle with the same record.
For more information about theCUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
orREGION_SCRIPT_INTERFACE
interfaces see theModel Hierarchy
documentation.Parameters:
1
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
custom effect bundle
2
REGION_SCRIPT_INTERFACE
region
Returns:
nil
-
cm:apply_custom_effect_bundle_to_faction(
custom effect bundle
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE,
faction
FACTION_SCRIPT_INTERFACE
) -
Applies a custom effect bundle to a faction. This replaces any existing effect bundle with the same record.
For more information about theCUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
orFACTION_SCRIPT_INTERFACE
interfaces see theModel Hierarchy
documentation.Parameters:
1
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
custom effect bundle
2
FACTION_SCRIPT_INTERFACE
faction
Returns:
nil
-
cm:apply_custom_effect_bundle_to_character(
custom effect bundle
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE,
character
CHARACTER_SCRIPT_INTERFACE
) -
Applies a custom effect bundle to a character. This replaces any existing effect bundle with the same record.
For more information about theCUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
orCHARACTER_SCRIPT_INTERFACE
interfaces see theModel Hierarchy
documentation.Parameters:
1
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
custom effect bundle
2
CHARACTER_SCRIPT_INTERFACE
character
Returns:
nil
-
cm:apply_custom_effect_bundle_to_force(
custom effect bundle
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE,
military force
MILITARY_FORCE_SCRIPT_INTERFACE
) -
Applies a custom effect bundle to a military force. This replaces any existing effect bundle with the same record.
For more information about theCUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
orMILITARY_FORCE_SCRIPT_INTERFACE
interfaces see theModel Hierarchy
documentation.Parameters:
1
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
custom effect bundle
2
MILITARY_FORCE_SCRIPT_INTERFACE
military force
Returns:
nil
-
cm:apply_custom_effect_bundle_to_faction_province(
custom effect bundle
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE,
region
REGION_SCRIPT_INTERFACE
) -
Applies a custom effect bundle to a province. This replaces any existing effect bundle with the same record. The effect bundle will be applied to the portion of the province owned by the owner of the specified region - this can be the whole province if one faction controls it all.
For more information about theCUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
orREGION_SCRIPT_INTERFACE
interfaces see theModel Hierarchy
documentation.Parameters:
1
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
custom effect bundle
2
REGION_SCRIPT_INTERFACE
region
Returns:
nil
-
cm:apply_custom_effect_bundle_to_characters_force(
custom effect bundle
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE,
character
CHARACTER_SCRIPT_INTERFACE
) -
Applies a custom effect bundle to a character's military force. This replaces any existing effect bundle with the same record.
For more information about theCUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
orCHARACTER_SCRIPT_INTERFACE
interfaces see theModel Hierarchy
documentation.Parameters:
1
CUSTOM_EFFECT_BUNDLE_SCRIPT_INTERFACE
custom effect bundle
2
CHARACTER_SCRIPT_INTERFACE
character
Returns:
nil
-
cm:force_diplomacy_new(
source faction
string
,
target faction
string
,
bitmask
number
,
can offer
boolean
,
can accept
boolean
) -
Disables or re-enables availability of a set of diplomacy types between factions described in the faction and target specifiers. Specifiers can be
all
,faction:<faction_key>
,subculture:<subculture_key>
orculture:<culture_key>
.
The diplomacy types to be allowed or disallowed are specified with a bitmask. Diplomacy types can be included in the bitmask by adding the number corresponding to the diplomacy type to the mask value. This mapping is shown here:
The function
Diplomacy Type Mask Value
trade agreement 2^0
hard military access 2^1
cancel hard military access 2^2
military alliance 2^3
regions 2^4
technology 2^5
state gift 2^6
payments 2^7
vassal 2^8
peace 2^9
war 2^10
join war 2^11
break trade 2^12
break alliance 2^13
hostages 2^14
marriage 2^15
non aggression pact 2^16
soft military access 2^17
cancel soft military access 2^18
defensive alliance 2^19
client state 2^20
form confederation 2^21
break non aggression pact 2^22
break soft military access 2^23
break defensive alliance 2^24
break vassal 2^25
break client state 2^26
state gift unilateral 2^27
campaign_manager:force_diplomacy
on thecampaign_manager
interface wraps this function, providing a more useable interface and debug output. It's recommended to call that function rather than directly calling this one.Parameters:
1
Specifier that specifies one or more source factions.
2
Specifier that specifies one or more target factions.
3
Bitmask.
4
Sets whether the source faction(s) can to offer deals of this diplomacy type to the target faction(s).
5
Sets whether the target faction(s) can accept deals of this diplomacy type from the source faction(s).
Returns:
nil
-
cm:force_declare_war(
attacking faction key
string
,
target faction key
string
,
invite attacker allies
boolean
,
invite defender allies
boolean
,
use command queue
[boolean
]
) -
Forces one faction to declare war on another.
Parameters:
1
Faction key of the attacking faction, from the
factions
table.2
Faction key of the target faction, from the
factions
table.3
Allows factions allied with the attacker to choose whether to join.
4
Allows factions allied with the defender to choose whether to join.
5
optional, default value=true
Sends the declaration command via the command queue.
Returns:
nil
-
cm:force_make_vassal(
vassalising faction keystring
,
vassal faction keystring
)
-
Force one faction to vassalise another faction.
Parameters:
1
Key of the faction which will become the master, from the
factions
table.2
Key of the faction which will become the vassal, from the
factions
table.Returns:
nil
-
cm:force_alliance(
first faction keystring
,
second faction keystring
,
is military allianceboolean
)
-
Force two factions to become defensive or military allies.
Parameters:
1
Faction key of the first faction, from the
factions
table.2
Faction key of the second faction, from the
factions
table.3
Specifies whether the alliance should be a military alliance. If
false
is supplied then the alliance is defensive.Returns:
nil
-
cm:force_grant_military_access(
granting faction key
string
,
recipient faction key
string
,
is hard access
boolean
) -
Force one faction to grant another faction military access to its territory.
Parameters:
1
Faction key of the granting faction, from the
factions
table.2
Faction key of the recipient faction, from the
factions
table.3
Indicates whether this should be hard military access. This concept is currently unused.
Returns:
nil
-
cm:force_make_peace(
first faction keystring
,
second faction keystring
)
-
Forces peace between two warring factions.
Parameters:
1
Faction key of the first faction, from the
factions
table.2
Faction key of the second faction, from the
factions
table.Returns:
nil
-
cm:force_confederation(
proposing faction keystring
,
target faction keystring
)
-
Forces a proposing faction to subsume a target faction into its confederation.
Parameters:
1
Faction key of the proposing faction, from the
factions
table.2
Faction key of the target faction, from the
factions
table. This faction will be subsumed into the confederation.Returns:
nil
-
cm:force_make_trade_agreement(
first faction keystring
,
second faction keystring
)
-
Forces a trade agreement between two specified factions. If no agreement is possible then nothing will happen.
Parameters:
1
Faction key of the first faction, from the
factions
table.2
Faction key of the second faction, from the
factions
table.Returns:
nil
-
cm:make_diplomacy_available(
first faction keystring
,
second faction keystring
)
-
Makes diplomacy available between two factions, as if they had discovered each other on the campaign map.
Parameters:
1
Faction key of the first faction, from the
factions
table.2
Faction key of the second faction, from the
factions
table.Returns:
nil
-
cm:faction_offers_peace_to_other_faction(
proposing faction keystring
,
target faction keystring
)
-
Compels one faction to offer peace to another faction that it's at war with. The target faction may decline.
Parameters:
1
Faction key of the first faction, from the
factions
table.2
Faction key of the second faction, from the
factions
table.Returns:
nil
-
cm:apply_dilemma_diplomatic_bonus(
faction a keystring
,
faction a keystring
,
bonus valuenumber
)
-
Directly applies a diplomatic bonus or penalty between two factions, as if it had come from a dilemma. The bonus should be an integer between
-6
and+6
, each integer value of which corresponds to a change type (fromPENALTY_XXXLARGE
(-6
) toBONUS_XXXLARGE
(+6
)) which carries a diplomatic attitude modifier that is actually applied.Parameters:
1
First faction key.
2
Second faction key.
3
Bonus value (
-6
to+6
).Returns:
nil
-
cm:add_event_restricted_unit_record(
unit keystring
, [
tooltip keystring
])
-
Adds a restriction preventing a specified unit from being a recruitment option for any faction.
This setting is saved into the campaign save file when the game is saved, and automatically re-established when the campaign is reloaded.Parameters:
1
Unit key, from the
main_units
table.2
optional, default value=nil]
string
tooltip key, Key of localised text in full [table]_[field]_[keyKey of localised text in full [table]_[field]_[key] format to show as a tooltip on the restricted unit icon. This can be omitted.
Returns:
nil
-
cm:remove_event_restricted_unit_record(
unit keystring
)
-
Removes a restriction previously added with
cm:add_event_restricted_unit_record
.Parameters:
1
Unit key, from the
main_units
table.Returns:
nil
-
cm:add_event_restricted_unit_record_for_faction(
unit keystring
,
faction keystring
, [
tooltip keystring
])
-
Adds a restriction preventing a specified unit from being a recruitment option for a specified faction.
This setting is saved into the campaign save file when the game is saved, and automatically re-established when the campaign is reloaded.Parameters:
1
Unit key, from the
main_units
table.2
Faction key, from the
factions
table.3
optional, default value=nil]
string
tooltip key, Key of localised text in full [table]_[field]_[keyKey of localised text in full [table]_[field]_[key] format to show as a tooltip on the restricted unit icon. This can be omitted.
Returns:
nil
-
cm:remove_event_restricted_unit_record_for_faction(
unit keystring
,
faction keystring
)
-
Removes a restriction previously added with
cm:add_event_restricted_unit_record_for_faction
.Parameters:
1
Unit key, from the
main_units
table.2
Faction key, from the
factions
table.Returns:
nil
-
cm:add_event_restricted_building_record(
building keystring
, [
tooltip keystring
])
-
Adds a restriction preventing a specified building from being a construction option for any faction.
This setting is saved into the campaign save file when the game is saved, and automatically re-established when the campaign is reloaded.Parameters:
1
Building key, from the
building_levels
table.2
optional, default value=nil]
string
tooltip key, Key of localised text in full [table]_[field]_[keyKey of localised text in full [table]_[field]_[key] format to show as a tooltip on the restricted building icon. This can be omitted.
Returns:
nil
-
cm:remove_event_restricted_building_record(
building keystring
)
-
Removes a restriction previously added with
cm:add_event_restricted_building_record
.Parameters:
1
Building key, from the
building_levels
table.Returns:
nil
-
cm:add_event_restricted_building_record_for_faction(
building key
string
,
faction key
string
,
tooltip key
[string
]
) -
Adds a restriction preventing a specified building from being a construction option for a specified faction.
This setting is saved into the campaign save file when the game is saved, and automatically re-established when the campaign is reloaded.Parameters:
1
Building key, from the
building_levels
table.2
Faction key, from the
factions
table.3
optional, default value=nil]
string
tooltip key, Key of localised text in full [table]_[field]_[keyKey of localised text in full [table]_[field]_[key] format to show as a tooltip on the restricted building icon. This can be omitted.
Returns:
nil
-
cm:remove_event_restricted_building_record_for_faction(
building keystring
,
faction keystring
)
-
Removes a restriction previously added with
cm:add_event_restricted_building_record_for_faction
.Parameters:
1
Building key, from the
building_levels
table.2
Faction key, from the
factions
table.Returns:
nil
-
cm:lock_technology(
faction keystring
,
technology keystring
)
-
Lock a specified technology and all technologies that are children of it, for a specified faction.
This setting is saved into the campaign save file when the game is saved, and automatically re-established when the campaign is reloaded.Parameters:
1
Faction key, from the
factions
table.2
Technology key, from the
technologies
table.Returns:
nil
-
cm:unlock_technology(
faction keystring
,
technology keystring
)
-
Removes a lock previously placed with
cm:lock_technology
.Parameters:
1
Faction key, from the
factions
table.2
Technology key, from the
technologies
table.Returns:
nil
-
cm:disable_movement_for_character(
character lookupstring
)
-
Prevents the specified character from moving, regardless of where the move order comes from, until movement is subsequently re-enabled with
cm:enable_movement_for_faction
orcm:enable_movement_for_character
.
This setting is saved into the campaign save file when the game is saved, and automatically re-established when the campaign is reloaded.Parameters:
1
Character lookup string - see
Character Lookups
for more information.Returns:
nil
-
cm:disable_movement_for_faction(
faction keystring
)
-
Prevents all characters in the specified faction from moving, regardless of where the move order comes from, until movement is subsequently re-enabled with
cm:enable_movement_for_faction
orcm:enable_movement_for_character
. Note that characters created in the faction after this restriction is applied will not have this restriction applied and will be able to move.
This setting is saved into the campaign save file when the game is saved, and automatically re-established when the campaign is reloaded.Parameters:
1
Faction key, from the
factions
table.Returns:
nil
-
cm:enable_movement_for_character(
character lookupstring
)
-
Re-enables movement for a specified character after it has been disabled with
cm:disable_movement_for_character
orcm:disable_movement_for_faction
.Parameters:
1
Character lookup string - see
Character Lookups
for more information.Returns:
nil
-
cm:enable_movement_for_faction(
faction keystring
)
-
Re-enables movement for every character in the specified faction after it has been disabled with
cm:disable_movement_for_character
orcm:disable_movement_for_faction
.Parameters:
1
Faction key, from the
factions
table.Returns:
nil
-
cm:disable_pathfinding_restriction(
idnumber
)
-
Disables a pathfinding restriction layer. These are layers that can be built into the campaign map data that prevent the player from being able to move into an area on the map. By calling this function to lift a restriction, the player will be able to pathfind into the new area.
Parameters:
1
Pathfinding restriction layer id to un-restrict. Layers are numbered sequentially - lifting the restriction on one layer will also lift it on all layers with a lower numerical id.
Returns:
nil
The functions described in this section affect racial mechanics that are generally specific to one or only a few races in the game. Avoid calling them for factions that aren't party to the racial mechanic in question.
-
cm:modify_faction_slaves_in_a_faction(
faction keystring
,
changenumber
)
-
Modify the number of faction slaves in the specified faction. The change can be positive or negative. This function will only have an affect if the target faction makes use of the slaves mechanic.
Parameters:
1
Faction key, from the
factions
table.2
Value to modify slaves by.
Returns:
nil
-
cm:modify_faction_slaves_in_a_faction_province(
region keystring
,
changenumber
)
-
Modify the number of faction slaves in the province containing a specified region. The change can be positive or negative. This function will only have an affect if the target faction makes use of the slaves mechanic.
Parameters:
1
Region key, from the
campaign_map_regions
table.2
Value to modify slaves by.
Returns:
nil
-
cm:faction_set_food_factor_multiplier(
faction keystring
,
food factor keystring
,
multipliernumber
)
-
Sets the multiplier of a scripted food type for a specified faction. The amount of food of this type this faction will earn per-turn will be multiplied by this amount.
Parameters:
1
Faction key, from the
factions
table.2
Food factor key, from the
food_factors
table.3
Multiplier.
Returns:
nil
-
cm:faction_set_food_factor_value(
faction keystring
,
food factor keystring
,
modifiernumber
)
-
Sets the per-turn modifier of a scripted food type for a specified faction. This is the amount of food of this type this faction will earn per-turn.
Parameters:
1
Faction key, from the
factions
table.2
Food factor key, from the
food_factors
table.3
Modifier.
Returns:
nil
-
cm:faction_mod_food_factor_value(
faction keystring
,
food factor keystring
,
modifiernumber
)
-
Modifies the per-turn modifier of a scripted food type for a specified faction. This is the amount of food of this type this faction will earn per-turn.
The supplied value is added to the existing modifier value.Parameters:
1
Faction key, from the
factions
table.2
Food factor key, from the
food_factors
table.3
Modifier.
Returns:
nil
-
cm:faction_add_pooled_resource(
faction keystring
,
resource keystring
,
factor keystring
,
amountnumber
)
-
Add the specified amount to the specified resource pool (type of resource), as the specified factor (type of change). The supplied value will be clamped to pool and factor bounds.
Parameters:
1
Faction key, from the
factions
table.2
Pooled resource key, from the
pooled_resources
table.3
Change factor key, from the
pooled_resource_factors
table.4
Amount of resource to add. This value can be negative.
Returns:
nil
-
cm:perform_ritual(
performing faction keystring
,
target faction keystring
,
ritual keystring
)
-
Perform a ritual for a faction. The ritual must be available and valid for the action to succeed.
Parameters:
1
Faction key of the faction performing the ritual, from the
factions
table.2
Faction key of the target faction of the ritual, from the
factions
table. An emptystring
may be supplied, in which case the performing faction is the target.3
Ritual key, from the
rituals
table.Returns:
nil
-
cm:create_new_ritual_setup(FACTION_SCRIPT_INTERFACE
performing faction,
ritual keystring
)
-
Creates and returns a new MODIFY_RITUAL_SETUP_SCRIPT_INTERFACE, related to a ritual record from the database. This can be then be used to query, modify and trigger a ritual in script.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction to perform the ritual.
2
Ritual key, from the
rituals
table.Returns:
nil
-
cm:perform_ritual_with_setup(RITUAL_SETUP_SCRIPT_INTERFACE
interface ritual setup)
-
Perform a ritual with the provided setup. It must be available and valid for this call to succeed. Both modify and standard ritual setup interfaces are valid for this method
Parameters:
1
RITUAL_SETUP_SCRIPT_INTERFACE
Ritual setup to use. This can be either a RITUAL_SETUP_SCRIPT_INTERFACE or a MODIFY_RITUAL_SETUP_SCRIPT_INTERFACE object.
Returns:
nil
-
cm:rollback_linked_ritual_chain(
ritual chain keystring
, number
stage)
-
Rolls back a linked ritual chain to the specified stage. It is safe to call this function if the ritual chain isn't at this stage yet.
Parameters:
1
Ritual chain key, from the
campaign_group_ritual_chains
table.2
number
Stage number.
Returns:
nil
-
cm:lock_ritual(FACTION_SCRIPT_INTERFACE
faction,
ritual keystring
)
-
Lock a ritual for a faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Target faction.
2
Ritual key, from the
rituals
table.Returns:
nil
-
cm:unlock_ritual(FACTION_SCRIPT_INTERFACE
faction,
ritual keystring
,
durationnumber
)
-
Unlock a ritual for a faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Target faction.
2
Ritual key, from the
rituals
table.3
Duration, number of rounds the ritual will be unlocked for. Zero or negative will be infinite.
Returns:
nil
-
cm:lock_ritual_chain(FACTION_SCRIPT_INTERFACE
faction,
ritual_chain_keystring
)
-
Lock a ritual chain for a faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Target faction.
2
Ritual chain key, from the
ritual_chains
table.Returns:
nil
-
cm:unlock_ritual_chain(FACTION_SCRIPT_INTERFACE
faction,
ritual chain keystring
,
durationnumber
)
-
Unlock a ritual chain for a faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Target faction.
2
Ritual Chain key, from the
ritual_chains
table.3
Duration, number of rounds the ritual chain will be unlocked for. Zero or negative will be infinite.
Returns:
nil
-
cm:lock_rituals_in_category(FACTION_SCRIPT_INTERFACE
faction,
ritual_category_keystring
)
-
Lock all rituals in a category for a faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Target faction.
2
Ritual category key, from the
ritual_categories
table.Returns:
nil
-
cm:unlock_rituals_in_category(
faction
FACTION_SCRIPT_INTERFACE,
ritual_category_key
string
,
duration
number
) -
Unlocks all rituals in a category for a faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Target faction.
2
Ritual category key, from the
ritual_categories
table.3
Duration, number of rounds the rituals in the category will be unlocked for. Zero or negative will be infinite.
Returns:
nil
-
cm:apply_active_ritual(FACTION_SCRIPT_INTERFACE
faction, ACTIVE_RITUAL_SCRIPT_INTERFACE
ritual)
-
Applies the effect of a ritual that is active right now. This is used in conjunction with the
delay_payload_application
field of therituals
database table. Should this field be set for a ritual, then that ritual will not apply its payload effects when triggered until this function orcm:apply_active_rituals
is called.
Calls to this function will not succeed if the ritual has not been actively triggered.Parameters:
1
FACTION_SCRIPT_INTERFACE
Target faction.
2
ACTIVE_RITUAL_SCRIPT_INTERFACE
Target ritual.
Returns:
nil
-
cm:apply_active_rituals(FACTION_SCRIPT_INTERFACE
faction)
-
Applies the effect of all rituals that are active for a faction right now. This is used in conjunction with the
delay_payload_application
field of therituals
database table. Should this field be set for a ritual, then that ritual will not apply its payload effects when triggered until this function orcm:apply_active_ritual
is called.
Calls to this function will not succeed if the ritual has not been actively triggered.Parameters:
1
FACTION_SCRIPT_INTERFACE
Target faction.
Returns:
nil
-
cm:spawn_plague_at_settlement(SETTLEMENT_SCRIPT_INTERFACE
settlement,
plague keystring
)
-
Spawn a plague at a settlement.
Parameters:
1
SETTLEMENT_SCRIPT_INTERFACE
Target settlement.
2
Plague key, from the
plagues
table.Returns:
nil
-
cm:spawn_plague_at_region(REGION_SCRIPT_INTERFACE
region,
plague keystring
)
-
Spawn a plague in a region.
Parameters:
1
REGION_SCRIPT_INTERFACE
Target region.
2
Plague key, from the
plagues
table.Returns:
nil
-
cm:spawn_plague_at_military_force(MILITARY_FORCE_SCRIPT_INTERFACE
military force,
plague keystring
)
-
Spawn a plague at a military force.
Parameters:
1
MILITARY_FORCE_SCRIPT_INTERFACE
Target military force.
2
Plague key, from the
plagues
table.Returns:
nil
-
cm:faction_set_unit_purchasable_effect_availability(
faction key
string
,
purchasable effect key
string
,
available
boolean
) -
Sets a unit purchasable effect to be available or unavailable for a specified faction. Unit purchasable effects are upgrades for units, which is supported for some factions/races.
Parameters:
1
Key of the target faction, from the
factions
database table.2
Key of the purchasable effect, from the
unit_purchasable_effects
database table.3
Sets whether the purchasable effect should be available or not.
Returns:
nil
-
cm:faction_purchase_unit_effect(
faction
FACTION_SCRIPT_INTERFACE,
unit
UNIT_SCRIPT_INTERFACE,
purchasable effect
UNIT_PURCHASABLE_EFFECT_SCRIPT_INTERFACE
) -
Makes the supplied faction purchase a supplied effect for a supplied unit. All arguments are specified by model hierarchy objects - see the
Model Hierarchy
documentation for more information.Parameters:
1
FACTION_SCRIPT_INTERFACE
faction
2
UNIT_SCRIPT_INTERFACE
unit
3
UNIT_PURCHASABLE_EFFECT_SCRIPT_INTERFACE
purchasable effect
Returns:
nil
-
cm:faction_set_unit_purchasable_effect_lock_state(
faction
FACTION_SCRIPT_INTERFACE,
purchasable effect
string
,
lock reason
string
,
should lock
boolean
) -
Locks or unlocks the purchasable unit effect faction-wide, with an optional lock reason record. The purchasable effect is specified by string key. The faction is specified by
FACTION_SCRIPT_INTERFACE
- see theModel Hierarchy
documentation for more information.Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object.
2
Unit purchasable effect. This should be a key from the
unit_purchasable_effects
database table.3
Lock reason. This should be a key from the
unit_purchasable_effect_lock_reasons
database table. A blank string may be supplied to not provide a lock reason.4
Should lock - supply
true
to lock the effect, andfalse
to unlock it.Returns:
nil
-
cm:faction_imprison_character(
imprisoning faction
FACTION_SCRIPT_INTERFACE,
imprisoned character
CHARACTER_SCRIPT_INTERFACE
) -
Puts the supplied character into the supplied faction's prison. The faction and character are specified by model hierarchy objects - see the
Model Hierarchy
documentation for more information.Parameters:
1
FACTION_SCRIPT_INTERFACE
imprisoning faction
2
CHARACTER_SCRIPT_INTERFACE
imprisoned character
Returns:
nil
-
cm:faction_perform_action_on_prisoner(
faction
FACTION_SCRIPT_INTERFACE,
character
FAMILY_MEMBER_SCRIPT_INTERFACE,
action
string
) -
Performs an action on a character within the faction's prison. The faction and character (family member) are specified by model hierarchy objects - see the
Model Hierarchy
documentation for more information.Parameters:
1
FACTION_SCRIPT_INTERFACE
Imprisoning faction.
2
FAMILY_MEMBER_SCRIPT_INTERFACE
Imprisoned character - this is specified as a family member.
3
Action to perform. This should be a key from the
campaign_prison_actions
database table.Returns:
nil
-
cm:cook_recipe(FACTION_SCRIPT_INTERFACE
faction,
recipestring
)
-
Attempt to cook a recipe for a faction. The default ingredients will be used.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.2
Recipe to cook. This should be a key from the
cooking_recipes
database table.Returns:
attempt was successfulboolean
-
cm:cook_recipe_with_ingredients(
faction
FACTION_SCRIPT_INTERFACE,
recipe
string
,
primary ingredients
table
,
secondary ingredients
table
) -
Attempt to cook a recipe for a faction with the specified ingredients. The ingredients lists should be specified as tables of strings.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.2
Recipe to cook. This should be a key from the
cooking_recipes
database table.3
Table containing a list of
string
values. Each should be a key from thecooking_ingredients
database table.4
Table containing a list of
string
values. Each should be a key from thecooking_ingredients
database table.Returns:
attempt was successfulboolean
-
cm:force_cook_recipe(FACTION_SCRIPT_INTERFACE
faction,
recipestring
,
apply costboolean
)
-
Force a recipe to be cooked for a faction. The default ingredients will be used.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.2
Recipe to cook. This should be a key from the
cooking_recipes
database table.3
Apply the recipe cost.
Returns:
attempt was successfulboolean
-
cm:force_cook_recipe_with_ingredients(
faction
FACTION_SCRIPT_INTERFACE,
recipe
string
,
primary ingredients
table
,
secondary ingredients
table
,
apply cost
boolean
) -
Force a recipe to be cooked for a faction with the specified ingredients. The ingredients lists should be specified as tables of strings.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.2
Recipe to cook. This should be a key from the
cooking_recipes
database table.3
Table containing a list of
string
values. Each should be a key from thecooking_ingredients
database table.4
Table containing a list of
string
values. Each should be a key from thecooking_ingredients
database table.5
Apply the recipe cost.
Returns:
attempt was successfulboolean
-
cm:unlock_cooking_ingredient(FACTION_SCRIPT_INTERFACE
faction,
ingredientstring
)
-
Unlock an ingredient for a faction. The ingredient must be permitted for the faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.2
Ingredient key, from the
cooking_ingredients
database table.Returns:
nil
-
cm:unlock_cooking_recipe(FACTION_SCRIPT_INTERFACE
faction,
recipestring
)
-
Unlock a cooking recipe for a faction. The recipe must be permitted for the faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.2
Recipe key, from the
cooking_recipes
database table.Returns:
nil
-
cm:clear_active_cooking_recipe(FACTION_SCRIPT_INTERFACE
faction)
-
Clears the active recipe for the specified faction.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.Returns:
recipe was clearedboolean
-
cm:set_faction_max_primary_cooking_ingredients(FACTION_SCRIPT_INTERFACE
faction,
max ingredientsnumber
)
-
Sets the maximum number of primary ingredients that the specified faction may cook with. This value is clamped between 0 and 10.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.2
Maximum number of ingredients.
Returns:
nil
-
cm:set_faction_max_secondary_cooking_ingredients(
faction
FACTION_SCRIPT_INTERFACE,
max ingredients
number
) -
Sets the maximum number of secondary ingredients that the specified faction may cook with. This value is clamped between 0 and 10.
Parameters:
1
FACTION_SCRIPT_INTERFACE
Faction object - see the
Model Hierarchy
documentation for more information.2
Maximum number of ingredients.
Returns:
nil
-
cm:add_custom_battlefield(
id
string
,
x
number
,
y
number
,
radius
number
,
dump campaign
boolean
,
loading screen override
string
,
script override
string
,
whole battle override
string
,
human alliance
number
,
launch immediately
boolean
,
is land battle
boolean
,
force autoresolve result
boolean
) -
Adds a record which modifies or completely overrides a battle involving the local player generated from campaign, if that battle happens within a certain supplied radius of a supplied campaign anchor position. Aspects of the battle may be specified, such as the loading screen and script to use, or the entire battle may be subsituted with an xml battle.
Parameters:
1
Id for this custom battle record. This may be used to later remove this override with
cm:remove_custom_battlefield
.2
X logical co-ordinate of anchor position.
3
Y logical co-ordinate of anchor position.
4
Radius around anchor position. If a battle is launched within this radius of the anchor position and it involves the local player, then the battle is modified/overridden.
5
If set to
true
, the battle makes no attempt to load back into this campaign after completion.6
Key of a custom loading screen to use, from the
custom_loading_screens
table. A blank string may be supplied to not override the loading screen. This is ignored if the entire battle is overriden with a battle xml, as that may specify a loading screen override.7
Path to a script file to load with the battle, from the working data folder. A blank string may be supplied to not override the loading screen. This is ignored if the entire battle is overriden with a battle xml, as that may specify a script override.
8
Path to an battle xml file which overrides the whole battle.
9
Sets the index of the human alliance, 0 or 1, if setting a battle xml to override the whole battle. If not setting a battle xml this number is ignored.
10
Launch the battle immediately without saving the campaign first.
11
Sets whether the following battle is a land battle. This is only required if when launching the battle immediately.
12
If set to
true
, this forces the application of the autoresolver to the battle result after the battle, regardless of what happened in the battle itself. This is of most use for faking a battle result of an xml battle, which would otherwise return with no result.Returns:
nil
-
cm:remove_custom_battlefield(
idstring
)
-
Removes a custom battle override previously set with
cm:add_custom_battlefield
.Parameters:
1
id
Returns:
nil
-
cm:win_next_autoresolve_battle(
faction keystring
)
-
The specified faction will win the next autoresolve battle.
Parameters:
1
Faction key, from the
factions
table.Returns:
nil
-
cm:modify_next_autoresolve_battle(
attacker win chance
number
,
defender win chance
number
,
attacker losses modifier
number
,
defender losses modifier
number
,
kill loser
boolean
) -
Modifies the result of the next autoresolved battle.
Parameters:
1
Attacker win chance as a unary (0-1) value.
2
Defender win chance as a unary (0-1) value.
3
Multiplier for losses sustained by the attacker.
4
Multiplier for losses sustained by the defender.
5
Forces the loser of the battle to be wiped out if set to
true
.Returns:
nil
-
cm:skip_winds_of_magic_gambler(
should skipboolean
)
-
Sets whether the winds of magic gambler panel should be shown in the next player battle or not. The setting only affects the next battle.
Parameters:
1
should skip
Returns:
nil
-
cm:override_attacker_win_chance_prediction(
chancenumber
)
-
Set the attackers predicted win chance percentage for the next battle, affecting the balance of power shown on the pre-battle screen. This will not change the result.
This function will only work if called while the pending battle is being set up.Parameters:
1
Chance as a percentage, so a value of
50
would display a 50/50 attacker/defender balance.Returns:
nil
-
cm:pending_battle_add_scripted_tile_upgrade_tag(
tile upgrade keystring
)
-
Adds the specified tile upgrade to the currently active pending battle. This should match the key of a tile upgrade set within the map data of the tile the battle will be fought on, so its use is highly situational.
The function will only work if called while the pending battle is being set up.Parameters:
1
tile upgrade key
Returns:
upgrade was successfulboolean
-
cm:pending_battle_remove_scripted_tile_upgrade_tags(
tile upgrade keystring
)
-
Removes the specified tile upgrade from the currently active pending battle. The function will only work if called while the pending battle is being set up.
Parameters:
1
tile upgrade key
Returns:
upgrade was successfulboolean
The functions in this section relate to campaign AI. Some functions allow blocking or promotion of strategic stances, which is a driver of how much an AI faction is predisposed to like another faction. Strategic stances may be specified by one of the following strings:
Stance by string |
---|
CAI_STRATEGIC_STANCE_BEST_FRIENDS |
Strategic stances are different to, but loosely correlated with, the attitude score that is shown on the diplomacy screen. Generally speaking, diplomatic events (e.g. gifts, trespassing) lead to changes in attitude, which leads to changes in strategic stance, which leads to changes in behaviour. By setting two hostile factions to be best friends they will start being generally nicer to one another while still appearing to be hostile (although their attitude will likely improve over time due to positive events).
-
cm:force_change_cai_faction_personality(
faction keystring
,
personality keystring
)
-
Force the specified faction to adopt the specified AI personality.
Parameters:
1
Faction key, from the
factions
table.2
Personality key, from the
cai_personalities
table.Returns:
nil
-
cm:cai_strategic_stance_manager_block_all_stances_but_that_specified_towards_target_faction(
faction key
string
,
target faction key
string
,
strategic stance key
string
) -
Sets one faction's stance towards another to the supplied strategic stance.
Parameters:
1
Faction key, from the
factions
table.2
Target faction key, from the
factions
table.3
Strategic stance key - see the list at the top of this section.
Returns:
nil
-
cm:cai_strategic_stance_manager_promote_specified_stance_towards_target_faction(
faction key
string
,
target faction key
string
,
strategic stance key
string
) -
Makes it much more likely that one faction's stance towards another will be the supplied strategic stance.
Parameters:
1
Faction key, from the
factions
table.2
Target faction key, from the
factions
table.3
Strategic stance key - see the list at the top of this section.
Returns:
nil
-
cm:cai_force_personality_change(
faction keystring
)
-
Forces the specified faction to pick a new AI personality from their available pool. "All" may be supplied in place of a faction key to force all factions to change personalities.
Parameters:
1
Faction key, from the
factions
table, or "all".Returns:
nil
-
cm:cai_force_personality_change_with_override_round_number(
faction keystring
,
round numbernumber
)
-
Within the ai personality assignment system it is possible to set up weightings between rounds and personalities, allowing for certain personalities to be more or less likely to be chosen depending on the turn number (so the AI changes behaviour over time). This command forces the specified faction to pick a new AI personality from their available pool, based on the supplied round number rather than the actual round number. "All" may be supplied in place of a faction key to force all factions to change personalities in this way.
Parameters:
1
Faction key, from the
factions
table, or "all".2
Override for turn/round number.
Returns:
nil
-
cm:cai_strategic_stance_manager_force_stance_update_between_factions(
faction key
string
,
target faction key
string
) -
Forces a stance update from one faction to another faction. The AI picks an appropriate new strategic stance.
Parameters:
1
Faction key, from the
factions
table.2
Target faction key, from the
factions
table.Returns:
nil
-
cm:cai_strategic_stance_manager_set_stance_promotion_between_factions_for_a_given_stance(
faction key
string
,
target faction key
string
,
strategic stance key
string
,
start round
number
,
start level
number
,
end round
number
,
end level
number
) -
Sets up a process which promotes a particular strategic stance from one faction to a target faction over a number of turns.
Parameters:
1
Faction key, from the
factions
table.2
Target faction key, from the
factions
table.3
Strategic stance key - see the list at the top of this section.
4
Starting round number.
5
Starting stance level. This is a numerical indicator of how likely this stance is to be chosen.
6
End round number.
7
End stance level. This is a numerical indicator of how likely this stance is to be chosen.
Returns:
nil
-
cm:cai_strategic_stance_manager_clear_all_promotions_between_factions(
faction key
string
,
target faction key
string
) -
Clears any existing scripted stance promotions from one faction to a target faction.
Parameters:
1
Faction key, from the
factions
table.2
Target faction key, from the
factions
table.Returns:
nil
-
cm:cai_strategic_stance_manager_set_stance_blocking_between_factions_for_a_given_stance(
faction key
string
,
target faction key
string
,
strategic stance key
string
,
round number
number
) -
Blocks a specific strategic stance from one faction to another faction until a specified round number.
Parameters:
1
Faction key, from the
factions
table.2
Target faction key, from the
factions
table.3
Strategic stance key - see the list at the top of this section.
4
Final round number (inclusive) of blocking behaviour.
Returns:
nil
-
cm:cai_strategic_stance_manager_clear_all_blocking_between_factions(
faction key
string
,
target faction key
string
) -
Clears any existing scripted stance promotions between one faction and a target.
Parameters:
1
Faction key, from the
factions
table.2
Target faction key, from the
factions
table.Returns:
nil
-
cm:cai_disable_movement_for_character(
character lookupstring
)
-
Prevents the AI from being able to move a character. Other sources of character movement (e.g. the script or the player) will work as normal.
Parameters:
1
Character lookup string - see
Character Lookups
for more information.Returns:
nil
-
cm:cai_enable_movement_for_character(
character lookupstring
)
-
Allows the AI to move a character again after it was previously blocked with
cm:cai_disable_movement_for_character
.Parameters:
1
Character lookup string - see
Character Lookups
for more information.Returns:
nil
-
cm:cai_disable_movement_for_faction(
faction keystring
)
-
Prevents the AI from being able to move any characters in a faction. Other sources of character movement (e.g. the script or the player) will work as normal.
Parameters:
1
Faction key, from the
factions
table.Returns:
nil
-
cm:cai_enable_movement_for_faction(
faction keystring
)
-
Allows the AI to move characters in a faction again after it was previously blocked with
cm:cai_disable_movement_for_faction
.Parameters:
1
Faction key, from the
factions
table.Returns:
nil
-
cm:cai_disable_command_assignment_for_character(
character lookupstring
)
-
Prevents the AI from assigning the specified character to a position of command.
Parameters:
1
Character lookup string - see
Character Lookups
for more information.Returns:
nil
-
cm:cai_enable_command_assignment_for_character(
character lookupstring
)
-
Allows the AI to assigning the specified character to a position of command again after it was previously blocked with
cm:cai_disable_command_assignment_for_character
.Parameters:
1
Character lookup string - see
Character Lookups
for more information.Returns:
nil
-
cm:cai_disable_targeting_against_settlement(
settlement keystring
)
-
Prevents any AI faction from targeting a specified settlement for capture for the rest of the campaign. This setting can be later cleared with
cm:cai_enable_targeting_against_settlement
.Parameters:
1
Settlement key, from the
campaign_map_settlements
database table. This will besettlement:
followed by the region key.Returns:
nil
-
cm:cai_enable_targeting_against_settlement(
settlement keystring
)
-
Clears any restriction previously set with
cm:cai_disable_targeting_against_settlement
, allowing AI factions to target a specified settlement for capture again.Parameters:
1
Settlement key, from the
campaign_map_settlements
database table. This will besettlement:
followed by the region key.Returns:
nil