Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

message (1)

This document outlines the Easy Red 2 Scripting System, which allows users to create custom game modes and AI behaviors using Lua scripts. It provides guidelines on writing efficient scripts, managing mission phases, and controlling AI and soldier actions, emphasizing the use of global variables to maintain state across host migrations. Additionally, it details specific Lua functions available in the Easy Red 2 API for manipulating AI behavior and game elements.

Uploaded by

vianneyjrcuerda
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

message (1)

This document outlines the Easy Red 2 Scripting System, which allows users to create custom game modes and AI behaviors using Lua scripts. It provides guidelines on writing efficient scripts, managing mission phases, and controlling AI and soldier actions, emphasizing the use of global variables to maintain state across host migrations. Additionally, it details specific Lua functions available in the Easy Red 2 API for manipulating AI behavior and game elements.

Uploaded by

vianneyjrcuerda
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 36

Additional Context:

This Lua script is intended for the Easy Red 2 videogame. The script must be
written in basic Lua and may only use the Easy Red 2 custom functions.
The scripts need to be very performant and have high delay sleep() calls in loops.
If waypoints, string ids (like loadouts, items and vehicles) are given, please
declare them in variables at the beginning of the lua code along with appropriate
comments wrapping the editable section to make it easier for the user to edit them.
Don't use commands that are either not part of the Easy Red 2 scripting API
documentation or builtin MoonSharp Lua instructions. Also if something doesn't seem
to be possible with avalable apis, simply explain why. Also be short in answer to
provide a faster reply.

This script is intended to run on an AI, so it will be executed through a script


injection in the Unit Spawner or by assigning this script to the AI with the
setBrain call. In case of host migration this AI will be transferred to the new
host and the code will run again, so if necessary make sure to use global.set and
global.get to check variables to avoid redundant initialization of the AI. Remember
that AI script can also make use of myself() to access its own class functions.

Overview

The Easy Red 2 Scripting System is an optional add-on that allows you to
create new game modes and customize missions as well as AI and soldier behaviors.
It works alongside the default Mission Editor and enables you to:

Script mission phases to create new objective types (e.g., destroy a


specific vehicle, eliminate a particular unit, reach a destination, trigger
explosions, etc.).
Script soldiers and AIs to control behavior, disable functionalities, force
actions, or even trigger in-game dialogue.

The system leverages Lua, meaning you have access to all standard Lua
features like tests, loops, functions, and conditions. For general Lua language
documentation, please refer to the
Lua Documentation.

For Easy Red 2–specific Lua commands and further examples, check out our
dedicated scripting wiki.

Important Tools

While making your scripts, you might need some extra data to use in your
scripts such as Ids to spawn vehicles, acquire vanilla loadouts, spawn items,
acquire vanilla and modded factions.
You can acquire string Ids from the Id tables section in the Script
Settings. By selecting any object you'll copy it's Id into the clipboard.
You might also need to acquire 3D world positions. You can copy a vec3(...)
world position for lua code by pressing P.A vec3(...) position will be acquired
from cursor position and copied into the clipboard to use it in your code.

Scripting Mission Phases

It is possible to run a script at the beginning of each mission phase. The


script starts executing when the phase begins and is interrupted when a new phase
starts or when it has finished executing. If a previously run phase is started
again, the script will run once more.

Within the Mission Editor UI, you will find a script button:

Clicking this button opens a code editor that allows you to edit the script
for the current phase. To save your changes, simply close the editor by clicking
the red cross:

Additionally, scripts are stored in a dedicated subfolder of the mission


folder. This allows you to edit them using an external code editor if you prefer:

When playing offline, your machine runs all the scripts. In online matches,
the phase script runs on the master client only, although most scripting commands
generate actions synchronized across all players.

Note: If the master client leaves, a new one is assigned and the phase
script will run from the beginning on that machine. For this reason, it is
recommended to use the global class to set global variables that keep track of the
phase state, ensuring that operations already performed are not unnecessarily
repeated.

Below is an example of a mission phase script:

-- Mission Phase Script Example


-- check if a certain "target_spawned" global boolean variable have been set
already;
-- If not, then the script is running for the first time in this phase
-- and we want to do the initialization actions, like spawning targets
if not global.get("targets_spawned") then
print("Spawning targets to eliminate...")
-- Perform targets spawn operations here ...

-- Next, set the "targets_spawned" to true,


-- so if this script will run again* we know that this action has performed.
global.set(true, "targets_spawned")

-- *Why could the script run again?


-- Phase script is executed every time the phase starts (or re-start)
-- or whenever the host has changed
end

-- Example of main phase loop


local phaseCompleted = false
while not phaseCompleted do
sleep(3) -- always recommended to put some wait time on every loop!

if checkTargetsStillAlive() then -- dummy function


phaseCompleted = true
end
end

--loop is done so continue with next phase...


er2.nextPhase()

Scripting AI & Soldier Behavior

In addition to mission phases, you can script the behavior of AI and


soldiers. This is done through the Script Editor where you can create, edit, and
delete AI scripts.

In the Script Editor, navigate to the Script Settings menu:

AI scripts can be assigned in two ways:

Assign via Squad Spawner: When a script is assigned to a squad spawner,


it is automatically injected into every AI unit of that squad.

Manual Assignment: You can also assign a script via Lua code when
spawning a unit in a mission phase script.

For example, you might assign an AI script manually like this:

-- AI Script Assignment Example


--spawn an unit
local aiUnit = spawnSoldier(vec3(10,0,10), "England_allies", 0,
"eng_infantry_gunner")

if aiUnit then
-- give the unit some lua script
aiUnit.setBrain("ai_patrol.lua")
end

Note that the Id "eng_infantry_gunner" (and other vanilla loadout Ids) and
the Faction Id "England_allies" (and other vanilla and modded squad Ids) can be
acquired trough the Id tables section in the Script Settings menu.

AI scripts run locally on the owner’s machine. When using a squad spawner,
the entire squad is owned by you so the script executes on your computer. However,
AI squads are ultimately managed by the master client – including their Lua
scripts.

Important: If a player leaves an online match, their units (and associated


scripts) transfer to the master client, where the scripts will restart. It is
therefore recommended to use the global class to verify whether certain operations
should be skipped on a fresh run.

Like phase scripts, AI scripts are stored in their own subfolder within the
mission folder, making them accessible for external editing.

A notable feature in soldier scripts is the myself() function, which


returns a reference to the Soldier class instance running the script. This allows
you to call specific soldier functions directly.

For example, a soldier script might look like this:

-- Get the unit which is running this script


local soldier = myself()

-- Make the unit play the VoiceClip.scream_long clip every 5 seconds while being
alive
while sold.isAlive() do
sold.say(VoiceClip.scream_long)
sleep(5)
end
Easy Red 2 Scripting API:
---
Function: allowBeingTargeted (Class: AiParams)
Description: If enabled, enemies will target this soldier whenever they see him. If
disabled, the soldier will be completly ignored by enemies.
Toghether with allowCheckForEnemies, this function is helpful to script systems
like Civilian or Non combatant medics.
Parameters:
- set_enabled (bool)
Examples:
myself().getAiParams().allowBeingTargeted(false) -- prevents enemy from targeting
this unit

---
Function: allowChangePose (Class: AiParams)
Description: When enabled, AI will change pose depending on cover, suppression and
other situations. Disable this function if you want to control soldier's pose by
custom scripting
Parameters:
- set_enabled (bool)
Examples:
myself().getAiParams().allowChangePose(false) -- prevents AI to automatically
switch pose

