Unit
A unit
object may be created in script to represent a logical unit of soldiers taking part in the battle. The unit object interface permits querying of the state of the unit - to issue orders to the unit a battle_unitcontroller
object must be created to which the unit object may then be associated.
Loaded in Campaign | |
Loaded in Battle | |
Loaded in Frontend |
Unit objects are created from the battle_hierarchy
. They appear at the bottom of this hierarchy - see the battle_hierarchy
page for more information on how unit
objects relate to (and are created from) armies and alliances. Alternatively, and preferably, see the section on scriptunits below for a shorthand method of unit object creation.
Once a handle to a sound effect object is obtained, functions may be called on it to query or modify its state in the following form.
Example - Specification:
<object_name>:<function_name>(<args>)
Example - Creation and Usage:
local sfx_01 = battle_sound_effect:new()
sfx_01:load("test_sound_event") -- calling a function on the object once created
It is highly recommended for client scripts to work with script_unit
objects through the interface provided by the script libraries rather than attempting to manage unit
objects individually. By creating a script_unit
object, a unit
object is automatically created and can be accessed at <script_unit>.unit
. See the script_unit
documentation for more information.
Alternatively the generated_battle
script framework can be used. This automatically creates script_unit
objects (with associated unit objects) and negates the need to set up references to anything more granular than an army.
-
unit:name()
-
Returns the script name for the unit, if any has been set. A script name for the unit may be set in the battle setup, either in the battle xml or on the appropriate record in the
battle_set_piece_armies_units_junctions
table if setting up a set-piece/quest battle. It is valid for multiple units in a given army to have the same script name.Returns:
script namestring
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2596
-
unit:unique_ui_id()
-
Returns the unique ui id for the unit, which should match the name of the corresponding unit card.
Returns:
ui udnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2632
-
unit:type()
-
Returns the unit type of the unit, from the
land_units
table.Returns:
unit typestring
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2647
-
unit:army()
-
Returns the army object to which the unit currently belongs.
Returns:
parent armybattle_army
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2665
-
unit:alliance_index()
-
Returns the index number of the alliance the unit belongs to, allowing its
battle_alliance
to be determined or looked up from abattle_alliances
object.Returns:
alliance indexnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2680
-
unit:army_index()
-
Returns the index number of the army the unit belongs to, allowing its
battle_army
to be determined or looked up from abattle_armies
object (which itself can be determined from the value returned byunit:alliance_index
).Returns:
army indexnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2699
-
unit:unit_class()
-
Returns the class of the unit, from the
land_units
table.Returns:
unit classstring
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2717
-
unit:is_commanding_unit()
-
Returns whether this is the commanding unit of the army.
Returns:
is commandingboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2737
-
unit:is_infantry()
-
Returns whether this is a unit of infantry.
Returns:
is infantryboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2757
-
unit:is_pikemen()
-
Returns whether this is a unit of pikemen.
Returns:
is pikemenboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2777
-
unit:is_anti_cavalry_infantry()
-
Returns whether this is a unit of anti-cavalry infantry.
Returns:
is anti-cavalry infantryboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2797
-
unit:is_cavalry()
-
Returns whether the unit is cavalry.
Returns:
is cavalryboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2817
-
unit:is_lancers()
-
Returns whether this is a unit of lancers.
Returns:
is lancersboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2834
-
unit:is_dismounted_cavalry()
-
Returns whether this is a dismounted cavalry unit.
Returns:
is dismounted cavalryboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2854
-
unit:is_chariot()
-
Returns whether this is a chariot unit.
Returns:
is chariotboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2874
-
unit:is_camels()
-
Returns whether this unit fights on camels.
Returns:
is camelsboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2894
-
unit:is_elephants()
-
Returns whether this is a unit of elephants.
Returns:
is elephantsboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2914
-
unit:is_war_beasts()
-
Returns whether this is a unit of war beasts.
Returns:
is war beastsboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2934
-
unit:is_artillery()
-
Returns whether the unit is artillery.
Returns:
is artilleryboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2954
-
unit:is_unlimbered_artillery()
-
Returns whether the unit is artillery in an unlimbered state (it can fire, but not move).
Returns:
is unlimbered artilleryboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2971
-
unit:is_limbered_artillery()
-
Returns whether the unit is artillery in a limbered state (i.e. it can move but not fire).
Returns:
is limbered artilleryboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 2991
-
unit:is_fixed_artillery()
-
Returns whether the unit is fixed artillery. Fixed artillery can never move.
Returns:
is fixed artilleryboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3008
-
unit:is_war_machine()
-
Returns whether the unit is a war machine.
Returns:
is war machineboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3028
-
unit:can_fly()
-
Returns whether the unit can fly.
Returns:
can flyboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3048
-
unit:is_currently_flying()
-
Returns whether the unit can fly and is currently flying.
Returns:
is flyingboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3068
-
unit:has_ships()
-
Returns whether the unit is currently on a ship.
Returns:
is on a shipboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3088
-
unit:is_dismounted_ships()
-
Returns whether the unit has a ship but is not currently on it.
Returns:
dismounted from shipboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3108
-
unit:position()
-
Returns the centre position of the main squad of the unit.
Returns:
positionbattle_vector
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3132
-
unit:ordered_position()
-
Returns the position to which the unit has been ordered to move to. Note that if the unit is attacking, as opposed to moving, then this will return the current position of the unit.
Returns:
ordered positionbattle_vector
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3150
-
unit:can_reach_position(
positionbattle_vector
)
-
Returns whether the unit can reach the supplied position.
Parameters:
1
position
Returns:
can reachboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3168
-
unit:bearing()
-
Returns the current orientation of the main squad of the unit in degrees.
Returns:
orientationnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3199
-
unit:ordered_bearing()
-
Returns the orientation of the position to which the unit has been ordered in degrees.
Returns:
orientationnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3218
-
unit:ordered_width()
-
Returns the width of the position to which the unit has been ordered in metres.
Returns:
widthnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3237
-
unit:position_of_officer()
-
Returns the position of the commanding officer of the unit.
Returns:
officer positionbattle_vector
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3254
-
unit:is_ai_controlled()
-
Returns whether the supplied unit is currently under AI control.
Returns:
controlled by AIboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3282
-
unit:is_script_controlled()
-
Returns whether the supplied unit is currently under script control.
Returns:
controlled by scriptboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3299
-
unit:is_player_controlled()
-
Returns whether the supplied unit is currently under script control.
Returns:
controlled by scriptboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3316
-
unit:unit_in_range(
target unitbattle_unit
)
-
Returns whether the supplied unit is in missile range of this unit.
Parameters:
1
target unit
Returns:
is in rangeboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3333
-
unit:unit_distance(
target unitbattle_unit
)
-
Returns the shortest distance in metres between this unit and a supplied unit, taking into account their bounding box rather than just working out the centre-to-centre distance.
Parameters:
1
target unit
Returns:
shortest distancenumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3358
-
unit:strategic_value()
-
Returns an arbitrary numeric indicator of this unit's current strength. Better units, or units in a better current condition, will return higher values that less capable units.
Returns:
strategic valuenumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3383
-
unit:is_moving()
-
Returns whether the unit is moving.
Returns:
is movingboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3401
-
unit:is_moving_fast()
-
Returns whether the unit is moving fast (running/charging).
Returns:
is moving fastboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3419
-
unit:slow_speed()
-
Returns the unit's slow/walking movement speed in m/s.
Returns:
movement speednumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3437
-
unit:fast_speed()
-
Returns the unit's fast/running movement speed in m/s.
Returns:
movement speednumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3455
-
unit:is_idle()
-
Returns whether the unit is currently idle.
Returns:
is idleboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3473
-
unit:is_leaving_battle()
-
Returns whether the unit is currently leaving the battlefield.
Returns:
is leaving battleboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3490
-
unit:is_valid_for_deployment()
-
Returns whether this unit is currently valid for deployment, that means if the unit is not in a playable state or if its being deployed by the reinforcement system
Returns:
is valid for deploymentboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3507
-
unit:is_valid_target()
-
Returns whether this unit is currently a valid target for enemies to attack. A unit might be invalid if they are entering or leaving the battlefield, hidden, or dead.
Returns:
is valid targetboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3527
-
unit:is_currently_garrisoned()
-
Returns whether the unit is currently garrisoned in a building.
Returns:
is garrisonedboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3544
-
unit:is_hidden()
-
Returns whether the unit is currently hidden in tall grass/trees. Note that this is a separate test from the unit being obscured from the enemy behind hills or other terrain features.
Returns:
is hiddenboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3565
-
unit:is_visible_to_alliance(
alliancebattle_alliance
)
-
Returns whether the unit is visible to a supplied alliance. This returns the last calculated result of the line-of-sight test that determines whether a unit is obscured from its enemy by terrain features.
Parameters:
1
alliance
Returns:
is visible to allianceboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3583
-
unit:is_under_missile_attack()
-
Returns whether the unit is currently taking fire.
Returns:
taking fireboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3616
-
unit:is_in_melee()
-
Returns whether the unit is currently in melee combat.
Returns:
in meleeboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3634
-
unit:number_of_enemies_killed()
-
Returns the number of enemy combatants this unit has killed in this battle.
Returns:
number killednumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3652
-
unit:initial_number_of_men()
-
Returns the number of soldiers the unit started the battle with.
Returns:
initial unit sizenumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3672
-
unit:number_of_men_alive()
-
Returns the number of soldiers currently alive in the unit.
Returns:
current unit sizenumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3689
-
unit:unary_of_men_alive()
-
Returns the number of soldiers currently alive in the unit, expressed as a unary fraction of the the initial size of the unit. A returned value of 0.75 would indicate that 25% of the soldiers in the unit that started the battle have died.
Returns:
unary proportionnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3706
-
unit:kill_number_of_men(
soldiers to killnumber
, [
hide bodiesboolean
])
-
Kills a specified number of soldiers in the unit. The optional second argument allows their bodies to be hidden - this is useful if it's desired that the unit 'disappear'.
Parameters:
1
soldiers to kill
2
optional, default value=false
hide bodies
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3724
-
unit:reduce_hitpoints_unary(
unary hitpointsnumber
, [
hide bodiesboolean
])
-
Reduces hitpoints of the unit. The optional second argument allows their bodies to be hidden - this is useful if it's desired that the unit 'disappear'.
Parameters:
1
percentage of full hit points of unit to reduce
2
optional, default value=false
hide bodies
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3745
-
unit:heal_hitpoints_unary(
unary hitpointsnumber
, [
allow resurrectionboolean
])
-
Heals the unit to the specified unary proportion of full strength i.e. 1.0 = full strength. If the allow-resurrection flag is set then dead entities may be resurrected, otherwise the function heals where it can. The function does not work in all circumstances, healing animals + handlers are not currently supported.
Parameters:
1
percentage of full hit points to heal to.
2
optional, default value=true
Allow resurrection of dead entities.
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3777
-
unit:respawn()
-
Respawns the unit in a supplied position on the battlefield.
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3808
-
unit:unary_hitpoints()
-
Returns the hitpoint strength of all soldiers in the unit, expressed as a unary fraction of the the initial hitpoint strength of the unit. A returned value of 0.75 would indicate that the unit has lost 25% of the hitpoints it started the battle with.
Returns:
unary proportionnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3839
-
unit:is_wavering()
-
Returns whether the morale of the unit is currently wavering.
Returns:
is waveringboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3862
-
unit:is_routing()
-
Returns whether the unit is currently routing.
Returns:
is routingboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3879
-
unit:is_invulnerable()
-
Returns whether the unit is currently invulnerable.
Returns:
is invulnerableboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3895
-
unit:is_rampaging()
-
Returns whether the unit is currently rampaging.
Returns:
is rampagingboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3911
-
unit:is_shattered()
-
Returns whether the unit is currently shattered (routing without possibility of return).
Returns:
is shatteredboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3928
-
unit:is_crumbling()
-
Returns whether the unit is currently crumbling (undead's equivalent of routing).
Returns:
is crumblingboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3945
-
unit:is_unstable()
-
Returns whether the unit is currently daemonically unstable (daemonic equivalent of routing).
Returns:
is unstableboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3962
-
unit:is_left_flank_threatened()
-
Returns whether the left flank of the unit is currently threatened by the enemy.
Returns:
left flank threatenedboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3979
-
unit:is_right_flank_threatened()
-
Returns whether the right flank of the unit is currently threatened by the enemy.
Returns:
left right threatenedboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 3997
-
unit:is_rear_flank_threatened()
-
Returns whether the rear of the unit is currently threatened by the enemy.
Returns:
rear threatenedboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4015
-
unit:left_flank_threat()
-
Returns the
battle_unit
threatening this unit's left flank. If no such unit is threatening then no value is returned.Returns:
threatening unitbattle_unit
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4033
-
unit:right_flank_threat()
-
Returns the
battle_unit
threatening this unit's right flank. If no such unit is threatening then no value is returned.Returns:
threatening unitbattle_unit
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4053
-
unit:rear_threat()
-
Returns the
battle_unit
threatening this unit's rear. If no such unit is threatening then no value is returned.Returns:
threatening unitbattle_unit
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4073
-
unit:current_target()
-
Returns the
battle_unit
this unit is targeting. If no unit is being targeted then no value is returned.Returns:
target unitbattle_unit
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4093
-
unit:is_on_top_of_platform()
-
Returns whether the unit is currently on the top of a platform, such as a wall.
Returns:
is on platformboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4113
-
unit:is_controllable()
-
Returns whether the unit is currently controllable.
Returns:
is controllableboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4130
-
unit:is_deploying()
-
Returns whether the unit is deploying or waiting to be
Returns:
is deployed.boolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4146
-
unit:is_deployed()
-
Returns whether the unit has been deployed
Returns:
is deployed.boolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4164
-
unit:fatigue_state()
-
Returns the fatigue state of the unit as a string. Possible values are
threshold_fresh
,threshold_active
,threshold_winded
,threshold_tired
,threshold_very_tired
andthreshold_exhausted
.Returns:
fatigue statestring
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4182
-
unit:ammo_left()
-
Returns the remaining ammunition count of this unit.
Returns:
current ammunitionnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4206
-
unit:starting_ammo()
-
Returns the amount of ammunition the unit started the battle with.
Returns:
starting ammunitionnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4223
-
unit:set_current_ammo_unary(
unary ammunition levelnumber
)
-
Sets the current ammunition level of the unit to the supplied unary value. Setting a value of 0 would mean the unit would have no ammunition, whereas setting a value of 1 would mean the unit would have the amount of ammunition they started the battle with. It is permitted to set a value greater than 1, but the unit will appear to have full ammunition on the UI until its ammunition level drops back below 100%.
Parameters:
1
unary ammunition level
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4240
-
unit:missile_range()
-
Returns the missile range of this unit in metres.
Returns:
missile rangenumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4269
-
unit:can_perform_special_ability(
special ability keystring
)
-
Returns whether the unit can perform the specified special ability. Valid special abilities are defined in the
unit_special_abilities
database table.Parameters:
1
special ability key
Returns:
can perform abilityboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4290
-
unit:disable_passive_special_abilities([
disableboolean
])
-
Disables or re-enables all passive special abilities of this unit. It only affects abilities owned by the unit. Abilities specify if they are passive in the
unit_special_abilities
database table. Passive abilities are mostly buffs or infinite effects. This function works independently fromunit:disable_special_ability
so it will not re-enable abilities affected by it.Parameters:
1
optional, default value=true
Disables or re-enables the ability (
true
for disabling it)Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4332
-
unit:disable_non_passive_special_abilities([
disableboolean
])
-
Disables or re-enables all non_passive special abilities of this unit. It only affects abilities owned by the unit. Abilities specify if they are passive in the unit_special_abilities
unit_special_abilities
database table. Non-passive abilities are mostly direct damage spells or abilities. This function works independently fromunit:disable_special_ability
so it will not re-enable abilities affected by it.Parameters:
1
optional, default value=true
Disables or re-enables the ability (
true
for disabling it)Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4341
-
unit:disable_special_ability(
ability_keystring
, [
disableboolean
])
-
Disables the specified special ability from this unit. It only affects the ability instance currently owned by the unit. This function works independently from
unit:disable_passive_special_abilities
andunit:disable_non_passive_special_abilities
so it will not re-enable abilities affected by it.Parameters:
1
ability_key
2
optional, default value=true
Disables or re-enables the ability (
true
for disabling it)Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4350
-
unit:owned_passive_special_abilities()
-
Returns a lua table of passive special abilities owned by this unit. Abilities specify if they are passive in the table unit_special_abilities. Passive abilities are mostly buffs or infinite effects - they are abilities activated automatically, not by the player.
Returns:
owned abilities, Table of strings containing the key of the corresponding special abilitiestable
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4405
-
unit:owned_non_passive_special_abilities()
-
Returns a lua table of non-passive special abilities owned by this unit. Abilities specify if they are passive in the table unit_special_abilities. Non-passive abilities are abilities activated by the player, mostly direct damage abilities and spells.
Returns:
owned abilities, Table of strings containing the key of the corresponding special abilitiestable
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4413
-
unit:owned_special_abilities()
-
Returns all special abilities owned by an unit. Valid special abilities are defined in the
special_abilities
table.Returns:
owned abilities, Table of strings containing the key of the corresponding special abilitiestable
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4421
-
unit:num_special_abilities()
-
Returns the number of special abilities this unit has.
Returns:
number of special abilitiesnumber
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4435
-
unit:can_use_magic()
-
Returns whether the unit can use any special abilities that cost magic.
Returns:
can use magicboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4450
Special Abilities
are associated with special ability flags, and are activated and deactivated depending upon what special ability flags are currently active, either globally or on a particular unit. Supported special ability flags on a given unit are found in the special_ability_invalid_usage_flags
table and are also listed below. Special ability flags may be activated or deactivated per-unit with unit:set_special_abilities_flags
and also globally with battle:set_special_abilities_flags
.
army_is_full
other_abilities_none_on_wind_up
other_abilities_at_least_one_on_wind_up
other_abilities_just_activated_after_wind_up
cannot_perform_missile_attack
cannot_find_enemies_in_intercept_range
enemies_in_intercept_range
enemies_in_intercept_range_commander_class
no_enemies_in_intercept_range_commander_class
enemies_in_intercept_range_large
no_enemies_in_intercept_range_large
climbing
climbing_manning_eq_on_platform
not_climbing_manning_eq_on_platform
disembarked_from_a_ship
embarked_on_a_ship
defending_a_zone
dismounted
enraged
engaged_in_melee
engaged_in_melee_anything
flying_currently
flying_unit
ground_unit
grounded
has_casting_ability
hasnt_casting_ability
health_above_10%
health_above_20%
health_above_25%
health_above_50%
health_above_75%
health_below_25%
health_below_50%
health_below_75%
health_above_50%_base
health_below_50%_base
mana_above_50%
mana_below_50%
mana_equal_or_above_value_15
mana_below_value_15
winning_melee_combat
losing_melee_combat
manning_equipment
morale_is_higher_than_broken
morale_is_higher_than_shattered
morale_is_higher_than_wavering
morale_is_broken_or_lower
morale_is_wavering_or_lower
morale_is_higher_than_half_of_base_morale
morale_is_lower_than_half_of_base_morale
fatigue_is_below_active
fatigue_is_below_winded
fatigue_is_below_tired
fatigue_is_below_very_tired
fatigue_is_below_exhausted
moving
not_yet_enraged
officer_dead
on_a_platform
not_on_a_platform
docked
not_docked
out_of_melee
out_of_melee_anything
phase_is_deployment
phase_is_the_end_phase
have_ammo_left
have_max_ammo
have_ammo_below_threshold
hp_replenish_cap_reached
unit_alive
unit_dead
unit_is_commander_class
unit_is_not_commander_class
ground_type_is_not_forest
unit_in_forest
unit_is_not_in_forest
unit_has_murderous_prowess
unit_is_not_pre_murderous_prowess
unit_does_not_have_murderous_prowess
unit_is_in_fort
unit_is_out_fort
unit_is_in_withdraw
unit_is_not_in_withdraw
unit_is_in_melee_breakoff
unit_is_not_in_melee_breakoff
unit_is_fearless
unit_is_not_fearless
has_realm_of_souls_tier_1
has_realm_of_souls_tier_2
has_realm_of_souls_tier_3
hasnt_realm_of_souls_tier_1
hasnt_realm_of_souls_tier_2
hasnt_realm_of_souls_tier_3
unit_is_not_construct
unit_is_not_single_entity
is_not_missile_unit
unit_is_not_shielded
unit_tier1_kills
unit_tier2_kills
unit_tier3_kills
cannot_find_allies_in_intercept_range
allies_in_intercept_range
commander_died_within_range
enemy_unit_died_within_range
no_enemy_unit_died_within_range
flying_over_platform
flying_over_invalid_location
unit_is_not_charging
unit_is_not_large
unit_is_large
friendly_battle_leader_killed_or_routed
friendly_battle_leader_not_killed_or_routed
no_harmony_yin_in_proximity
no_harmony_yang_in_proximity
unit_broken_within_range
is_rampaging
is_not_rampaging
living_unit
undead_unit
unit_is_not_a_lizard_unit
unit_is_skaven
unit_is_not_skaven
unit_is_gorger
unit_is_not_gorger
daemonic_unit
not_daemonic_unit
unit_is_moulder_monster
unit_is_nurgling
unit_is_not_nurgling
has_khorne_mark
hasnt_khorne_mark
has_nurgle_mark
hasnt_nurgle_mark
has_slaanesh_mark
hasnt_slaanesh_mark
has_tzeentch_mark
hasnt_tzeentch_mark
Not all flags will be supported by each game.
-
unit:set_special_abilities_flags(
flag keystring
,
enable/disableboolean
)
-
Activates or deactivates a special ability usage flag on the unit. Valid flags are listed at the top of this section.
Parameters:
1
flag key
2
enable/disable
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4629
-
unit:can_use_behaviour(
behaviourstring
)
-
Returns whether the unit can use a particular behaviour this battle. Valid behaviours are currently as follows:
defend
,drop_siege_equipment
,abandon_artillery_engines
,change_formation_spacing
,dismantle_artillery_piece
,dismount
,fire_at_will
,skirmish
,release_animals
,unlimber
,board_ship
, andformed_attack
.Parameters:
1
behaviour
Returns:
behaviour can be usedboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4661
-
unit:is_behaviour_active(
behaviourstring
)
-
Returns whether a particular behaviour is currently active. Valid behaviours are currently as follows:
defend
,drop_siege_equipment
,abandon_artillery_engines
,change_formation_spacing
,dismantle_artillery_piece
,dismount
,fire_at_will
,skirmish
,release_animals
,unlimber
,board_ship
, andformed_attack
.Parameters:
1
behaviour
Returns:
behaviour is activeboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4680
Unit attributes define certain intrinsic properties of a unit in battle. Attributes are generally assigned to a unit type in the game database, but may be enabled or disabled per-unit in script using the unit:set_stat_attribute
function. Valid attribute keys are shown in the following list:
Attribute Key | Description |
---|---|
all_ranks_fire | All ranks can fire if using a weapon that only allows one rank. |
berserk | This unit will occasionally go berserk. |
cant_run | This unit cannot run - generally for limbered artillery. |
campaign_stealth | This unit is able to move around the campaign map without being seen. |
causes_fear | This unit frightens all enemy units, reducing their morale when nearby. It is also immune to fear. |
causes_terror | The unit can cause terror, making enemies rout for a short time but without morale penalties. It is also immune to terror and fear. |
charge_defense | Defense bonus agains charges by all units. |
charge_defense_vs_large | Defense bonus agains charges by large units. |
commander_hunter | This unit is changed in various ways to make them better at killing commanders. |
disciplined | This unit doesn't suffer morale penalty from general's death. |
encourages | This unit provides a morale bonus to nearby allies. |
fatigue_res | Fatigue doesn't have as much of an effect. |
fatigue_immune | Fatigue doesn't affect this unit. |
fire_while_moving | This infantry unit can fire while moving. |
formed_attack | This unit will try to stay in formation when in melee. |
guerrilla_deploy | Can deploy outside deployment zone (vanguard deployment). |
hide_forest | Can hide in forest. |
hide_grass | Can hide in grass. |
hide_scrub_and_forest | Can hide in scrubland. |
hide_building | Can hide in buildings. |
ignore_ground_move_mod | Doesn't get slowed down by terrain. |
strider | Strider attribute. |
immune_to_psychology | The unit is immune to psychological attacks (fear and terror). |
impetuous | The unit gains an extra morale bonus when eager. |
invincible | The unit cannot be damaged. |
mounted_fire | The unit can fire while on a mount. |
mounted_fire_move | The unit can fire while on a moving mount. |
mounted_fire_parthian | The unit can fire while on a moving mount in a Parthian fashion. |
rampage | This unit may rampage if put under pressure. |
resist_cold | This unit doesn't take extra casualties from cold climates in campaign. |
resist_heat | This unit doesn't take extra casualties from hot climates in campaign. |
run_amok | This unit may run amok if put under pressure. |
scare_horse | This unit scares horses. |
scare_immune | This unit is immune to fear effects. |
snipe | The unit remains hidden while firing. |
stalk | This unit can remain hidden while moving. |
unbreakable | This unit's morale cannot be broken. |
undead | The unit is undead (does not rout, immune to terror, receives crumble damage when morale is low). |
unspottable | If this unit is able to hide in its current location, it will not be spotted by enemies until they are very close. |
expendable | A normal (non-expendable) unit's morale does not suffer from witnessing an expendable unit routing. |
construct | The unit is a statue. |
gorger | The unit is a statue. |
wallbreaker | The unit can attack walls physically. |
devastating_flanker | The unit can attack walls physically. |
daemonic | The unit is daemonic. |
flying | The unit is flying. |
always_flying | The unit is always flying. |
ignore_trees | The unit ignores trees. |
moulder_monster | The unit is a moulder monster that can be targeted by Throt's abilities. |
yin | Cathay unit is affiliated with yin. |
yang | Cathay unit is affiliated with yang. |
spell_mastery | The unit has spell mastery (mastery of elemental winds). |
charge_reflection | Unit can reflect charges. |
ogre_charge | The unit has ogre charge. |
shoot_disabled | Missile attacks disabled. |
melee_disabled | Melee attacks disabled. |
mark_khorne | Unit has the mark of Khorne. Used for ability targeting. |
mark_nurgle | Unit has the mark of Nurgle. Used for ability targeting. |
mark_slaanesh | Unit has the mark of Slaanesh. Used for ability targeting. |
mark_tzeentch | Unit has the mark of Tzeentch. Used for ability targeting. |
invulnerable_to_effects_ally | Invulnerable to damage from an allied effect. |
invulnerable_to_effects_enemy | Invulnerable to damage from allied effects. |
Not all attributes will be supported by each game.
-
unit:set_stat_attribute(
attribute keystring
,
enable/disableboolean
)
-
Enables or disables a global attribute on the unit. Attribute keys are listed above, in the
Unit Attributes
section description.Parameters:
1
attribute key
2
enable/disable
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4770
-
unit:has_attribute(
attribute keystring
)
-
Returns whether a unit currently has an attribute. Attribute keys are listed above, in the
Unit Attributes
section description.Parameters:
1
attribute key
Returns:
has attributeboolean
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4793
-
unit:trigger_sound_charge()
-
Compels the unit to make a charge sound effect.
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4823
-
unit:trigger_sound_taunt()
-
Compels the unit to make a taunt sound effect.
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4835
-
unit:play_anim_for_captain(
animation keystring
,
loop animationboolean
)
-
Compels the unit leader to play an animation.
Parameters:
1
animation key
2
loop animation
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4850
-
unit:deploy_reinforcement(
enableboolean
, [
spawn zone indexnumber
])
-
Prevents or allows the unit to deploy as a reinforcement from a specific spawn zone if provided. If set to
false
, and the unit has not yet entered the battlefield, then the unit will not be able to deploy until the function is called again with an argument oftrue
.
Calling this command has no effect if the unit is not part of a reinforcement army.Parameters:
1
Enable reinforcement.
2
optional, default value=nil
Index of spawn zone to use, if coming on as a reinforcement.
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4896
-
unit:select_in_ui()
-
Selects the unit in the user interface.
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4934
-
unit:highlight([
highlightboolean
])
-
Activates or deactivates a highlight on the unit.
Parameters:
1
optional, default value=true
highlight
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4943
-
unit:mark_as_ally(
mark as allyboolean
)
-
Makes a player unit look like it is allied, rather than part of the controlled army. This is useful for specific scripted situations where it's intended to grant allied units to player control.
Call this function withtrue
as a single argument to mark the controlled unit as an ally, and then again supplyingfalse
to mark the unit as part of the player's army again.Parameters:
1
mark as ally
Returns:
nil
defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 4955