Effect
The effect object is created automatically by code whenever a script environment is set up. It is mostly used to provide functionality that can be useful in all environments (campaign, battle and frontend). It does not need to be created by script, and the functions it provides may be called directly on the object in the following form.
Example:
effect.<function_name>(<args>)
Loaded in Battle | |
Loaded in Campaign | |
Loaded in Frontend |
The following function calls are available in a campaign script environment. They will not work in other environments.
-
effect.ancillary(
ancillary keystring
,
chancenumber
,
contextuserdata
)
-
Potentially adds the supplied ancillary to the character in the supplied context. When called, the function generates a random number between 0-100, and if this number is less than or equal to the supplied chance value, then the ancillary is added. The character to add the ancillary to is specified in the supplied context object, which must be a context object created by a character event (e.g. CharacterCompletedBattle, CharacterCreated).
This function is somewhat archaic and should only be used in exported ancillary scripts. For general script usageforce_add_ancillary
is greatly preferred.Parameters:
1
Ancillary key, from the
ancillaries
table.2
Percentage chance that the ancillary will actually be added.
3
Context object, provided by a character event.
Returns:
nil
-
effect.trait(
trait keystring
,
applicable tostring
,
pointsnumber
,
chancenumber
,
contextuserdata
)
-
Potentially adds the supplied trait points to the trait-recipient in the supplied context. When called, the function generates a random number between 0-100, and if this number is less than or equal to the supplied chance value then the trait points are added. The trait recipient is specified in the supplied context object, and the type of recipient must also be specified by a supplied string.
This function is somewhat archaic and should only be used in exported trait scripts. For adding traits to characters in general scriptsforce_add_trait
is greatly preferred.Parameters:
1
Trait key, from the
traits
table.2
Specifies the type of object to apply the trait to. Valid strings here are
agent
(for all characters),region
andunit
. Not all recipient types may currently be supported.3
Number of trait points to add, if successful.
4
Percentage chance that the trait will actually be added.
5
Context object, provided by an event.
Returns:
nil
-
effect.OpenBrowser(
encyclopedia urlstring
,
contextuserdata
)
-
Opens the in-game web browser with the supplied encyclopedia url.
Parameters:
1
encyclopedia url
2
Context object, provided by an event.
Returns:
nil
Example:
effect.OpenBrowser("how_to_play/045b_enc_manual_ui_character.html", context)
-
effect.suspend_contextual_advice(
should suspendboolean
)
-
Prevents advice from being triggered with
effect.advance_contextual_advice_thread
. This can be useful for tutorials, but is not used by modern advice systems.Parameters:
1
should suspend
Returns:
nil
-
effect.advice(
textstring
)
-
Directs the advisor to display the supplied advice string. This should only be used for debugging since localisation is bypassed.
Parameters:
1
text
Returns:
nil
-
effect.advance_scripted_advice_thread(
advice keystring
,
score increasenumber
)
-
Directs the advisor to advance the specified thread by the supplied score increase. If any advice on that thread subsequently becomes eligible to be issued, then that advice is issued.
Parameters:
1
Advice key, from the
advice_threads
table.2
Score to increase the advice thread by.
Returns:
nil
-
effect.advance_scripted_advice_thread_located(
advice keystring
,
score increasenumber
,
xnumber
,
ynumber
)
-
Parameters:
1
Advice key, from the
advice_threads
table.2
Score to increase the advice thread by.
3
X display co-ordinate to associate the advice with.
4
Y display co-ordinate to associate the advice with.
Returns:
nil
-
effect.get_advice_thread_score(
thread keystring
)
-
Returns the advice thread score. This can indicate whether advice on this thread has already been played.
Parameters:
1
Advice thread key, from the
advice_threads
table.Returns:
scorenumber
-
effect.increment_advice_thread_score(
thread keystring
,
scorenumber
)
-
Increments the advice thread score by the supplied amount, without playing any advice.
Parameters:
1
Advice thread key, from the
advice_threads
table.2
score
Returns:
nil
-
effect.set_advice_history_string_seen(
keystring
)
-
Stores a key in the advice history, which can subsequently be tested with
effect.get_advice_history_string_seen
. This allows scripts to test whether the player has ever encountered certain conditions in their playing history (e.g. "has ever started game"). The flag will be reset if the player resets their advice history.Parameters:
1
key
Returns:
nil
-
effect.get_advice_history_string_seen(
keystring
)
-
Returns whether a key has ever been set in the advice history with
effect.set_advice_history_string_seen
.Parameters:
1
key
Returns:
has been setboolean
-
effect.get_advice_level()
-
Returns the current advice level setting. The following table indicates potential returned values:
Returned Value Advice Level
0
Minimal 1
Low 2
High Returns:
advice levelnumber
-
effect.clear_advice_session_history()
-
Clears out the advice session history. This is the list of advice shown in this particular game session, accessed by the next/previous buttons on the advisor panel.
Returns:
nil
-
effect.advance_contextual_advice_thread(
advice threadstring
,
pointsnumber
,
contextuserdata
)
-
Directs the advisor to consider issuing advice on the supplied advice thread. The supplied number of points are added to the thread - if a record from the
advice_levels
table subsequently becomes eligible to be issued, then that advice is issued.Parameters:
1
Advice thread key.
2
Points to add to thread.
3
context object supplied by game event.
Returns:
nil
-
effect.is_advice_audio_playing()
-
Returns whether audio for any advice is currently playing.
Returns:
advice is playingboolean
-
effect.trigger_shortcut(
shortcut namestring
)
-
Triggers a keyboard shortcut event. Valid shortcut events are defined in
data\text\default_keys.xml
.Parameters:
1
shortcut name
Returns:
nil
-
effect.key_press(
eventstring
)
-
Simulates a key down followed by a key up key event. Valid key events are listed here:
Simulating Keyboard Events
Parameters:
1
event
Returns:
nil
-
effect.key_down(
eventstring
)
-
Triggers a key down key event. Note that the game will think the key is held down until a key up event is received. Valid key events are listed here:
Simulating Keyboard Events
Parameters:
1
event
Returns:
nil
-
effect.key_up(
eventstring
)
-
Triggers a key up event. Valid key events are listed here:
Simulating Keyboard Events
.Parameters:
1
event
Returns:
nil
-
effect.pref_as_bool(
preference keystring
)
-
Returns whether the specified boolean user preference setting is true or not.
Parameters:
1
preference key
Returns:
preference valueboolean
-
effect.pref_as_float(
preference keystring
)
-
Returns the numeric value of the specified floating point user preference. Floating point number values will be marked with <float> in the preferences file.
Parameters:
1
preference key
Returns:
preference valuenumber
-
effect.pref_as_integer(
preference keystring
)
-
Returns the numeric value of the specified integer user preference. Integer values will be marked with <int> in the preferences file.
Parameters:
1
preference key
Returns:
preference valuenumber
-
effect.tweaker_value(
tweaker namestring
)
-
Returns the value of the specified tweaker as a string. Tweakers are game settings that may be easily set and changed during development, through methods such as startup scripts or the game console.
Parameters:
1
tweaker name
Returns:
tweaker valuestring
-
effect.game_version()
-
Returns the game version string.
Returns:
game versionstring
-
effect.filesystem_lookup(
pathstring
,
patternstring
)
-
Performs a VFS lookup in the specified relative path (root is data/) for files matching the supplied pattern. Returns a comma-delimited list of files found.
Parameters:
1
Path from data/ in which to look.
2
Search pattern.
Returns:
file liststring
Example:
effect.filesystem_lookup("/script/_lib/", "*.lua")
-
effect.take_screenshot(
filenamestring
)
-
Triggers a screenshot
Parameters:
1
filename
Returns:
nil
-
effect.get_appdata_screenshots_path()
-
Returns the full path to the screenshots directory in appdata.
Returns:
screenshots pathstring
-
effect.PingIconPath(
ping typenumber
)
-
Returns the icon path for the supplied ping icon type, specified by a numeric index. This allows script to create its own pings that don't go through the ping system (like ping icons attached to units - see
script_unit:add_ping_icon
). This function works in battle only.Parameters:
1
ping type
Returns:
icon pathstring
-
effect.get_skinned_image_path(
image namestring
)
-
Retrieves a full image path from the working data folder for a supplied image name that obeys the currently loaded skins. For each loaded skin, the existence of the image is queried and, should it exist, the path to that image is returned. If the image is not found then a path to the image in the default skin folder is returned, although in this case the existence of the image is not checked for. The returned image path can subsequently be supplied to
uicomponent:SetImagePath
.Parameters:
1
Image name, excluding path but including file extension.
Returns:
image pathstring
-
effect.get_localised_string(
localisation keystring
)
-
Retrieves a localised string from the database by its full localisation key. This is in the form [table]_[field]_[record_key]. If the lookup fails, an empty string is returned.
Parameters:
1
localisation key
Returns:
localised stringstring
Example:
out(effect.get_localised_string("random_localisation_strings_string_shakespeare_quote"))
Alas, Poor Yoric..
-
effect.subtitles_enabled()
-
Returns whether subtitles are enabled or not in the player's preferences.
Returns:
subtitles enabledboolean
-
effect.is_any_movie_playing()
-
Returns whether any movie is currently playing.
Returns:
is movie playingboolean
-
effect.stop_all_movies()
-
Stops any currently playing movies.
Returns:
nil
-
effect.set_custom_loading_screen_key(
keystring
)
-
Sets a record from the
custom_loading_screens
table to use for the next loading screen. The record is specified by string key.Parameters:
1
key
Returns:
nil
-
effect.set_context_value(
idstring
,
valuenumber
/string
)
-
Creates or updates a CcoScriptObject data record within the UI context system with a specified value. UI components and layouts can be separately set up to query these values by name. This allows script to set up and modify values which are then reflected in the UI, giving script great power to set up custom gameplay structures which are visible to the player on the UI. Examples might include health bars, counters, progress meters etc which are tied to arbitrary scripted values.
Parameters:
1
Context value id.
2
Returns:
nil
-
effect.get_context_bool_value(
object idstring
,
function idstring
)
-
Calls a specified function on a specified context object. The value returned by the function is passed back to script as a
boolean
. This allows script to query values on objects within the UI context system.Parameters:
1
Context object id on which to call the function.
2
Function id on the context object to call. This can also be an expression.
Returns:
returned valueboolean
Example - Query CcoBattleRoot to see if battle is in deployment phase:
local is_deployment_phase = effect.get_context_bool_value("CcoBattleRoot", "IsDeploymentPhase")
Example - Query whether campaign character with cqi 51 is on the campaign map:
local char_is_on_map = effect.get_context_bool_value("CcoCampaignCharacter51", "IsOnMap")
-
effect.get_context_numeric_value(
object idstring
,
function idstring
)
-
Calls a specified function on a specified context object. The value returned by the function is passed back to script as a
number
. This allows script to query number values on objects within the UI context system.Parameters:
1
Context object id on which to call the function.
2
Function id on the context object to call. This can also be an expression.
Returns:
returned valuenumber
Example - Query CcoBattleRoot to see which alliance wins on timeout:
local winning_alliance_index = effect.get_context_bool_value("CcoBattleRoot", "TimeoutWinningAllianceIndex")
-
effect.get_context_string_value(
object idstring
,
function idstring
)
-
Calls a specified function on a specified context object. The value returned by the function is passed back to script as a
string
. This allows script to query string values on objects within the UI context system.Parameters:
1
Context object id on which to call the function.
2
Function id on the context object to call. This can also be an expression, but the result must return a context id.
Returns:
context object idstring
Example - Query battle unit 1004 for their morale state as a string:
local morale_state = effect.get_context_string_value("CcoBattleUnit1004", "MoraleName")
-
effect.get_context_vector4_value(
object idstring
,
function idstring
)
-
Calls a specified function on a specified context object. The value returned by the function is passed back to script as a vector4, which is expressed in lua as 4 number values. This allows script to query position values on objects within the UI context system.
Parameters:
1
Context object id on which to call the function.
2
Function id on the context object to call. This can also be an expression.
Returns:
x position valuenumber
y position valuenumber
z position valuenumber
w position value (meaning varies per function)number
Example - Get the position of the Victory Point in battle:
local x, y, z, w = effect.get_context_vector4_value("CcoBattleRoot", "VictoryCapturePointContext.Position")
-
effect.get_context_object_id(
object idstring
,
function idstring
)
-
Calls a specified function on a specified context object that returns a
string
name of another context object. This allows script to get a handle to a context object related to the subject context object, such as an army related to a unit.Parameters:
1
Context object id on which to call the function.
2
Function id on the context object to call. This can also be an expression, but the result must return a context id.
Returns:
context object idstring
Example - Query campaign character with cqi 123 for the context id of the associated military force:
local cco_military_force = effect.get_context_string_value("CcoCharacter123", "MilitaryForceContext")
-
effect.call_context_command(
object idstring
,
function idstring
)
-
Calls a specified function on a specified context object that makes changes to the game. This allows script to use the context system to modify the state of the game.
Parameters:
1
Context object id on which to call the function.
2
Function id on the context object to call. This can be expression.
Returns:
nil
Example - Toggles cinematics mode through the context system:
effect.call_context_command("CcoBattleRoot", "ToggleCinematicMode")