---
Function: allowCheckForEnemies (Class: AiParams)
Description: When enabled, AI will check for enemies around and target them. When
this function is disabled AI will not search and target enemies. Useful for custom
AI implementations
Parameters:
- set_enabled (bool)
Examples:
myself().getAiParams().allowCheckForEnemies(false) -- prevents AI to
automatically target enemies

---
Function: allowDoMedic (Class: AiParams)
Description: When this function is enabled, if a soldier has medic equipments in
his inventory he will proceed to heal nearby units
Parameters:
- set_enabled (bool)
Examples:
-- prevents the AI from healing up nearby soldiers
myself().getAiParams().allowDoMedic(false)

---
Function: allowFindCoverWhenSuppressed (Class: AiParams)
Description: When enabled, AI will automatically find cover when suppressed. If you
want to move the AI trough custom scripting, you most likely want to disable this
feature
Parameters:
- set_enabled (bool)
Examples:
myself().getAiParams().allowFindCoverWhenSuppressed(false) -- prevents AI from
moving to a cover when under fire
---
Function: allowFollowOrders (Class: AiParams)
Description: When enabled, AI will automatically follow squad leader orders. If you
want to move this specific unit with your custom scripts, for example by using
Soldier.moveTo function, most likely you want this to be disabled
Parameters:
- set_enabled (bool)
Examples:
-- prevents AI from following squad orders. Ai will still follow commands such as
soldier.moveTo()
myself().getAiParams().allowFollowOrders(false)

-- move the AI to a custom positon


myself().moveTo(vec3(10,20,30))

---
Function: allowGiveOrders (Class: AiParams)
Description: When enabled, AI will automatically give orders to the squad if squad
leader. If you want to give orders to a squad with your custom scripts, for example
by using Squad.moveTo function, most likely you want this to be disabled
Parameters:
- set_enabled (bool)
Examples:
-- prevents AI from giving orders. useful if you want to give orders to a squad
by using Squad.moveTo or Squad.followLeader without AI squad leader overriding your
orders
myself().getAiParams().allowGiveOrders (false)

---
Function: allowLeaveVehicle (Class: AiParams)
Description: When enabled, AI will leave vehicle when necessary. If you want to
control which vehicle the AI should use or force an AI never to leave a vehicle,
you might want to disable this feature
Parameters:
- set_enabled (void)
Examples:
myself().getAiParams().allowLeaveVehicle(false) -- prevents AI from leaving a
vehicle on it's own

---
Function: allowMovements (Class: AiParams)
Description: When enabled, AI will perform move commands. if you don't want the AI
never to move, not even with moveTo commands, disable this feature
Parameters:
- set_enabled (bool)
Examples:
myself().getAiParams().allowMovements(false) -- prevents AI from moving (include
by using the .moveTo function)

---
Function: allowOpenWindows (Class: AiParams)
Description: When enabled, AI will open windows that blocks it's vision, for
example when in cover behind a window
Parameters:
- set_enabled (bool)
Examples:
myself().getAiParams().allowOpenWindows (false) -- prevents AI opening windows in
from of it
---
Function: allowRadioOrders (Class: AiParams)
Description: When enabled and if radioman, AI will communicate radio orders
requested by squad leader
Parameters:
- set_enabled (Weapon)
Examples:
myself().getAiParams().allowRadioOrders(false) -- prevents AI from following
leader request to call radio orders

---
Function: enableAiBehaviour (Class: AiParams)
Description: This function enables or disbales all AI functionalities toghether,
including:
allowChangePose, allowCheckForEnemies, allowFindCoverWhenSuppressed,
allowLeaveVehicle, allowMovements, allowOpenWindows, allowOrders and
allowRadioOrders
Parameters:
- set_enabled (bool)
Examples:
myself().getAiParams().enableAiBehaviour(false) -- disable multiple AI behaviours
all toghether

---
Function: followCustomDirectCommands (Class: AiParams)
Description: Disable various AI behaviors in order to prepare the soldier to follow
direct commands, such as soldier.moveTo()
Examples:
myself().getAiParams().followCustomDirectCommands()

---
Function: followCustomSquadOrders (Class: AiParams)
Description: Normally squad soldiers will automatically give the orders that they
cosndier the best according to the situation. This function disables various AI
behaviors in order to prepare the soldier to only follow and give custom squad
orders via code, such as squad.moveTo()
Returns: this function doesn't return anything
Examples:
myself().getAiParams().followCustomSquadOrders()

---
Function: setTargetPlanesOften (Class: AiParams)
Description: Enable this feature to force the AI to target planes, if closer than
any other spotted enemy
Parameters:
- set_enabled (bool)
Examples:
myself().getAiParams().setTargetPlanesOften(true) -- start targeting planes with
small arms way more often

---
Function: distance (Class: Base Functions)
Description: The distance between 2 Vector3 points in meters
Returns: The distance between 2 points in meters
Parameters:
- pos1 (vec3)
- pos2 (vec3)
Examples:
local soldierPos = someSoldier.getPosition()
local destPos = vec3(10,20,30)

local dist = distance(soldierPos, destPos)

print("Distance between soldier and position: "..dist)

---
Function: log (Class: Base Functions)
Description: Log some text in the F3 console. This helps a lot with testing custom
Lua code. press F3 to open the console and visualize the log
Parameters:
- text (string)
Examples:
log("My code worked so far!")

---
Function: print (Class: Base Functions)
Description: Display a message on the screen
Parameters:
- message (string)
- duration (float)
Examples:
print("Here's some text to show to the player!")

---
Function: round (Class: Base Functions)
Description: Round a number to a specific quantity to decimal points
Returns: Rounded value
Parameters:
- numberToRound (float)
- decimalPoint (integer)
Examples:
local num1 = 10.123456
local num2 = 3.141592

num1 = round(num1, 0) -- remove all decimal points


num2 = round(num2, 2) -- round up to the first 2 decimal points

print(num1) -- shows "10"


print(num2) -- shows "3.14"

---
Function: sleep (Class: Base Functions)
Description: Pause the execution of the LUA script for some time. Notice: this is
very helpful to give some pause to the CPU, expecially during 'while' and 'for'
loops
Parameters:
- waitTime (float)
Examples:
sleep(3)

---
Function: spawnHuman (Class: Base Functions)
Description: Spawn a new human without specific loadout or rank. Faction Ids can be
acquired in the Script Settings menu -> Id tables section
Returns: Reference to the spawned human
Parameters:
- position (vec3)
- faction_id (string)
Examples:
-- spawn a generic human with United States faction at 1,4,6
spawnHuman(vec3(1,4,6), "UnitedStates_axis")

---
Function: spawnSoldier (Class: Base Functions)
Description: Spawn an AI soldier. Faction Ids and loadout Ids can be acquired in
the Script Settings menu -> Id tables section
Returns: Reference to the spawned soldier
Parameters:
- position (vec3)
- faction_id (string)
- rank (integer)
- loadout (string)
Examples:
-- spawn a German soldier with leutenant rank at position 0,0,0
spawnSoldier(vec3(0,0,0), "Germany_axis", 8, "ger_infantry_tankcrew_leader")

