Script Unit
A scriptunit is a script object type which represents a single unit on the battlefield. Its primary function is to package a battle_unit interface that represents the unit together with a battle_unitcontroller that has control over that unit. By packaging these two interfaces together, a scriptunit provides access through one object to commands that test the state of a unit (the battle_unit interface) as well as commands which issue orders to that unit (the battle_unitcontroller interface). Scriptunit objects may be passed around in script with the receiving code being sure that it has access to both read and modify the state of the subject unit.
The scriptunit interface provides direct access to the battle_unit and battle_unitcontroller interfaces related to the unit at the unit (
Scriptunit objects may be grouped together in a specialised container, the script_units object. This provides yet further functionality that can be offered when a collection of script units are assembled together. See the script_units documentation further down this page for more information.
| Loaded in Campaign |
|
| Loaded in Battle |
|
| Loaded in Frontend |
|
On creation, the battle_manager automatically sets up a script unit object for each unit and a script_units collection object for each army in the battle. These can be retrieved from the battle_manager with the functions listed in the Scriptunits section of this documentation.
New script unit objects may nevertheless be created using script_unit:new or script_unit:new_by_reference.
-
script_unit:new_by_reference(armybattle_army, valuereference) -
Creates a new script unit. The unit object to encapsulate is looked up by the supplied army and reference name.
Parameters:
1
Army the target unit is a member of.
2
valueReference for the unit. This can either be a
stringname, or an integer number representing the unit's index within the army ('1' is generally the general, for example). If astringname is supplied this must match the script name given to the unit in the battle setup - this is generally set in either the battle xml or in the relevant entry in thebattle_set_piece_armies_units_junctionsdatabase table.Returns:
script_unit
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 63
-
script_unit:new(unitbattle_unit, [namestring]) -
Creates a new script unit from a supplied
battle_unit. An optional reference name may be passed which is used for debug output.Parameters:
1
Unit object to be contained.
2
optional, default value=nil
Reference name for the unit.
Returns:
script_unit
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 130
Variables in this section:
These variables may be accessed via <interface>.<variable_name>:
| unit |
battle_unit
|
object representing the subject unit. |
| uc |
battle_unitcontroller
|
unitcontroller object that controls the unit. |
Functions in this section:
-
script_unit:army() -
Returns the army object to which the unit contained by this scriptunit currently belongs.
Returns:
armybattle_army
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 231
-
script_unit:alliance() -
Returns the alliance object to which the unit contained by this scriptunit belongs.
Returns:
alliancebattle_alliance
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 239
Variables in this section:
These variables may be accessed via <interface>.<variable_name>:
| start_position |
battle_vector
|
Vector position the unit started the battle at. |
| start_bearing |
number
|
Bearing in degrees the unit started the battle at. |
| start_width |
number
|
Width in m of the unit at the start of the battle. |
Functions in this section:
-
script_unit:goto_start_location([booleanshould run]) -
Instructs the scriptunit to move to its start location.
Parameters:
1
booleanoptional, default value=false
should run
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 265
-
script_unit:teleport_to_start_location() -
Teleports the scriptunit to the position/bearing/width it started the battle at.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 273
-
script_unit:teleport_to_start_location_offset(x offset
number,z offset
number,bearing override
[number],release control
[boolean]
) -
Teleports the scriptunit to an offset from the position/bearing/width it started the battle at. This offset will be calculated from the scriptunit's start bearing, so an offset of [0, -10] will teleport it 10m behind its starting position. The function also optionally takes an override bearing to alter the position calculation, as well as a flag to release the unit to script control afterwards.
Parameters:
1
numberx offset in m
2
numberz offset in m
3
numberoptional, default value=nil
Bearing override in degrees. Supply a value here to override the bearing used to make the offset calculation.
4
booleanoptional, default value=false
Release control after teleporting. Set this to true if you want the player (or AI, if it's not player-controlled) to be able to control this unit immediately after teleporting.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 280
-
script_unit:goto_start_location_offset(x offset
number,z offset
number,should run
[boolean],bearing override
[number],release control
[boolean]
) -
Instructs the scriptunit to move to an offset from the position/bearing/width it started the battle at. This offset will be calculated from the scriptunit's start bearing, so an offset of [0, -10] will send it 10m behind its starting position. The function also optionally takes a flag to instruct the unit to run, an override bearing to alter the position calculation, as well as a flag to release the unit to script control afterwards.
Parameters:
1
numberx offset in m
2
numberz offset in m
3
booleanoptional, default value=false
Set to true to instruct the unit to move quickly to its destination.
4
numberoptional, default value=nil
Bearing override in degrees. Supply a value here to override the bearing used to make the offset calculation.
5
booleanoptional, default value=false
Release control after the movement order is issued. Set this to true if you want the player (or AI, if it's not player-controlled) to be able to control this unit immediately after moving.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 312
-
script_unit:respawn_in_start_location([only if deadboolean]) -
Respawns the unit at the location it started the battle. This resets its health, fatigue, casualties and other stats.
Parameters:
1
optional, default value=false
Respawn the unit only if it is dead, or if it has routed off the battlefield.
Returns:
unit was respawnedboolean
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 345
-
script_unit:position_offset(numberx offset, numbery offset, numberz offset, [numberbearing override]) -
Returns the position of the scriptunit, offset from its current position. This offset will be calculated from the scriptunit's current bearing, so an offset of [0, 0, -10] will report a position 10m behind its current position. An override bearing to alter the position calculation may optionally be supplied.
Parameters:
1
numberx offset in m
2
numbery offset (height) in m
3
numberz offset in m
4
numberoptional, default value=nil
Bearing override in degrees. Supply a value here to override the bearing used to make the offset calculation.
Returns:
offset positionbattle_vector
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 377
-
script_unit:goto_location_offset(x offset
number,z offset
number,should run
[boolean],bearing override
[number],release control
[boolean]
) -
Instructs the scriptunit to move to an offset from its current position. This offset will be calculated from the scriptunit's current bearing, so an offset of [0, -10] will send it 10m behind its current position. The function also optionally takes a flag to instruct the unit to run, an override bearing to alter the position calculation, as well as a flag to release the unit to script control afterwards.
Parameters:
1
numberx offset in m
2
numberz offset in m
3
booleanoptional, default value=false
Set to true to instruct the unit to move quickly to its destination.
4
numberoptional, default value=nil
Bearing override in degrees. Supply a value here to override the bearing used to make the offset calculation.
5
booleanoptional, default value=false
Release control after the movement order is issued. Set this to true if you want the player (or AI, if it's not player-controlled) to be able to control this unit immediately after moving.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 414
-
script_unit:teleport_to_location_offset(x offset
number,z offset
number,bearing override
[number],release control
[boolean]
) -
Instructs the scriptunit to teleport to an offset from its current position. This offset will be calculated from the scriptunit's current bearing, so an offset of [0, -10] will teleport it 10m behind its current position. The function also optionally takes an override bearing to alter the position calculation, as well as a flag to release the unit to script control afterwards.
Parameters:
1
numberx offset in m
2
numberz offset in m
3
numberoptional, default value=nil
Bearing override in degrees. Supply a value here to override the bearing used to make the offset calculation.
4
booleanoptional, default value=false
Release control after the teleport order is issued. Set this to true if you want the player (or AI, if it's not player-controlled) to be able to control this unit immediately after teleporting.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 449
-
script_unit:goto_location_offset_when_deployed(x offset
number,z offset
number,should run
[boolean],bearing override
[number],release control
[boolean]
) -
Instructs the scriptunit to goto an offset from its location when it deploys. This offset will be calculated from the scriptunit's bearing at the time it finds itself on the battlefield, so an offset of [0, -5] will move it 50m forward. The function also optionally takes a flag instructing it to run, an override bearing to alter the position calculation, as well as a flag to release the unit to script control afterwards.
Parameters:
1
numberx offset in m
2
numberz offset in m
3
booleanoptional, default value=false
Set to true to instruct the unit to move quickly to its destination.
4
numberoptional, default value=nil
Bearing override in degrees. Supply a value here to override the bearing used to make the offset calculation.
5
booleanoptional, default value=false
Release control after the movement order is issued. Set this to true if you want the player (or AI, if it's not player-controlled) to be able to control this unit immediately after moving.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 487
-
script_unit:stop_goto_location_offset_when_deployed() -
Stops a running
script_unit:goto_location_offset_when_deployedlistener on the current unit. Call this after callingscript_unit:goto_location_offset_when_deployedto stop the listener for any reason.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 508
-
script_unit:turn_to_face(vectorposition) -
Instructs the scriptunit to turn to face a position vector.
Parameters:
1
vectorposition
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 515
-
script_unit:teleport_to_location(vectorposition, numberbearing, numberwidth) -
Instructs the scriptunit to teleport to a location.
Parameters:
1
vectorPosition to teleport to.
2
numberBearing to face at the target position in degrees.
3
numberWidth in m of formation at target position.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 551
-
script_unit:cache_location() -
Caches the units current position, bearing and width.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 591
-
script_unit:get_cached_position() -
Returns the vector position of the unit last time it was cached with
script_unit:cache_location.Returns:
vectorposition (or nil, if never cached).
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 600
-
script_unit:get_cached_bearing() -
Returns the bearing of the unit in degrees last time it was cached with
script_unit:cache_location.Returns:
numberbearing (or nil, if never cached).
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 608
-
script_unit:get_cached_width() -
Returns the width of the unit in m last time it was cached with
script_unit:cache_location.Returns:
numberwidth (or nil, if never cached).
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 616
-
script_unit:goto_cached_location([booleanshould run]) -
Instructs the scriptunit to move to the location the unit occupied the last time it was cached with
script_unit:cache_location.Parameters:
1
booleanoptional, default value=false
Instructs the unit to move fast.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 624
-
script_unit:teleport_to_cached_location() -
Teleports the scriptunit to the location the unit occupied the last time it was cached with
script_unit:cache_location.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 635
-
script_unit:has_moved([vectorposition override], [numberthreshold distance]) -
Returns true if the scriptunit has moved from the last cached position, or an optional supplied position. The movement threshold can also be overriden (by default it's 1m).
Parameters:
1
vectoroptional, default value=nil
position override
2
numberoptional, default value=1
threshold distance
Returns:
booleanhas moved
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 644
-
script_unit:cache_destination() -
Caches the current destination position of the scriptunit. Note that the if the subject unit is attacking rather than moving to a position it will have no valid destination. The function also caches whether the unit is running.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 681
-
script_unit:cache_destination_and_halt() -
Caches the current destination position of the scriptunit with
script_unit:cache_destination, and then orders the unit to halt.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 695
-
script_unit:get_cached_destination_position() -
Returns the vector destination last cached by
script_unit:cache_destination.Returns:
vectordestination position (or nil if destination never cached).
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 703
-
script_unit:get_cached_destination_bearing() -
Returns the ordered bearing in degrees that was last cached by
script_unit:cache_destination.Returns:
numberbearing in degrees (or nil if destination never cached).
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 711
-
script_unit:get_cached_destination_width() -
Returns the ordered width in m that was last cached by
script_unit:cache_destination.Returns:
numberwidth in m (or nil if destination never cached).
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 719
-
script_unit:goto_cached_destination([booleanshould release]) -
Instructs the unit to move to the location last cached by
script_unit:cache_destination. If the unit was moving quickly when its destination was last cached, than it will resume moving quickly when this function is called.Parameters:
1
booleanoptional, default value=false
Set to true to release script control of the unit after calling this function. Set this if it's desirable for the player (or AI, if it's not a player-controlled unit) to be able to control this unit after the order has been issued.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 727
-
script_unit:is_under_attack() -
Returns true if the unit is under missile attack, in melee, or has casualties since the last time
is_under_attackwas called. Designed to be called repeatedly.Returns:
booleanis under attack
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 759
-
script_unit:is_in_melee() -
Returns true if the unit is in melee. This is an unembellished wrapper for an underlying code function.
Returns:
booleanis in melee
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 769
Many of the functions in this section just wrap the function provided by code on the unitcontroller interface with no embellishments - by wrapping it here, however, access to it can be provided at the script_units level, so a scriptunits collection can be told to stop with one call to script_unit:halt, for example.
-
script_unit:halt() -
Instructs the scriptunit to halt. This is an unembellished wrapper for an underlying code function.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 817
-
script_unit:celebrate() -
Instructs the scriptunit to celebrate. This is an unembellished wrapper for an underlying code function.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 824
-
script_unit:taunt() -
Instructs the scriptunit to taunt. This is an unembellished wrapper for an underlying code function.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 830
-
script_unit:play_sound_charge() -
Instructs the scriptunit to play a charge sound. This is an unembellished wrapper for an underlying code function.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 837
-
script_unit:play_sound_taunt() -
Instructs the scriptunit to play a taunt sound. This is an unembellished wrapper for an underlying code function.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 844
-
script_unit:deploy_reinforcement([booleanshould deploy]) -
Instructs the scriptunit to deploy as a reinforcement if it can.
Parameters:
1
booleanoptional, default value=true
should deploy
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 861
-
script_unit:change_behaviour_active(stringbehaviour name, booleanactivate) -
Sets a supplied behaviour active on the unit or not. This is an unembellished wrapper for an underlying code function. This is the main mechanism for turning on/turning off certain unit behaviours such as fire at will, skirmish etc. Current list of behaviours includes, but may not be limited to the following:
"defend", "dismount", "fire_at_will", "skirmish", "change_formation_spacing", "drop_siege_equipment", "release_animals", "disembark_from_ship", "board_ship"Parameters:
1
stringbehaviour name
2
booleanactivate
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 873
-
script_unit:withdraw(booleanshould run) -
Instructs the specified unit to withdraw. This is an unembellished wrapper for an underlying code function.
Parameters:
1
booleanshould run
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 886
-
script_unit:set_melee_mode([booleanactivate], [booleanrelease control]) -
Activates or deactivates melee mode.
Parameters:
1
booleanoptional, default value=true
Should activate melee mode.
2
booleanoptional, default value=false
Release script control after setting melee mode. Set this to true if the unit is under player control.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 894
-
script_unit:set_stat_attribute(attribute keystring,enable/disableboolean) -
Enables or disables a unit attribute for the unit. Valid attribute keys are listed in the
Unit Attributessection of this documentation.Parameters:
1
attribute key
2
enable/disable
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 907
-
script_unit:set_enabled(enabled
[boolean],force unit card update
[boolean],unit contributes to army strength
[boolean]
) -
Sets the unit to be enabled and visible if
trueis supplied as an argument, or disabled and invisible iffalseis supplied. The second argument forces the UI to refresh the unit card's visibility, but this only needs to be set totruein certain specific circumstances.
The third argument, if set totrueorfalse, will also set that unit to contribute to the army strength or not depending upon the value supplied. If no value is supplied here then enabled units will contribute to army strength whereas disabled units will not.Parameters:
1
optional, default value=true
enabled
2
optional, default value=false
force unit card update
3
optional, default value=nil
unit contributes to army strength
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 937
-
script_unit:set_always_visible([booleanalways visible]) -
Sets the unit to be always visible, according to the rules of the terrain visibility system.
Parameters:
1
booleanoptional, default value=true
always visible
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 965
-
script_unit:set_always_visible_no_hidden([booleanalways visible]) -
Sets the unit to be always visible, doesn't affect hidden by forest / abilities
Parameters:
1
booleanoptional, default value=true
always visible
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 976
-
script_unit:set_always_visible_no_leave_battle([booleanalways visible]) -
Sets the unit to be always visible, doesn't affect leaving battle
Parameters:
1
booleanoptional, default value=true
always visible
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 987
-
script_unit:set_always_visible_no_hidden_no_leave_battle([booleanalways visible]) -
Sets the unit to be always visible, doesn't affect hidden by forest / abilities doesn't affect leaving battle
Parameters:
1
booleanoptional, default value=true
always visible
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 998
-
script_unit:mark_as_ally(booleanmark as ally) -
Makes player unit look like ally (for script where gradually give units in tutorials). This is an unembellished wrapper for an underlying code function.
Parameters:
1
booleanmark as ally
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1010
-
script_unit:is_hidden() -
Returns true if the unit is hidden in grass/forests etc. This is an unembellished wrapper for an underlying code function. Returned result is not related to the terrain visibility system, which came later than this code function, so a unit may not be hidden (according to this result returned by this function) but may still not be visible to its enemy - check also
script_unit:is_visible_to_enemy.Returns:
booleanis hidden
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1018
-
script_unit:set_invisible_to_all(booleanis hidden) -
Makes the unit invisible. This is an unembellished wrapper for an underlying code function.
Parameters:
1
booleanis hidden
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1026
-
script_unit:is_visible_to_enemy(booleanis visible) -
Returns true if this unit is visible to its enemy, by the rules of the visibility system. Note that the unit may be visible according to the visibility system, but may still be hidden in forests or tall grass - check
script_unit:is_hidden.Parameters:
1
booleanis visible
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1034
These functions explicitly instruct script to take or release control of the subject unit. A unit under script control is removed from the player's control or from general AI control, but may still be controlled by an ai_planner (or script_ai_planner). Note also that giving orders to a unit with a unitcontroller will usually also take control of that unit.
-
script_unit:take_control() -
Takes script control of this unit.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1054
-
script_unit:release_control() -
Releases script control of the subject unit.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1061
-
script_unit:modify_ammo(numberproportion) -
Modifies this unit's ammo to a specified unary proportion of its starting value.
Parameters:
1
numberDesired proportion of starting ammo. Supply 1 to set the ammo back to its starting value, 0.5 to half etc. Values of greater than one are semi-supported - the command will work, but any ammo bars on the UI will show as full until the unit's ammo value drops below its starting value.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1081
-
script_unit:refill_ammo(numberproportion) -
Modifies this unit's ammo to a specified unary proportion of its starting value, but only if it has less than the specified amount.
Parameters:
1
numberDesired proportion of starting ammo. Supply 1 to set the ammo back to its starting value, 0.5 to half etc. Values of greater than one are semi-supported - the command will work, but any ammo bars on the UI will show as full until the unit's ammo value drops below its starting value.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1094
-
script_unit:grant_infinite_ammo() -
Grants this unit infinite ammo by refilling ammo every 5 seconds.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1111
-
script_unit:refresh([booleanshould release]) -
Sets this unit to 1/10th its current fatigue level, and tops its ammo back to full.
Parameters:
1
booleanoptional, default value=false
Release script control of the unit after refreshing. Set this to
trueif the unit is under player control.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1128
-
script_unit:cache_ammo() -
Caches this unit's current ammunition level.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1141
-
script_unit:restore_cached_ammo() -
Restores this unit's ammunition level to the value previously cached with
script_unit:cache_ammo.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1148
-
script_unit:cache_health() -
Caches the proportion of the scriptunit still alive, so that it can be queried later with
script_unit:has_taken_casualties.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1178
-
script_unit:has_taken_casualties([numbertolerance]) -
Compares the scriptunits current casualties with that when it was previously cached with
script_unit:cache_health, and returns true if they're different.Parameters:
1
numberoptional, default value=0
Tolerance value. The casualties values is expressed internally as a unary value (between 0 and 1), so this should be expressed in a similar manner. Therefore a tolerance of 0.1 would allow for 10% casualties (of the original number of soldiers in the unit) more than when previously cached before returning true.
Returns:
booleanhas taken casualties
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1189
-
script_unit:unary_hitpoints([shatteredconsidered dead]) -
Returns this unit's hitpoints as a unary of its initial value. If the shattered-considered-dead flag is set and the unit is shattered (or it's routing and has left the field), then 0 is returned.
Parameters:
1
shatteredoptional, default value=false
considered dead
Returns:
unary hitpointsnumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1219
-
script_unit:max_casualties(unary proportion
number,should release
[boolean],exception sunit(s)
[script_units],boolean silent mode
) -
Sets the maximum number of casualties that this unit can take. If the unit's hitpoints drop below the specified unary value, the unit is made invincible so that it can no longer take casualties (note that it may still rout). Exception scriptunits can be set, so that proximity to those
script_unitorscript_unitsdisables this invincibility (allow certain units to be perceived to charge in and 'save the day').Parameters:
1
numberUnary proportion. A value of 0.5 would allow the unit to take 50% casualties before becoming invincible (note that in extreme scenarios the unit may still die, if one-shotted by something for example).
Call
max_casualtieswith a proportion value of 0 to disables any previousmax_casualtiesmonitor on this unit.2
booleanoptional, default value=false
Set to true to release script control of this unit after
max_casualtiesmakes a change. Set this primarily if the unit is under player control.3
optional, default value=nil
Exception
script_unitorscript_unitscollection. If this unit comes within 30m of any unit specified here, themax_casualtiesmonitor will temporarily cease and they will become vulnerable to casualties.The monitor will resume and this unit will (potentially) regain invincibility when this unit moves more than 40m away from any unit specified as an exception.
4
Activate silent mode.
max_casualtieswrites output by default, supplytruehere to suppress this.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1232
-
script_unit:set_invincible(booleanset invincible) -
Makes the subject unit invincible. This wraps an underlying code function, and also cancels any running process started for this unit with
script_unit:max_casualtiesorscript_unit:set_invincible_for_time_proportion.Parameters:
1
booleanset invincible
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1327
-
script_unit:set_invincible_for_time_proportion(time proportionnumber, [should releaseboolean]) -
Makes the subject unit invincible a proportion of the time. The intended effect is to slow the rate at which the unit receives casualties. Invincibility is toggled on and off over a five second interval, with the unit being invincible the specified proportion of time. The proportion is set as a unary
number, so supplying a value of0.8would make the unit invincible for four seconds out of every five.
Set a value of 0 to turn off any previous invincibility set with this function.Parameters:
1
Unary (0-1) time proportion over which this unit should be invincible.
2
optional, default value=false
Instructs the function to release script control of the unit after setting it to be invincible or otherwise. Set this to
trueif the scriptunit is player-controlled.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1337
-
script_unit:fearless_until_casualties(unaryproportion, [booleanshould release]) -
Prevents this unit from routing until it takes a certain proportion of casualties. If a proportion of 0 is supplied then any previous monitor set up with
fearless_until_casualtiesis cancelled and the unit is allowed to rout.Parameters:
1
unaryProportion of unit at which it may rout. Value should be expressed as a unary e.g. 0.5 = 50% casualties.
2
booleanoptional, default value=false
Set to true to release script control of this unit after
fearless_until_casualtiesmakes a change. Set this primarily if the unit is under player control.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1421
-
script_unit:rout_on_casualties(unary proportionnumber, [set invincibleboolean]) -
Forces this unit to rout when it reaches a certain proportion of casualties. If a proportion of 0 is supplied then any previous monitor set up with
rout_on_casualtiesis cancelled.Parameters:
1
Proportion of unit hitpoints remaining at which it routs. Value should be expressed as a unary e.g. 0.6 = unit will rout when its health gets below 60%.
2
optional, default value=false
Makes the unit invincible when it routs, so that it's guaranteed to survive.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1464
-
script_unit:invincible_if_standing([booleanshould release]) -
Makes the subject unit invincible/fearless if it's not already routing.
Parameters:
1
booleanoptional, default value=false
Set to true to release script control of this unit after
invincible_if_standingmakes a change. Set this primarily if the unit is under player control.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1518
-
script_unit:prevent_rallying_if_routing(check perpetually
[boolean],shattered only
[boolean],permit rampaging
[boolean]
) -
Prevents the subject unit from rallying if it's already routing. Supply
trueas a single argument to start a monitor that will continually poll whether this unit is routing, and prevent itParameters:
1
booleanoptional, default value=false
Check perpetually. If false or no value is supplied here, the function will only check the unit's routing state once, at the time the function is called. If the unit is not routing at this time, it may later rout and subsequently rally.
If true is supplied instead, the function sets up a monitor that will continually poll the unit's routing status and, when found to be routing, prevents it from rallying at that time.
2
booleanoptional, default value=false
Only count shattered units
3
booleanoptional, default value=false
Don't automatically count rampaging units, check if they are actually routing too.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1533
-
script_unit:stop_prevent_rallying_if_routing() -
Stops any running monitor started by
script_unit:prevent_rallying_if_routing.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1565
-
script_unit:morale_behavior_fearless() -
Sets this unit to be fearless/unroutable. This is an unembellished wrapper for an underlying code function.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1572
-
script_unit:morale_behavior_rout() -
Causes this unit to instantly rout. This is an unembellished wrapper for an underlying code function.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1579
-
script_unit:morale_behavior_default() -
Causes this unit to be subject to normal morale. This is an unembellished wrapper for an underlying code function.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1586
-
script_unit:morale_behavior_fearless_if_standing([booleanshould release]) -
Makes the subject unit fearless if it's not already routing.
Parameters:
1
booleanoptional, default value=false
Set to true to release script control of this unit after
morale_behavior_fearless_if_standingmakes a change. Set this primarily if the unit is under player control.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1593
-
script_unit:morale_behavior_default_if_standing([booleanshould release]) -
Makes the subject unit fearless if it's not already routing.
Parameters:
1
booleanoptional, default value=false
Set to true to release script control of this unit after
morale_behavior_default_if_standingmakes a change. Set this primarily if the unit is under player control.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1607
-
script_unit:hide_unbreakable_in_ui(hide unbreakable stateboolean) -
Calls
unitcontroller:hide_unbreakable_in_uito prevent or allow the UI to show that this unit is unbreakable. This is useful for scripted content which is altering whether a unit can rout or not but doesn't want this to be reflected on the user interface.Parameters:
1
hide unbreakable state
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1621
-
script_unit:kill([booleanshould disappear]) -
Instantly kills this unit.
Parameters:
1
booleanoptional, default value=false
Set to true to make the unit instantly disappear, instead of appearing to drop dead on the spot.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1643
-
script_unit:kill_proportion(numberproportion, [numberpreserve proportion], [booleanhide bodies]) -
Instantly kills a unary proportion of this unit.
Parameters:
1
numberProportion to kill, expressed as a unary value (e.g. 0.5 = 50% of the unit's starting number of soldiers die).
2
numberoptional, default value=0
Prevents kill_proportion from reducing the strength of the unit below a specified unary proportion.
3
booleanoptional, default value=false
Hides the bodies.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1654
-
script_unit:kill_proportion_over_time(numberproportion, numberduration, [booleanstop on rout]) -
Kills a unary proportion of this unit over a specified time period in ms.
Parameters:
1
numberProportion to kill, expressed as a unary value (e.g. 0.5 = 50% of the unit's starting number of soldiers die).
2
numberDuration in ms over which to kill soldiers.
3
booleanoptional, default value=false
Stops the function from killing any more soldiers if the unit routs during the process.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1682
-
script_unit:stop_kill_proportion_over_time() -
Stops a running process started by
script_unit:kill_proportion_over_time.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1735
-
script_unit:get_enemy_alliance_num() -
Gets the enemy alliance number.
Returns:
enemy alliance numbernumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1754
-
script_unit:get_enemy_alliance() -
Gets the enemy alliance object.
Returns:
enemy alliancebattle_alliance
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1762
-
script_unit:highlight_unit_card(booleanshould highlight, [numberpulse strength], [booleanforce highlight]) -
Pulses a highlight effect on the unit card associated with this scriptunit.
Parameters:
1
booleanSet to
trueto turn the highlight effect on,falseto turn it off.2
numberoptional, default value=5
Sets the strength of the pulse effect. A higher supplied value leads to a more pronounced pulse effect. The default value is 5.
3
booleanoptional, default value=false
Overrides the disabling of help page highlighting with
battle_ui_manager:set_help_page_link_highlighting_permitted. Set this to true if the script explicitly wants to highlight the UI cards when help page link highlighting is disabled (useful in tutorials).Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1782
-
script_unit:add_ping_icon(icon_type Type of icon to add. This is a numeric index.
[number],duration
[number]
) -
Adds a ping icon above the unit, optionally for a duration.
Parameters:
1
numberoptional, default value=8
icon_type Type of icon to add. This is a numeric index.
2
numberoptional, default value=nil
Duration in ms.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1847
-
script_unit:remove_ping_icon() -
Removes a ping icon from above the unit added with
script_unit:add_ping_icon.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1887
-
script_unit:start_attack_closest_enemy([intervalnumber], [debugboolean]) -
Instructs this scriptunit to attack the closest enemy unit under full script control. This process will continually re-acquire the closest enemy target every interval and instruct the unit to attack. The process repeats until the unit is shattered, dead, or until
script_unit:stop_attack_closest_enemyis called.Parameters:
1
optional, default value=10000
Repeating interval in milliseconds after which the scriptunit re-acquires the closest enemy target.
2
optional, default value=false
Shows debug output about what this unit is attacking.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1937
-
script_unit:stop_attack_closest_enemy([reasonstring]) -
Stops any running attack closest enemy process that was started with
script_unit:start_attack_closest_enemy. An optional string reason may be supplied which is printed as debug output.Parameters:
1
optional, default value=nil
reason
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 1967
Variables in this section:
These variables may be accessed via <interface>.<variable_name>:
| unit |
battle_unit
|
object representing the subject unit. |
| uc |
battle_unitcontroller
|
unitcontroller object that controls the unit. |
| start_position |
battle_vector
|
Vector position the unit started the battle at. |
| start_bearing |
number
|
Bearing in degrees the unit started the battle at. |
| start_width |
number
|
Width in m of the unit at the start of the battle. |
Scriptunits
A Scriptunits collection is a container for script_unit objects. There are a couple of advantages to assembling a script_units collection object instead of just a throwing them into a single table:
- The collection object provides additional functionality that can only be provided on a number of scriptunits (e.g.
script_units:rout_over_time). - Calls made to the scriptunits collection that are not recognised as function calls on the collection object are instead passed through and that same call is made on each script unit the collection contains. For example, setting a behaviour active on a scriptunits collection sets it active on all the scriptunits within that collection.
-
script_units:new(stringname, ...scriptunits) -
Creates a new script units collection.
Parameters:
1
stringName for this script_units collection. Will be used for debug output.
2
...One or more
script_unitobjects to add to the collection. Note that a scriptunit can be a member of multiple script_units collections at the same time.Returns:
script_units
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2096
-
script_units:set_debug([booleandebug mode]) -
Sets the scriptunits collection into debug mode, for more output.
Parameters:
1
booleanoptional, default value=true
debug mode
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2137
-
script_units:add_sunits(...additional script units) -
Adds one or more supplied
script_unitobjects to this scriptunits collection.Parameters:
1
...additional script units
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2160
-
script_units:merge(other script unitsscript_units) -
Copies all
script_unitobjects associated with a suppliedscript_unitscollection into this script units collection.Parameters:
1
other script units
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2204
-
script_units:remove_sunit(script_unitscriptunit to remove) -
Removes a supplied
script_unitobject from this scriptunits collection.Parameters:
1
script_unitscriptunit to remove
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2216
-
script_units:remove_sunits(...script_unit list) -
Removes one or more supplied
script_unitobjects from this scriptunits collection.Parameters:
1
...scriptunits to remove
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2236
-
script_units:get_sunit_by_name(valuereference) -
Returns a
script_unitfrom this script_units collection that matches the supplied referencenumberorstring.nilis returned if no matching script_unit is found.Parameters:
1
valueReturns:
matching name, orscript_unitnil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2285
-
script_units:get_sunit_for_unit(unitbattle_unit) -
Returns a
script_unitfrom this script_units collection that contains the suppliedbattle_unit.nilis returned if no matching script_unit is found.Parameters:
1
unit
Returns:
matching unit, orscript_unitnil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2299
-
script_units:get_sunit_by_type(unit typestring) -
Returns the first
script_unitin this script_units collection that contains abattle_unitof the supplied type.nilis returned if no matching script_unit is found.Parameters:
1
Unit type, from the
main_unitstable.Returns:
matching unit, orscript_unitnil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2313
-
script_units:count() -
Returns the number of
script_unitobjects in this script_units collection.Returns:
number of unitsnumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2327
-
script_units:item(index valuenumber) -
Returns the
script_unitin this collection at the supplied index.Parameters:
1
index value
Returns:
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2335
-
script_units:contains(objectobject) -
Returns whether the script units collection contains the supplied object. Supported object types are
script_unit,battle_unitandbattle_unitcontroller.Parameters:
1
objectObject to test - supported types are
script_unit,battle_unitandbattle_unitcontroller.Returns:
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2351
-
script_units:get_sunit_table() -
Returns the internal table containing all the
script_unitobjects in thisscript_unitscollection. Be aware that modifications to this table will also modify this script_units object.Returns:
of script_unit objectstable
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2385
-
script_units:get_unit_table() -
Returns a table containing all
battle_unitobjects contained within thisscript_unitscollection. The table that's returned is built each time this function is called, so be wary of calling this function too often.Returns:
oftablebattle_unitobjects
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2393
-
script_units:filter(namestring,testfunction, [assert if emptyboolean], [max sizenumber]) -
Returns another scriptunits collection containing all
script_unitobjects from the subject collection that pass the supplied test. The test should be supplied as a function that takes a scriptunit parameter and returns a boolean value. Should a call to the function with a specific scriptunit return true, that scriptunit will be added to the returned collection.Parameters:
1
Name for the returned scriptunits collection
2
Function that takes a scriptunit parameter and returns a boolean value.
3
optional, default value=false
If set to true,
filtertriggers a script assert if the returned collection is empty.4
optional, default value=nil
Maximum number of units to add to the returned scriptunit collection.
Returns:
filtered scriptunits collectionscript_units
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2407
-
script_units:sort(filter functionfunction) -
Sorts the internal list of
script_unitobjects based on the supplied filter function. The filter function should take twoscript_unitarguments and returntrueif the first should be sorted before the second, andfalseotherwise.table:sortis used to perform the operation.Parameters:
1
filter function
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2448
-
script_units:out() -
Prints the list of
script_unitobjects this collection contains to the debug console spool.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2460
-
script_units:duplicate(namestring) -
Returns a duplicate
script_unitscollection with the supplied name.Parameters:
1
name
Returns:
duplicate collectionscript_units
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2475
-
script_units:get_unitcontroller([armybattle_army]) -
Returns a unitcontroller with control over all the units this
script_unitscollection contains.Parameters:
1
optional, default value=nil
If an army is supplied here, the function will only add units that belong to that army and ignore any that don't.
If no army is supplied, the function assumes that all units in the scriptunits collection are in the same army, and will assert if any aren't.
Returns:
unitcontrollerbattle_unitcontroller
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2499
-
script_units:num_generals() -
Returns the number of commanding general units the scriptunits collection contains.
Returns:
number of generalsnumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2536
-
script_units:get_general_sunit([general indexnumber]) -
Returns a commanding general scriptunit from the scriptunits collection. By default the first general scriptunit is returned. An index value may be given to specify a particular general to return.
Parameters:
1
optional, default value=1
general index
Returns:
number of generalsscript_unit
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2550
-
script_units:centre_point() -
Returns a vector corresponding to the mean centre position of all the
script_unitobjects in the collection.Returns:
centre positionbattle_vector
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2588
-
script_units:radius() -
Returns the distance from the furthest unit from the centre, to the centre, which is an indication of how spread out the units in this collection are.
Returns:
radiusnumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2596
-
script_units:width() -
Returns the current cumulative width of all units in the collection in metres.
Returns:
combined widthnumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2616
-
script_units:average_bearing() -
Returns the average ordered bearing of all units in the collection, in degrees.
Returns:
average bearingnumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2628
-
script_units:get_northernmost() -
Returns the northern-most
script_unit.Returns:
script_unit
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2644
-
script_units:get_southernmost() -
Returns the southern-most
script_unit.Returns:
script_unit
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2663
-
script_units:get_westernmost() -
Returns the western-most
script_unit.Returns:
script_unit
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2682
-
script_units:get_easternmost() -
Returns the eastern-most
script_unit.Returns:
script_unit
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2701
-
script_units:get_closest(objectposition collection, [2donly]) -
Returns the closest
script_unitin this collection to the supplied collection of units/positions, as well as the distance in m.Parameters:
1
objectPosition object or collection. Supported object types are vector, unit,
script_unit, units,script_units, army, armies, alliance or table.2
2doptional, default value=false
consider 2D distance only (disregarding altitude)
Returns:
script_unitclosest scriptunitdistancedistance of closest scriptunit in mobjectclosest foreign object from the supplied object - either abattle_vector, abattle_unitor ascript_unit, depending upon the container type.
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2720
-
script_units:get_furthest(objectposition collection, [2donly]) -
Returns the furthest
script_unitin this collection from the supplied collection of units/positions, as well as the distance in m.Parameters:
1
objectPosition object or collection. Supported object types are
battle_vector,battle_unit,script_unit,battle_units,script_units,battle_army,battle_armies,battle_allianceortable.2
2doptional, default value=false
consider 2D distance only (disregarding altitude)
Returns:
script_unitfurthest scriptunitdistancedistance of furthest scriptunit in m
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2816
-
script_units:get_centremost() -
Returns the
script_unitin the collection that is closest to the calculated centre.Returns:
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2902
-
script_units:get_outlying() -
Returns the furthest
script_unitin this collection from the mean centre.Returns:
script_unit
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2910
-
script_units:are_any_routing_or_dead([booleanshattered only], [booleanpermit rampaging]) -
Returns
trueif any unit in this scriptunits collection is routing or dead, orfalseotherwise.Parameters:
1
booleanoptional, default value=false
Only count shattered units.
2
booleanoptional, default value=false
Don't automatically count rampaging units, check if they are actually routing too.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2963
-
script_units:are_all_routing_or_dead([booleanshattered only], [booleanpermit rampaging]) -
Returns
trueif all units in this scriptunits collection are routing or dead, orfalseotherwise.Parameters:
1
booleanoptional, default value=false
Only count shattered units.
2
booleanoptional, default value=false
Don't automatically count rampaging units, check if they are actually routing too.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2978
-
script_units:rout_over_time(numberperiod in ms) -
Prevents routing units within the collection from rallying, and routs all non-routing units over the specified period in ms so that all units are eventually routing.
Parameters:
1
numberTime in ms over which the units are routed. Must be positive.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 2987
-
script_units:teleport_withdraw_over_time(numberperiod in ms) -
Teleports units over the specified period in ms so all units eventually withdraw
Parameters:
1
numberTime in ms over wich the units are teleported away. Must be positive.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3029
-
script_units:have_any_deployed() -
Have any of the
script_unitobjects in the collection deployed onto the battlefield.Returns:
any deployedboolean
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3078
-
script_units:have_all_deployed() -
Have all of the
script_unitobjects in the collection deployed onto the battlefield.Returns:
all deployedboolean
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3094
-
script_units:num_deployed() -
Returns the number of
script_unitobjects in the collection that are currently deployed onto the battlefield.Returns:
number deployednumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3110
-
script_units:are_any_active_on_battlefield() -
Returns true if any
script_unitin this collection is deployed on the battlefield and not routing or dead.Returns:
any activeboolean
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3126
-
script_units:have_any_moved([vectorposition], [distancethreshold distance]) -
Returns true if
script_unit:has_movedreturns true for any unit in this collection. Callscript_unit:cache_location() first to set a position from which each unit's distance is tested.Parameters:
1
vectoroptional, default value=nil
Position to test against. May be of limited usefulness when testing multiple units like this.
2
distanceoptional, default value=0
Threshold distance in m.
Returns:
have any movedboolean
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3156
-
script_units:num_moved([vectorposition], [distancethreshold distance]) -
Returns the number of units in this collection that have moved when tested with
script_unit:has_moved. Callscript_unit:cache_location() first to set a position from which each unit's distance is tested.Parameters:
1
vectoroptional, default value=nil
Position to test against. May be of limited usefulness when testing multiple units like this.
2
distanceoptional, default value=0
Threshold distance in m.
Returns:
Number that have movednumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3174
-
script_units:have_all_moved([vectorposition], [distancethreshold distance]) -
Returns true if
script_unit:has_movedreturns true for all units in this collection. Callscript_unit:cache_location() first to set a position from which each unit's distance is tested.Parameters:
1
vectoroptional, default value=nil
Position to test against. May be of limited usefulness when testing multiple units like this.
2
distanceoptional, default value=0
Threshold distance in m.
Returns:
booleanhave all moved
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3192
-
script_units:are_any_running() -
Returns true if any
script_unitin this collection is moving fast.Returns:
booleanany running
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3210
-
script_units:are_all_running() -
Returns true if all
script_unitobjects in this collection are moving fast.Returns:
booleanany running
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3226
-
script_units:is_under_attack() -
Returns true if any
script_unitin this collection is under attack (usesscript_unit:is_under_attack)Returns:
booleanany under attack
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3242
-
script_units:is_in_melee() -
Returns true if any
script_unitin this collection is in melee combat (usesscript_unit:is_in_melee).Returns:
booleanany in melee
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3258
-
script_units:unary_hitpoints([shattered considered deadboolean]) -
Returns the average unary hitpoints of all
script_unitobjects in this collection.Parameters:
1
optional, default value=false
Shattered units (or units that have routed and left the field) are considered dead, with 0 hitpoints.
Returns:
average hitpointsnumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3274
-
script_units:number_of_enemies_killed() -
Returns the total number of enemies killed by all units in this collection.
Returns:
total enemies killednumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3294
-
script_units:disordered_teleport(target position
battle_vector,radius in m
number,release control
[boolean]
) -
Performs a disordered teleport of all units contained within this collection to within a radius around a position, both supplied. A disordered teleport preserves the current orientation and width of each unit, but teleports them within the radius of the position if they're not already inside.
The function is intended to assist in transitions between different sections of gameplay within a heavily scripted battle. We may wish for the player to start the latter section with their troops in unformed order, akin to where they were at the end of the previous section, but to ensure that none of the player's forces are too far away from a known position (i.e. where we'd like them to start the latter section of gameplay).
Script control of the teleported units is automatically released after this function is called.Parameters:
1
target position
2
radius in m
3
optional, default value=false
release control
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3322
-
script_units:respawn_in_start_location([only if deadboolean], [debug outputboolean]) -
Respawns the units in the collection at the locations they started the battle. This resets their health, fatigue, casualties and other stats.
Parameters:
1
optional, default value=false
Respawn each unit only if it is dead, or if it has routed off the battlefield.
2
optional, default value=false
Produce debug output about which units have been respawned.
Returns:
number respawnednumber
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3371
Changing formation won't work unless all script_unit objects in the collection are in the same army (which is recommended anyway).
-
script_units:change_formation(stringgroup formation name) -
Sets all
script_unitobjects in the collection into a group formation.
A list of formations can be found in raw data. Valid entries at time of writing are:
- flanking
- generic_directfire_defence
- generic_directfire_attack
- generic
- generic_ranged_protected
- generic_melee_heavy
- generic_melee_super_heavy
- assault_gates_formation
- assault_reserves_formation
- Multiple Selection Drag Out Land
- Multiple Selection Deployable Drag Out Land
- single_line
- Multiple Selection Naval
- Ambush Defence Block
- test_melee_forward_simple
- test_missile_forward_simple
- river_ai_attack
- river_ai_attack_narrow
- river_ai_stop_and_shoot
- river_ai_defend
- stop_and_shoot_artillery
- stop_and_shoot_ranged_direct
Parameters:
1
stringgroup formation name
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3432
-
script_units:is_hidden([booleanall units]) -
Returns true if any
script_unitin this collection is hidden in long grass or trees. Iftrueis supplied as a single argument, then all units in the collection must be hidden for the function to return true.Parameters:
1
booleanoptional, default value=false
all units
Returns:
booleanis hidden
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3480
-
script_units:is_visible_to_enemy() -
Returns true if any
script_unitin this collection is visible to the enemy, by the rules of the terrain visibility system. Note that a unit can be considered visible by this system but still be hidden in forests.Returns:
booleanis visible
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3509
-
script_units:deploy_at_random_intervals(min units
number,max units
number,min period
number,max period
number,debug out
[boolean],spawn immediately
[boolean],allow respawning
[boolean],new wave callback
[function]
) -
Deploys the units in this collection onto the battlefield in randomly-sized, randomly-timed batches. Units must have been scripted to not deploy automatically before this is called. Arguments can be used to influence the size and timing of the batches of units.
Parameters:
1
Minimum size of random unit batch. Must be postive.
2
Maximum size of random unit batch. Must be positive, and not less than the supplied min units value.
3
Minimum time period between the arrival of batches in ms. Must be positive.
4
Maximum time period between the arrival of batches in ms. Must be positive, and not less than the supplied minimum period.
5
optional, default value=false
Supply true to turn on debug output.
6
optional, default value=false
Spawns the first wave immediately.
7
optional, default value=false
Allows units to be respawned and deployed again.
8
optional, default value=nil
Callback to call when a new wave in deployed. A
tablecontaining a list ofscript_unitobjects representing the units being deployed will be passed to the callback when it is called.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3534
-
script_units:cancel_deploy_at_random_intervals() -
Cancels/stops a running process started with
script_units:deploy_at_random_intervals.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3674
-
script_units:start_kill_aura(script_unitstarget sunits, numberrange, [numbercasualties proportion]) -
Activates a kill aura around these units that cause a specified enemy/other
script_unitsto take casualties when they come within a specified range. Only one kill aura process may be active on a scriptunit at a time.Parameters:
1
script_unitsTarget
script_unitscollection.2
numberRange in m at which the enemy
script_unitsbegin to take casualties.3
numberoptional, default value=0.02
Proportion of casualties taken per second. This should be specified as a unary proportion of the unit's initial strength, so the default value of 0.02 represents 2% of the initial strength per second.
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3693
-
script_units:stop_kill_aura() -
Stops the kill aura started on this collection with
script_units:start_kill_aura.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3740
-
script_units:attack_enemy_scriptunits(script_unitsenemy script_units, [booleanshould run]) -
Instructs this scriptunits collection to attack another, acting entirely under script control. This is best used for a close-quarters scripted engagement where no AI randomness or maneouvring is desired.
Parameters:
1
script_unitsenemy script_units
2
booleanoptional, default value=false
should run
Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3759
-
script_units:stop_attack_enemy_scriptunits() -
Stops an attack process started with
script_units:attack_enemy_scriptunits.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3911
-
script_units:highlight_unit_cards(should highlight
boolean,pulse strength
[number],force highlight
[boolean]
) -
Pulses a highlight effect on all the unit cards associated with this scriptunits collection, using
script_unit:highlight_unit_card.Parameters:
1
booleanSet to
trueto turn the highlight effect on,falseto turn it off.2
numberoptional, default value=5
Sets the strength of the pulse effect. A higher supplied value leads to a more pronounced pulse effect. The default value is 5.
3
booleanoptional, default value=false
Overrides the disabling of help page highlighting with
battle_ui_manager:set_help_page_link_highlighting_permitted. Set this to true if the script explicitly wants to highlight the UI cards when help page link highlighting is disabled (useful in tutorials).Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3933
The functions in this section allow scripts to save or apply a serialised state from the scriptedvalueregistry, across campaign and battle. This allows battle script to apply health values to units that were set in campaign, or vice-versa. This is chiefly useful for scripted battles that are launched from campaign but are logically actually nothing to do with that campaign, such as a tutorial battle xml loaded from a campaign as if it was a campaign-generated battle. Using this functionality the battle scripts would be able to spoof the approximate health of the army as if it were coming from campaign, and then pass it back to campaign on battle completion.
Campaign scripts can use campaign_manager:save_army_state_to_svr and campaign_manager:load_army_state_from_svr to save and load army states, and in battle script_units:save_state_to_svr and script_units:load_state_from_svr can be used to do the same.
Note that at present this only serialises the health state of units and not their experience, items carried etc.
-
script_units:serialise_state() -
Returns a
stringwhich represents the serialised state of this script_units collection. This does not embody the full model state of the units but only selected information. It is mainly intended for use byscript_units:save_state_to_svrwhich will save the returned string into the scripted value registry. This string can then be loaded bycampaign_manager:load_army_state_from_svr, allowing campaign scripts to spoof the results from a scripted battle that occurs mid-campaign flow.Returns:
serialised statestring
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3961
-
script_units:save_state_to_svr(namestring) -
Saves a
stringwhich represents the serialised state of this script_units collection to the scripted value registry.script_units:serialise_stateis used to generate the state string, andcore:svr_save_stringis used to save the string. This is for use by scripts that wish to pass the state of an army, usually at the end of a battle, from battle script to campaign script, usually so that the latter can spoof the battle results in script. The functioncampaign_manager:load_army_state_from_svrcan be used on the campaign-side to load the values saved by this string.Parameters:
1
Name for this svr entry, to be passed to
core:svr_save_string.Returns:
nil
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3983
-
script_units:load_state_from_svr(namestring, [allow partialboolean]) -
Checks for a
scriptedvalueregistrystring with the supplied name, and attempts to apply the health values it contains to the units in this script_units collection. These svr strings would be set by eithercampaign_manager:save_army_state_to_svrin campaign orscript_units:save_state_to_svrin battle.
This is primarily intended to spoof casualties on a battle army that is coming from campaign, but where the army in battle is not logically related to that campaign army (for example, when loading from a campaign into a scripted xml battle).
The function returns whether the application was successful. A successful application is one that modifies all units in the script_units collection (a "modification" from 100% health to 100% health would count), unless theallow_partialflag is set, in which case even a partial application would be considered successful. If the application is not successful then no changes are applied. Output is generated in all cases.Parameters:
1
Name of string saved in the
scriptedvalueregistry.2
optional, default value=false
Allow a partial application of the state string. If this is set to
trueReturns:
state was applied successfullyboolean
defined in ../../warhammer/working_data/script/_lib/lib_battle_script_unit.lua, line 3998