---
Function: spawnSoldierOnVehicle (Class: Base Functions)
Description: Spawn an AI soldier on a vehicle. Faction Ids and loadout Ids can be
acquired in the Script Settings menu -> Id tables section
Returns: Reference to the spawned soldier
Parameters:
- position (vec3)
- faction_id (string)
- rank (integer)
- loadout (string)
- vehicle_reference (Vehicle)
Examples:
-- spawn a vehicle
local veh = spawnVehicle("JeepWillys", vec3(0,1.5,0), vec3(0,90,0))

-- spawn a unit onto that vehicle


local soldierToKill = spawnSoldierOnVehicle(vec3(6,0,2), "Germany_allies", 4, "",
veh)

---
Function: spawnVehicle (Class: Base Functions)
Description: Spawn a vehicle. Vehicle Ids can be acquired in the Script Settings
menu -> Id tables section
Returns: Reference to the vehicle
Parameters:
- vehicle_id (string)
- position (vec3)
- rotation (vec3)
Examples:
-- Spawn a basic vehicle
local vehicle1 = spawnVehicle("JeepWillys", vec3(0, 1.5, 0), vec3(0, 90, 0))
if vehicle1 then
print("Basic vehicle spawned!", 3)
end

---
Function: spawnVehicle_camo (Class: Base Functions)
Description: Spawn a vehicle with a specified camo. Vehicle Ids can be acquired in
the Script Settings menu -> Id tables section
Returns: Reference to the vehicle
Parameters:
- vehicle_id (string)
- position (vec3)
- rotation (vec3)
- camo_id (integer)
Examples:
-- Spawn a vehicle with a specified camo
local vehicle1 = spawnVehicle_camo("JeepWillys", vec3(0, 1.5, 0), vec3(0, 90, 0),
1)
if vehicle1 then
print("Basic vehicle spawned!", 3)
end

---
Function: spawnVehicle_camo_dest (Class: Base Functions)
Description: Spawn a vehicle with a specified camo and give it a destination. For
Auto-Transport vehicles, this is where units will be deployed. Vehicle Ids can be
acquired in the Script Settings menu -> Id tables section
Returns: Reference to the vehicle
Parameters:
- vehicle_id (string)
- position (vec3)
- rotation (vec3)
- camo_id (integer)
- destination (vec3)
Examples:
-- Spawn a vehicle with camo and destination
local vehicle1 = spawnVehicle_camo("JeepWillys", vec3(0, 1.5, 0), vec3(0, 90, 0),
1, vec3(50, 0, 50))
if vehicle1 then
print("Basic vehicle spawned!", 3)
end

---
Function: spawnVehicle_dest (Class: Base Functions)
Description: Spawn a vehicle and give it a destination. For Auto-Transport
vehicles, this is where units will be deployed. Vehicle Ids can be acquired in the
Script Settings menu -> Id tables section
Returns: Reference to the vehicle
Parameters:
- vehicle_id (string)
- position (vec3)
- rotation (vec3)
- destination (vec3)
Examples:
-- Spawn a vehicle with destination
local vehicle1 = spawnVehicle_camo("JeepWillys", vec3(0, 1.5, 0), vec3(0, 90, 0),
vec3(50, 0, 50))
if vehicle1 then
print("Basic vehicle spawned!", 3)
end

---
Function: waitForAny (Class: Base Functions)
Description: Pause the execution of the script until any of the given conditions
are met.
Parameters:
- conditions (function)
Examples:
-- get a soldier (uncomplete)
local soldierToKill1 = spawnSoldier(....)
local soldierToKill2 = spawnSoldier(....)

-- create a condition that waits for each them to die


local condition1 = function() return not soldierToKill1:isAlive() end
local condition2 = function() return not soldierToKill2:isAlive() end

-- wait for the condition to be true


waitUntil(condition1, condition2)

-- print result
print("One of the soldiers is is dead!")

---
Function: waitUntil (Class: Base Functions)
Description: Pause the execution of the script until one or multiple conditions are
met.
Parameters:
- condition (function)
Examples:
-- get a soldier (uncomplete)
local soldierToKill1 = spawnSoldier(....)

-- create a condition that waits for him to die


local condition1 = function() return not soldierToKill1:isAlive() end

-- wait for the condition to be true


waitUntil(condition1)

-- print result
print("Soldier is dead!")

---
Function: addInvadersTickets (Class: er2)
Description: Adds tickets to the current invaders faction.
Parameters:
- ticketsToAdd (integer)

---
Function: countDeceasedDefenders (Class: er2)
Description: Count how many defenders are deceased during the mission
Returns: Amount of deceased defenders

---
Function: countDeceasedInvaders (Class: er2)
Description: Count how many invaders are deceased during the mission
Returns: Amount of deceased invaders

---
Function: countLostVehiclesDefenders (Class: er2)
Description: Count how many defenders have been captured during the mission
Returns: Amount of prisoners. This doesn't include prisoners that have been freed

---
Function: countLostVehiclesInvaders (Class: er2)
Description: Count how many invaders have been captured during the mission
Returns: Amount of prisoners. This doesn't include prisoners that have been freed
---
Function: countPrisonersDefenders (Class: er2)
Description: Count how many vehicles have been lost by the defenders during the
mission
Returns: Amount of deceased lost vehicles

---
Function: countPrisonersInvaders (Class: er2)
Description: Count how many vehicles have been lost by the invaders during the
mission
Returns: Amount of deceased lost vehicles

---
Function: endPrecipitation (Class: er2)
Description: Stops the rain or the snow from falling in the map
Examples:
er2.endPrecipitation -- Will stop raining or snowing on the map

---
Function: explosion (Class: er2)
Description: Generates an explosion
Parameters:
- position (vec3)
- maxDamage (float)
- maxPenetration (float)
- radius (float)
Examples:
-- Get the AI soldier running this script
local soldier = myself()

-- Ensure the soldier is alive before proceeding


if soldier and soldier:isAlive() then
-- Wait 5 seconds
sleep(5)

-- Get the soldier's position


local pos = soldier:getPosition()

-- Create an explosion at the soldier's location


er2.explosion(pos, 100, 50, 5)
end

---
Function: findSoldier (Class: er2)
Description: Find a soldier from it's unique Id (network safe)
Returns: Soldier corresponding to the provided Id
Parameters:
- unique_id (integer)

---
Function: findVehicle (Class: er2)
Description: Find a vehicle from it's unique Id (network safe)
Returns: Vehicle corresponding to the provided Id
Parameters:
- unique_id (integer)

---
Function: getAllSoldiers (Class: er2)
Description: Get all alive soldiers.
Notice: After a new soldier spawns or dies, this function might get a few instant
before returning a correctly updated value.
Parameters:
- tableToFill (Table)
Examples:
--get a list of all soldiers in battle
local allSoldiers = {} -- Create an empty table.
er2.getAllSoldiers(allSoldiers); -- fill it with all soldiers currently alive

--print the name of each soldier


for key, soldier in pairs(allSoldiers) do
print("Name: "..soldier.getName())
end

---
Function: getAllVehicles (Class: er2)
Description: Get all vehicles around the map
Parameters:
- table_to_fill (Table)

---
Function: getBattleName (Class: er2)
Description: Returns the current battle's name
Returns: The current battle name

---
Function: getDistanceFromTerrain (Class: er2)
Description: Returns the distance between the given position and the terrain.
Returns: Important: if the given position is under the terrain, will return a
negative distance
Parameters:
- position (vec3)
- clampToWaterHeight (bool)

---
Function: getInvadersTicket (Class: er2)
Description: Returns the number of tickets left by the invaders
Returns: The current tickets left by the invaders

---
Function: getMapName (Class: er2)
Description: Returns the name of the map of the current battle
Returns: The name of the current battle's map

---
Function: getMyNickname (Class: er2)
Description: Get nickname of the local user
Returns: Nickname of the local user

---
Function: getNearestSoldier (Class: er2)
Description: Get nearest soldier to a specific location
Returns: Returns the nearest soldier, nil if nothing is found
Parameters:
- position (vec3)
- maxDistance (bool)
Examples:
--get nearest soldier to position 0,10,0 within 1km
local nearestSold = er2.getNearestSoldier(vec3(0,10,0), 1000);
--print the name of the soldier, if there was any
if not (nearestSold == nil) then
print("Name: "..nearestSold.getName())
end

---
Function: getNearestVehicle (Class: er2)
Description: Get nearest vehicle from a specific location
Returns: Nearest vehicle from a location, nil if any vehicle is found.
Parameters:
- position (vec3)
- radius (float)

---
Function: getNickname (Class: er2)
Description: Get nickname of an online player
Returns: Nickname of the player
Parameters:
- online_id (string)

---
Function: getPlayer (Class: er2)
Description: Find a reference to the Soldier controlled by the player
Returns: Reference to the Soldier controlled by the player. Null if any
Examples:
-- get a reference to the soldier controlled by the player
local player = er2.getPlayer()

--print name of the soldier controller by the player


print("Player's name: "..player.getName())

---
Function: getSoldiersInArea (Class: er2)
Description: Get all alive soldiers within a specific radius from a specific
position, ordered by the distance from the given position.
Notice: After a new soldier spawns or dies, this function might get a few instant
before returning a correctly updated value.
Returns: The script fills the Table given as parameter with the found soldiers,
indexing it from 1,...,n ordered by distance from the given position and returns
the filled table
Parameters:
- position (vec3)
- maxDistance (float)
- tableToFill (Table)
Examples:
--get a list of all soldiers arount pos 0,0,0 for 20 meters
local closeSoldiers = {} -- Create an empty table.
er2.getSoldiersInArea(vec3(0,0,0), 20, closeSoldiers); -- fill it with all soldiers
currently alive

--print the name of each soldier


for key, soldier in pairs(closeSoldiers) do
print("Name: "..soldier.getName())
end

---
Function: getTerrainHeight (Class: er2)
Description: Returns the terrain height from sea level of the given x and z
coordinates.
Parameters:
- position (vec3)

---
Function: getVehiclesInArea (Class: er2)
Description: Get all vehicles within a specific area
Parameters:
- position (vec3)
- radius (float)
- table_to_fill (Table)

---
Function: isAllied (Class: er2)
Description: Check if a given faction Id is part of Allies faction
Returns: True if the given faction Id refers is part of Allies faction
Parameters:
- faction_id (string)

---
Function: isAxis (Class: er2)
Description: Check if a given faction Id is part of Axis faction
Returns: True if the given faction Id refers is part of Axis faction
Parameters:
- faction_id (string)

---
Function: isCivilian (Class: er2)
Description: Check if a given faction Id is part of Civilians faction
Returns: True if the given faction Id refers is part of Civilians faction
Parameters:
- faction_id (string)

---
Function: isInsideMainTerrainBounds (Class: er2)
Description: Checks if the given position is inside the terrain bounds
Parameters:
- position (vec3)

---
Function: isMasterClient (Class: er2)
Description: Check if current user is master client for online match
Returns: True if user is online match master client, or if match is being played
offline

---
Function: isOnline (Class: er2)
Description: Check if current mission is being played on an online match

---
Function: isSameFaction (Class: er2)
Description: Check if two faction Ids are part of the same faction (Allies or Axis)
Returns: True if thw two faction Ids are part of the same faction (Allies or Axis)
Parameters:
- faction_id1 (string)
- faction_id2 (string)

---
Function: MakeSquad (Class: er2)
Description: Create a new empty squad. You can add soldiers to this squad in order
to make them react to squad orders
Returns: A new empty squad

---
Function: nextPhase (Class: er2)
Description: Force mission to skip to next phase
Returns: If previous phase was last phase, returns true and conclude the mission

---
Function: playMusic (Class: er2)
Description: Plays a music track globally.
Parameters:
- clip_name (string)
- force_volume (float)

---
Function: previousPhase (Class: er2)
Description: Force mission to skip to previous phase
Returns: If next phase is first phase, returns true and conclude the mission
(defenders won)

---
Function: raycast (Class: er2)
Description: Casts a ray from an origin toward a direction. Used to test collisions
and objects presence.
The test is done trough a Unity Raycast.
Returns: Returns the distance from the ray's origin to the impact point.
Returns -1 if the ray doesn't intersects with any Collider.
Parameters:
- startPos (vec3)
- direction (vec3)
- maxDistance (float)

---
Function: setPhase (Class: er2)
Description: Changes the current phase to the one of index order
Returns: Returns false if it doesn't exist
Parameters:
- phase_index (integer)

---
Function: setRaining (Class: er2)
Description: Activates the rain on the map.
Examples:
er2.setRaining() -- Will start raining on the map.

---
Function: setSnowing (Class: er2)
Description: Activates the snow on the map.
Examples:
er2.setSnowing() -- Will start snowing on the map

---
Function: setTimeAndWeather (Class: er2)
Description: Sets the current time of day of the mission and some weather
conditions, like clouds, snow and fog.

NOTE: This function it's CPU heavy


Parameters:
- hour (integer)
- minute (integer)
- cloudsAmount (float)
- snowAmount (float)
- fogAmount (float)

---
Function: setTimeOfDay (Class: er2)
Description: Sets the current time of day of the mission. NOTE: This function is
CPU heavy
Parameters:
- hour (integer)
- minute (integer)
Examples:
-- set 4:20 PM
local currentHour = 16;
local currentMinute = 20;
er2.setTimeOfDay(currentHour, currentMinute)

-- or simply
er2.setTimeOfDay(16, 20)

---
Function: setVictoryDefenders (Class: er2)
Description: Concludes the mission declaring defenders as winners

---
Function: setVictoryInvaders (Class: er2)
Description: Concludes the mission declaring invaders as winners

---
Function: showObjective (Class: er2)
Description: Display a new objective text
Parameters:
- title (string)
- message (string)
Examples:
--show a new mission objective UI
er2.showObjective("New objective","Survive")

---
Function: get (Class: global)
Description: Get the value of a stored global variable
Returns: The variable that was stored. Expected types: bool, float, int, string.
If the variable was never set, returns nil.
Parameters:
- var_id (string)
Examples:
-- retrieve a stored global numeric value
local somenumber = global.get("some_stored_integer")

-- retrieve a stored global boolean value


local someboolean = global.get("some_stored_bool")

-- retrieve a stored global text value


local sometext = global.get("some_stored_text")

---
Function: myplayerget (Class: global)
Description: Get the value of a stored global variable by my player.
Returns: The variable that was stored. Expected types: bool, float, int, string.
If the variable was never set, returns nil.
Parameters:
- var_id (string)

---
Function: myplayerset (Class: global)
Description: Set a global variable for my network player that can be referenced
from any script and by any player in the room.
If another player sets a variable with the same id, it won't compromise my
variable.
Parameters:
- variable (any)
- var_id (any)

---
Function: playerget (Class: global)
Description: Get the value of a stored global variable by a specific player.
Returns: The variable that was stored. Expected types: bool, float, int, string.
If the variable was never set, returns nil.
Parameters:
- var_id (string)
- player_id (string)

---
Function: set (Class: global)
Description: Set a global variable that can be referenced from any script and by
any player in the room
Parameters:
- variable (any)
- var_id (string)
Examples:
-- save a value "100" on a global variable
global.set(100, "some_stored_integer")

-- save a value "true" on a global variable


global.set(true, "some_stored_bool")

-- save a value "hello!" on a global variable


global.set("hello!", "some_stored_text")

---
Function: addNewItem (Class: Soldier)
Description: Add Item to the inventory of the soldier
Returns: True if some item was correctly created and added
Parameters:
- item_id (string)

---
Function: alertFor (Class: Soldier)
Description: Puts the soldier in an alert state for a defined time
Parameters:
- time (float)

---
Function: applyBleeding (Class: Soldier)
Description: Applies bleed status to the soldier
---
Function: boardVehicle (Class: Soldier)
Description: Order the soldier to approach and borar onto the specified vehicle if
available.
Parameters:
- veh (Vehicle)
Examples:
soldier.boardVehicle(vehicle);

---
Function: canSwitchSeat (Class: Soldier)
Description: Check if the soldier is ready to switch seat. Usually this happens
when a soldier is not busy with enteirng or leaving the vehicle with an animation.
Returns: Returns true the soldier is ready to switch to another seat

---
Function: carryBody (Class: Soldier)
Description: Force the soldier to carry a another incapacitated soldier
Parameters:
- soldierToCarry (Soldier)

---
Function: damageSoldier (Class: Soldier)
Description: Apply damage to a soldier
Parameters:
- damageAmount (float)

---
Function: decreaseStamina (Class: Soldier)
Description: Decreases soldier's stamina
Parameters:
- amount (integer)

---
Function: disableHitByVehicleFor (Class: Soldier)
Description: Disable receiving damage from impacts with vehicles for some time
Parameters:
- time (float)

---
Function: doingMelee (Class: Soldier)
Description: Check if the soldier is doing a melee attack
Returns: Returns true if the soldier is doing a melee attack

---
Function: executeOrdersRoutine (Class: Soldier)
Description: Executes the routine to process squad orders for the soldier.
Examples:
soldier.executeOrdersRoutine();

---
Function: findCover (Class: Soldier)
Description: Finds a cover position near a specified position within a given
radius.
Parameters:
- position (vec3)
- radius (float)
Examples:
soldier.findCover(vec3(20, 0, 10), 5.0);

---
Function: getAiParams (Class: Soldier)
Description: Access AI parameters management
Returns: Reference to the AI parameters management class. If soldier is not an AI
(e.g. local player, online player) returns Nil

---
Function: getCarriedBody (Class: Soldier)
Description: Get a reference to the incapacitated soldier carried by this unit
Returns: The reference to the incapacitated soldier carried by this unit, nil if no
one is being carried

---
Function: getClassName (Class: Soldier)
Description: Returns the soldier's class name
Returns: Returns the soldier's class name

---
Function: getCurrentVehicle (Class: Soldier)
Description: Returns the current vehicle the soldier is in
Returns: Returns the current vehicle the soldier is in. Returns null if not in a
vehicle.

---
Function: getDistanceFromGround (Class: Soldier)
Description: Get the distance between the soldier and the ground below
Returns: Returns the distance between the soldier and the ground below

---
Function: getFacePosition (Class: Soldier)
Description: Get the world position of soldier's face
Returns: Returns world position of soldier's face

---
Function: getFaction (Class: Soldier)
Description: Gets the soldier's faction ID
Returns: Returns the soldier's faction ID

---
Function: getFireDirection (Class: Soldier)
Description: Return a vector representing the direction where the gun held by the
soldier is pointed to
Returns: Return a vector representing the direction where the gun held by the
soldier is pointed to

---
Function: getHeadgearId (Class: Soldier)
Description: Returns the current wearing headgear Id
Returns: Returns the current wearing headgear Id. Returns null if not wearing an
headgear

---
Function: getHealth (Class: Soldier)
Description: Get the soldier's health

---
Function: getMoveDirection (Class: Soldier)
Description: Returns the moving direction of the soldier
Returns: Returns the moving direction of the soldier

---
Function: getName (Class: Soldier)
Description: Returns the soldier's full name
Returns: The soldier's name and surname
Examples:
--get name into a string variable
local soldierName = someSoldier.getName()

--print the name on screen


print("Name of the soldier: "..soldierName)

---
Function: getNearestInjured (Class: Soldier)
Description: Get the nearest wounded soldier around the current one
Returns: Returns the nearest wounded soldier around the current one

---
Function: getNearestVehicleToRepair (Class: Soldier)
Description: Returns the nearest vehicle that requires repair from the current
soldier
Returns: Returns the nearest vehicle that requires repair from the current soldier

---
Function: getOffVehicle (Class: Soldier)
Description: Kicks the soldier from the current vehicle

---
Function: getOwnerId (Class: Soldier)
Description: Get Id of the online player controlling this soldier (Including AIs
being controlled by his machine).
Returns: If online, this returns the network Id of the player controlling this
soldier. If offline it returns 'NOT_FOUND'

---
Function: getPosition (Class: Soldier)
Description: Get world position of the soldier
Returns: A vector containing the world coordinate of the position of the soldier

---
Function: GetSquad (Class: Soldier)
Description: Get the Squad that the soldier is currently in
Returns: Reference to the squad the soldier is currently in

---
Function: getSuppressionValue (Class: Soldier)
Description: Checks the suppression value of the soldier from the enemy fire.
Returns: The value ranges from 0 (no suppression) to 1 (max level of suppression)
Examples:
-- In the AI brain, get a reference to the soldier
local soldier = myself()

sleep(0.1)

--While the soldier is alive, check his suppression status

while soldier.isAlive do
if (soldier.getSuppressionValue > 0.5) then
-- If the suppression value is higher than 0.5 (under heavy fire) kill the soldier
soldier.killSoldier()
end
sleep(0.1)
end

---
Function: getUniformId (Class: Soldier)
Description: Get the Id of the uniform worn by the soldier
Returns: Id of the uniform worn by the soldier

---
Function: getUniqueId (Class: Soldier)
Description: Get unique identifier for the unit. This is useful to check if a unit
already exist, or to find specific units, especially across the network.
Returns: A unique ID for the unit, Nil if not found.

---
Function: getVehicleSoldierIsExitingFrom (Class: Soldier)
Description: Get the vehicle the current soldier is exiting from
Returns: Returns the vehicle the current soldier is exiting from

---
Function: getVelocity (Class: Soldier)
Description: Returns the current soldier's velocity
Returns: Returns the current soldier's velocity

---
Function: getVestId (Class: Soldier)
Description: Get the Id of the vest worn by the soldier
Returns: Id of the vest worn by the soldier

---
Function: hasHeadgear (Class: Soldier)
Description: Check if the the soldier is wearing an headgear
Returns: Returns true if the current soldier is wearing an headgear

---
Function: hasRadio (Class: Soldier)
Description: Check if a soldier is wearing a radio
Returns: True if soldier is wearing a radio vest

---
Function: hasVest (Class: Soldier)
Description: Check if a soldier is wearing a vest
Returns: True if soldier is wearing a vest

---
Function: healSoldier (Class: Soldier)
Description: Heals soldier of a certain amount
Parameters:
- healAmount (float)

---
Function: incapacitate (Class: Soldier)
Description: Force incapacitate a soldier

---
Function: isAI (Class: Soldier)
Description: Checks if the current soldier is controlled by the AI
Returns: Returns true if the current soldier is controlled by AI

---
Function: isAiming (Class: Soldier)
Description: Checks if the current soldier is aiming the gun
Returns: Returns true if the soldier is aiming at something

---
Function: isAlerted (Class: Soldier)
Description: Check if the soldier has spotted an enemy recently and is moving
carefully
Returns: Returns true if the soldier is in an alert state

---
Function: isAlive (Class: Soldier)
Description: Checks if the current soldier is alive
Returns: Returns true if it's alive

---
Function: isAllied (Class: Soldier)
Description: Check if current soldier is part of Allies faction
Returns: True if current soldier is part of Allies faction

---
Function: isAmmoBoxCarrier (Class: Soldier)
Description: Check if soldier is carrying an ammo box
Returns: Returns true if the current soldier is is carrying an ammo box

---
Function: isATSoldier (Class: Soldier)
Description: Returns true if the current soldier is an Anti-Tank unit
Returns: Returns true if the current soldier is an Anti-Tank unit

---
Function: isAxis (Class: Soldier)
Description: Check if current soldier is part of Axis faction
Returns: True if current soldier is part of Axis faction

---
Function: isBleeding (Class: Soldier)
Description: Check if the soldier is bleeding
Returns: Returns true if the soldier is bleeding

---
Function: isCarried (Class: Soldier)
Description: Returns true if the current soldier is getting carried
Returns: Returns true if the current soldier is getting carried

---
Function: isCarryingBody (Class: Soldier)
Description: Check if the current soldier is carrying an incapacitated soldier
Returns: Returns true if the current soldier is carrying am incapacitated soldier

---
Function: isCharging (Class: Soldier)
Description: Returns true if the current soldier is charging
Returns: Returns true if the current soldier is charging
---
Function: isCivilian (Class: Soldier)
Description: Check if current soldier is part of Civilians faction
Returns: True if current soldier is part of Civilians faction

---
Function: isCrawling (Class: Soldier)
Description: Returns true if the current soldier is crawling
Returns: Returns true if the current soldier is crawling

---
Function: isDead (Class: Soldier)
Description: Check if a soldier is dead
Returns: True if soldier is dead

---
Function: isEnteringVehicle (Class: Soldier)
Description: Returns true if the current soldier has started the entering vehicle
animation
Returns: Returns true if the current soldier has started the entering vehicle
animation

---
Function: isExitingVehicle (Class: Soldier)
Description: Returns true if the current soldier has started the exiting vehicle
animation
Returns: Returns true if the current soldier has started the exiting vehicle
animation

---
Function: isFallingFromParachute (Class: Soldier)
Description: Checks if the current soldier is falling with a parachute
Returns: Returns true if the soldier is falling with a parachute

---
Function: isFlameThrowerCarrier (Class: Soldier)
Description: Check if a soldier is a flamethrower carrier
Returns: Returns true if the current soldier is a flame thrower carrier

---
Function: isFromChargingFaction (Class: Soldier)
Description: Check if the soldier can execute a charge order
Returns: True if a soldier can execute a charge order

---
Function: isGrounded (Class: Soldier)
Description: Returns true if the soldier is on the ground
Returns: Returns true if the soldier is touching the ground

---
Function: isIncapacitated (Class: Soldier)
Description: Check if a soldier is incapacitated
Returns: True if the soldier is incapacitated

---
Function: isInsideVehicle (Class: Soldier)
Description: Check if the soldier is inside a vehicle
Returns: Returns true if the soldier is inside a vehicle
---
Function: isJumping (Class: Soldier)
Description: Returns true if the current soldier is jumping
Returns: Returns true if the current soldier is jumping

---
Function: isMarksman (Class: Soldier)
Description: Returns true if the current soldier is a Marksman
Returns: Returns true if the current soldier is a Marksman

---
Function: isMechanic (Class: Soldier)
Description: Returns true if the current soldier is a mechanic
Returns: Returns true if the current soldier is a mechanic

---
Function: isMedic (Class: Soldier)
Description: Returns true if the current soldier is a medic
Returns: Returns true if the current soldier is a medic

---
Function: isMoving (Class: Soldier)
Description: Returns true if the current soldier is moving
Returns: Returns true if the current soldier is moving

---
Function: isOnCover (Class: Soldier)
Description: Check if a soldier is taking cover
Returns: True if the soldier is taking cover

---
Function: isOnFire (Class: Soldier)
Description: Returns true if the current soldier is on fire
Returns: Returns true if the current soldier is on fire

---
Function: isOnWater (Class: Soldier)
Description: Check if a soldier is walking inside water
Returns: True if soldier's feet are below water level

---
Function: isOutOfStamina (Class: Soldier)
Description: Returns true if the current soldier is out of stamina
Returns: Returns true if the current soldier is out of stamina

---
Function: isPlayer (Class: Soldier)
Description: Check if the soldier is a player
Returns: Returns true if the soldier is a player

---
Function: isPlayerFPS (Class: Soldier)
Description: Returns true if the current soldier is a player and in first person
Returns: Returns true if the current soldier is a player and in first person.
Returns false if the soldier is not the player and/or is not in first person

---
Function: isRadioman (Class: Soldier)
Description: Check if the current soldier is a Radioman
Returns: Returns true if the current soldier is a Radioman

---
Function: isReachingVehicleToMount (Class: Soldier)
Description: Check if a soldier is on his way to mount inside a vehicle
Returns: True if a soldier is on his way to mount inside a vehicle

---
Function: isReloading (Class: Soldier)
Description: Returns true if the current soldier is reloading a weapon
Returns: Returns true if the current soldier is reloading a weapon

---
Function: isRunning (Class: Soldier)
Description: Returns true if the current soldier is running
Returns: Returns true if the current soldier is running

---
Function: isSameFaction (Class: Soldier)
Description: Check if another soldier is in the same faction of this soldier
Returns: True if the two soldier are in the same faction
Parameters:
- other_soldier (Soldier)

---
Function: isSquadLeader (Class: Soldier)
Description: Returns true if the current soldier is the Squad Leader
Returns: Returns true if the current soldier is the Squad Leader

---
Function: isSquadReady (Class: Soldier)
Description: Check if soldier is in a squad, and the squad is marked as ready to
receive orders
Returns: True if the soldier is in a squad and the squad is spawned and ready to
receive orders

---
Function: isStealth (Class: Soldier)
Description: Returns true if the soldier is moving stealthly
Returns: Returns true if the soldier is moving stealthly

---
Function: isSuppressed (Class: Soldier)
Description: Checks if the soldier is being suppressed
Returns: True if the soldier is suppressed

---
Function: isSurrendering (Class: Soldier)
Description: Check if the soldier is surrendering
Returns: Returns true if the soldier is currently surrendering

---
Function: isTalking (Class: Soldier)
Description: Returns true if the current soldier is talking
Returns: Returns true if the current soldier is talking

---
Function: isThrowing (Class: Soldier)
Description: Returns true if the current soldier is throwing something
Returns: Returns true if the current soldier is throwing something

---
Function: isTowardWall (Class: Soldier)
Description: Returns true if the current soldier is facing a wall
Returns: Returns true if the current soldier is facing a wall

---
Function: isUsingVehicleTurret (Class: Soldier)
Description: Check if soldier is operating a turret
Returns: True if soldier is operating a turret

---
Function: jump (Class: Soldier)
Description: Makes the soldier jump.
Notice: the jump movement is based on the current soldier velocity and direction.

---
Function: killSoldier (Class: Soldier)
Description: Kills the soldier

---
Function: leaveVehicle (Class: Soldier)
Description: Commands the soldier to eject from the current vehicle.
Examples:
soldier.leaveVehicle();

---
Function: moveTo (Class: Soldier)
Description: Moves the soldier to a specified position using CoverPosition with a
new DestinationWithoutCover based on the given position and current pose.
Parameters:
- position (vec3)
Examples:
soldier.moveTo(vec3(10, 0, 5));

---
Function: myself (Class: Soldier)
Description: Can be called within a SoldierBrain script to acquire the soldier
controlled by the script
Returns: Returns the Soldier which the script is assigned to

---
Function: pauseAlert (Class: Soldier)
Description: Pauses the soldier's alert state.
Notice: the difference between this and setnotalerted is that this one just pauses
the alert state, while the other one stops

---
Function: removeBleeding (Class: Soldier)
Description: Removes bleeding effect from soldier

---
Function: removeItem (Class: Soldier)
Description: Remove one or multiple items from a soldier invenotory
Returns: True if any item with the given id was found and removed
Parameters:
- item_id (string)
- count (integer)

---
Function: say (Class: Soldier)
Description: Makes the soldier say a line based on the VoiceClip Enum
Parameters:
- clip (VoiceClip)
- delay (float)
Examples:
-- Spawns a german soldier at origin point
local sold = spawnSoldier("none", 8, "Germany_allies", Vector3(0,0,0))

-- Make the spawned soldier play the VoiceClip.scream_long clip every second while
being alive
while sold.isAlive() do
sold.say(VoiceClip.scream_long)
sleep(1)
end

---
Function: setBrain (Class: Soldier)
Description: Set script that controls AI. Usually AI will work with "Default"
behaviour, which will controls the way AI gives and follows squad orders, however
it's possible to define a completly new behaviour by coding a dedicated "brain" LUA
file and assign it to the AI with this function
Returns: False if script is not found
Parameters:
- scriptFile (string)

---
Function: setInVehicle (Class: Soldier)
Description: Teleport the soldier inside the specified vehicle.
Parameters:
- veh (Vehicle)
Examples:
soldier.setInVehicle(vehicle);

---
Function: setNotAlerted (Class: Soldier)
Description: Force concludes the alert state of the soldier

---
Function: setOnFire (Class: Soldier)
Description: Sets the current soldier on fire.
Notice: The fire does not damage the soldier.
Examples:
-- Spawn a German soldier at origin point
local sold = spawnSoldier("none", 8, "Germany_allies", Vector3(0,0,0))

-- After 10 seconds, set the soldier on fire


sleep(10)
sold.setOnFire()

---
Function: setPlayer (Class: Soldier)
Description: Force a soldier to be controlled by the player. Notice: This only
works for soldiers and AIs that have been spawned (or are controlled) by current
player's machine

---
Function: setPose (Class: Soldier)
Description: Sets the soldier's pose based on the given integer.
Parameters:
- pose (integer)
Examples:
soldier.setPose(2);

---
Function: stop (Class: Soldier)
Description: Stops the soldier by resetting the cover position to the current
position.
Examples:
soldier.stop();

---
Function: stopIncapacitate (Class: Soldier)
Description: Stops a soldier from being incapacitated

---
Function: stopSurrendering (Class: Soldier)
Description: Cancel soldier surrendering action

---
Function: surrender (Class: Soldier)
Description: Force surrender the current soldier

---
Function: addSoldier (Class: Squad)
Description: Add a Soldier to a squad
Returns: True if soldier was added correctly
Parameters:
- soldierToAdd (Soldier)

---
Function: alertEnemies (Class: Squad)
Description: Alert all enemies of the presence of the squad for some time
Parameters:
- duration (float)
Examples:
squad.alertEnemies(30.0);

---
Function: attackFromPoint (Class: Squad)
Description: Orders the squad to attack from the specified waypoint within the
given radius.
Parameters:
- waypoint (vec3)
- radius (float)
Examples:
squad.attackFromPoint(vec3(40, 0, 30), 7.5);

---
Function: boardVehicle (Class: Squad)
Description: Orders the squad to board the specified vehicle.
Parameters:
- vehicle (Vehicle)
Examples:
squad.boardVehicle(vehicle);

---
Function: cancelRadioRequest (Class: Squad)
Description: Cancels any active radio request by the squad.
Examples:
squad.cancelRadioRequest();

---
Function: charge (Class: Squad)
Description: Orders the squad to charge towards the specified position within the
given radius.
Parameters:
- position (vec3)
- radius (float)
Examples:
squad.charge(vec3(50, 0, 35), 8.0);

---
Function: coverArea (Class: Squad)
Description: Orders the squad to cover an area defined by a center position and
radius.
Parameters:
- position (vec3)
- radius (float)
Examples:
squad.coverArea(vec3(15, 0, 20), 10.0);

---
Function: fireAtWill (Class: Squad)
Description: Orders the squad to fire at will, canceling the stealth "hold fire"
order, optionally playing an order animation.
Parameters:
- playOrderAnimation (bool)
Examples:
squad.fireAtWill(true);

---
Function: followLeader (Class: Squad)
Description: Orders the squad to follow their leader, optionally playing an order
animation.
Parameters:
- playOrderAnimation (bool)
Examples:
squad.followLeader(true);

---
Function: getObjectivePosition (Class: Squad)
Description: Returns the position of the squad's current objective, or the leader's
position if none is set.
Returns: Objective or leader position.
Examples:
local pos = squad.getObjectivePosition();

---
Function: getObjectiveRadius (Class: Squad)
Description: Returns the radius of the squad's current objective area, or a default
value if none exists.
Returns: Objective area radius.
Examples:
local rad = squad.getObjectiveRadius();

---
Function: hasAliveMembers (Class: Squad)
Description: Returns whether the squad has any alive members.
Returns: True if the squad has alive members.
Examples:
local alive = squad.hasAliveMembers();

---
Function: hasFullySpawned (Class: Squad)
Description: When using in-game Spawn Manager, spawning a squad can take a few
instants. This function can be used to check whenever a squad has fully spawned
Returns: True if a squad is fully spawned

---
Function: hasObjective (Class: Squad)
Description: Returns whether the squad has an assigned objective.
Returns: True if the squad has an objective.
Examples:
local hasObj = squad.hasObjective();

---
Function: holdFire (Class: Squad)
Description: Orders the squad to hold fire and move stealthy, optionally playing an
order animation.
Parameters:
- playOrderAnimation (bool)
Examples:
squad.holdFire(true);

---
Function: leaveVehicle (Class: Squad)
Description: Orders the squad to leave the specified vehicle. The force flag
determines whether the leave order is forced.
Parameters:
- vehicle (Vehicle)
- force (bool)
Examples:
squad.leaveVehicle(vehicle, true);

---
Function: moveTo (Class: Squad)
Description: Orders the squad to hold an area at the specified position with the
given radius.
Parameters:
- position (vec3)
- radius (float)
Examples:
squad.moveTo(vec3(30, 0, 25), 5.0);

---
Function: removeSoldier (Class: Squad)
Description: Remove a Soldier from a Squad (Soldier will be put on a new Squad)
Returns: True if soldier was removed succesfully
Parameters:
- soldierToRemove (Soldier)

---
Function: repairVehicle (Class: Squad)
Description: Orders the squad to repair the specified vehicle.
Parameters:
- vehicle (Vehicle)
Examples:
squad.repairVehicle(vehicle);

---
Function: setClosestObjective (Class: Squad)
Description: Orders the squad to set their objective to the closest available one.
Examples:
squad.setClosestObjective();

---
Function: setRandomObjective (Class: Squad)
Description: Orders the squad to set a random objective.
Examples:
squad.setRandomObjective();

---
Function: addNewItemToCargo (Class: Vehicle)
Description: Add a new item to the cargo of the vehicle
Parameters:
- item_id (string)

---
Function: canBeRepaired (Class: Vehicle)
Description: Checks if the vehicle can be repaired

---
Function: canRecieveDamage (Class: Vehicle)
Description: Checks if the vehicle can recieve any form of damage.
Returns: Returns false if the vehicle is compleatly destroied

---
Function: canRefillAmmo (Class: Vehicle)
Description: Checks if is possible to refill ammo for the vehicle

---
Function: canShootInDirection (Class: Vehicle)
Description: Checks if someone on the vehicle can shoot in that direction
Returns: Returns true if, for each seat in the vehicle, exist at least 1 soldier
that can shoot in that direction
Parameters:
- direction (vec3)

---
Function: cargoContainsItem (Class: Vehicle)
Description: Check if vehicle inventory contains a specific item
Returns: True if item with same Id is found in the inventory of the vehicle
Parameters:
- item_id (string)

---
Function: countEmptySeats (Class: Vehicle)
Description: Counts the empty seats in the vehicle
---
Function: countItems (Class: Vehicle)
Description: Count how many items with a specific Id are found inside the inventory
of the vehicle
Returns: Count of items with specified Id have been found
Parameters:
- item_id (string)

---
Function: countPeopleInside (Class: Vehicle)
Description: Counts all the people inside the vehicle

---
Function: damage (Class: Vehicle)
Description: Apply damage to the hull of a vehicle
Parameters:
- damage (float)

---
Function: damageEngine (Class: Vehicle)
Description: Damage vehicle engine (if any)
Parameters:
- damage (integer)

---
Function: damageFuelTank (Class: Vehicle)
Description: Damage vehicle fuel tank (if any)
Returns: this function doesn't return anything
Parameters:
- damage (integer)

---
Function: damageTracks (Class: Vehicle)
Description: Damage vehicle tracks and/or wheels (if any)
Returns: this function doesn't return anything
Parameters:
- damage (integer)

---
Function: destroy (Class: Vehicle)
Description: Disable the vehicle forever

---
Function: dropInfantry (Class: Vehicle)
Description: Kicks all the soldier seated in the passenger seats

---
Function: emptyAllTurrets (Class: Vehicle)
Description: Empties the magazines of all the turrets in the vehicle

---
Function: getDamage (Class: Vehicle)
Description: Check life amount of a vehicle (hull integrity)
Returns: Amount of damage the hull can sustain

---
Function: getDriver (Class: Vehicle)
Description: Get reference to the Soldier driving the vehicle
Returns: Reference of the soldier driving the vehicle. Nil of no one is driving
this vehicle.

---
Function: getEngineDamage (Class: Vehicle)
Description: Check life amount of a vehicle engine (engine integrity)
Returns: Amount of damage the engine can still sustain

---
Function: getFaction (Class: Vehicle)
Description: Get faction Id of the vehicle
Returns: Id of the faction

---
Function: getFueltankDamage (Class: Vehicle)
Description: Check life amount of vehicle fuel tank
Returns: Amount of damage the fuel tank can still sustain

---
Function: getGunner (Class: Vehicle)
Description: Get reference to a soldier controlling a turret of the vehicle
Returns: Reference of a soldier controlling a turret of the vehicle

---
Function: getLeader (Class: Vehicle)
Description: Get reference of the soldier in the commanding seat of the vehicle
Returns: Reference of the soldier in the commanding seat of the vehicle. Nil if no
one is on that specific seat

---
Function: getPassengers (Class: Vehicle)
Description: Get all passengers of the vehicle
Returns: Lua Table containing all the passengers of the vehicle, ordered by seat
priority

---
Function: getTracksDamage (Class: Vehicle)
Description: Check life amount of vehicle tracks/wheels
Returns: Amount of damage the tracks/wheels can still sustain

---
Function: getUniqueId (Class: Vehicle)
Description: Get unique identifier for the vehicle. This is useful to check if a
vehicle already exist, or to find specific vehicles, especially across the network.
Returns: A unique ID for the vehicle, Nil if not found.

---
Function: hasDriver (Class: Vehicle)
Description: Checks if the vehicle has a driver

---
Function: isArtilleryVehicle (Class: Vehicle)
Description: Checks if the vehicle has any seat to be considered artillery

---
Function: isBraking (Class: Vehicle)
Description: Checks if the vehicle is braking

---
Function: isDestroyed (Class: Vehicle)
Description: Check if vehicle is fully destroyed
Returns: True if vehicle is destroyed forever
Examples:
--[[ Editable Section: Spawn Vehicle Variables ]]
local VEHICLE_ID = "Panzer iii J" -- Vehicle Id from the Id tables
local POSITION = vec3(0, 1.5, 0) -- Spawn position for the vehicle
local ROTATION = vec3(0, 90, 0) -- Vehicle rotation

-- Spawn a basic vehicle


local vehicle1 = spawnVehicle(VEHICLE_ID, POSITION, ROTATION)
if vehicle1 then
print("Basic vehicle spawned! Destroy it to complete the mission.", 3)
end

-- Wait for the spawned vehicle to be destroyed


while vehicle1 and not vehicle1.isDestroyed() do
-- Do the check every 3 seconds not to cause lag spikes
sleep(3)
end

print("Vehicle destroyed, mission complete!", 3)


er2.nextPhase()

---
Function: isDriverAlive (Class: Vehicle)
Description: Checks if there's a driver and is alive

---
Function: isEmpty (Class: Vehicle)
Description: Check if vehicle is empty (No units are left inside)
Returns: True if vehicle is completely empty from units

---
Function: isFull (Class: Vehicle)
Description: Check if vehicle seats are all occupied
Returns: True if vehicle has no more space for units

---
Function: kickEveryoneOut (Class: Vehicle)
Description: Force everyone to leave the vehicle

---
Function: kickUnits (Class: Vehicle)
Description: Force specific units to leave the vehicle
Returns: this function doesn't return anything
Parameters:
- onlyPassengers (bool)
- ignorePlayer (bool)

---
Function: removeItemFromCargo (Class: Vehicle)
Description: Remove an item from the cargo of the vehicle
Returns: this function doesn't return anything
Parameters:
- item_id (string)

---
Function: repair (Class: Vehicle)
Description: Set vehicle to fully repaired.
Notice: This works only on vehicles that are not fully destroyed

User Request to generate: create a AI where they do not leave the vehicle unless
only and only if ordered to

You might also like