Scripting API
AiParams
Class that handles AI parameters management.
Return | Function Name | Description | Vote |
---|---|---|---|
void | allowBeingTargeted | 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. | 4 |
void | allowChangePose | 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 | 2 |
void | allowCheckForEnemies | 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 | 2 |
void | allowDoMedic | When this function is enabled, if a soldier has medic equipments in his inventory he will proceed to heal nearby units | 0 |
void | allowFindCoverWhenSuppressed | 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 | 3 |
void | allowFollowOrders | 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 | 0 |
void | allowGiveOrders | 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 | 2 |
void | allowLeaveVehicle | 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 | 3 |
void | allowMovements | 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 | 2 |
void | allowOpenWindows | When enabled, AI will open windows that blocks it's vision, for example when in cover behind a window | 2 |
void | allowRadioOrders | When enabled and if radioman, AI will communicate radio orders requested by squad leader | 2 |
void | enableAiBehaviour | This function enables or disbales all AI functionalities toghether, including: allowChangePose, allowCheckForEnemies, allowFindCoverWhenSuppressed, allowLeaveVehicle, allowMovements, allowOpenWindows, allowOrders and allowRadioOrders | 3 |
void | followCustomDirectCommands | Disable various AI behaviors in order to prepare the soldier to follow direct commands, such as soldier.moveTo() | 0 |
void | followCustomSquadOrders | 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() | 0 |
void | setTargetPlanesOften | Enable this feature to force the AI to target planes, if closer than any other spotted enemy | 2 |
Base Functions
These functions are not part of a specific class and can be called from anywhere.
Return | Function Name | Description | Vote |
---|---|---|---|
float | distance | The distance between 2 Vector3 points in meters | 3 |
void | log | 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 | 7 |
void | Display a message on the screen | 4 | |
float | round | Round a number to a specific quantity to decimal points | 7 |
void | sleep | 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 | 7 |
Soldier | spawnHuman | Spawn a new human without specific loadout or rank | 3 |
Soldier | spawnSoldier | Spawn an AI soldier | 4 |
Soldier | spawnSoldierOnVehicle | Spawn an AI soldier on a vehicle | 3 |
Vehicle | spawnVehicle | Spawn a vehicle | 3 |
Vehicle | spawnVehicle_camo | Spawn a vehicle with a specified camo | 3 |
Vehicle | spawnVehicle_camo_dest | Spawn a vehicle with a specified camo and give it a destination. For Auto-Transport vehicles, this is where units will be deployed. | 3 |
Vehicle | spawnVehicle_dest | Spawn a vehicle and give it a destination. For Auto-Transport vehicles, this is where units will be deployed. | 2 |
void | waitForAny | Pause the execution of the script until any of the given conditions are met. | 3 |
void | waitUntil | Pause the execution of the script until one or multiple conditions are met. | 3 |
er2
General utility and helper functions.
Return | Function Name | Description | Vote |
---|---|---|---|
void | addInvadersTickets | Adds tickets to the current invaders faction. | 3 |
integer | countDeceasedDefenders | Count how many defenders are deceased during the mission | 2 |
integer | countDeceasedInvaders | Count how many invaders are deceased during the mission | 2 |
integer | countLostVehiclesDefenders | Count how many defenders have been captured during the mission | 2 |
integer | countLostVehiclesInvaders | Count how many invaders have been captured during the mission | 2 |
integer | countPrisonersDefenders | Count how many vehicles have been lost by the defenders during the mission | 2 |
integer | countPrisonersInvaders | Count how many vehicles have been lost by the invaders during the mission | 2 |
void | endPrecipitation | Stops the rain or the snow from falling in the map | 0 |
void | explosion | Generates an explosion | 3 |
Soldier | findSoldier | Find a soldier from it's unique Id (network safe) | 2 |
Soldier | findVehicle | Find a vehicle from it's unique Id (network safe) | 2 |
void | getAllSoldiers | 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. | 3 |
void | getAllVehicles | Get all vehicles around the map | 3 |
string | getBattleName | Returns the current battle's name | 7 |
float | getDistanceFromTerrain | Returns the distance between the given position and the terrain. | 2 |
integer | getInvadersTicket | Returns the number of tickets left by the invaders | 3 |
string | getMapName | Returns the name of the map of the current battle | 3 |
string | getMyNickname | Get nickname of the local user | 3 |
Squad | getNearestSoldier | Get nearest soldier to a specific location | 3 |
Vehicle | getNearestVehicle | Get nearest vehicle from a specific location | 3 |
string | getNickname | Get nickname of an online player | 3 |
Soldier | getPlayer | Find a reference to the Soldier controlled by the player | 7 |
Table | getSoldiersInArea | 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. | 3 |
float | getTerrainHeight | Returns the terrain height from sea level of the given x and z coordinates. | 2 |
void | getVehiclesInArea | Get all vehicles within a specific area | 3 |
bool | isAllied | Check if a given faction Id is part of Allies faction | 2 |
AiParams | isAxis | Check if a given faction Id is part of Axis faction | 2 |
AiParams | isCivilian | Check if a given faction Id is part of Civilians faction | 2 |
bool | isInsideMainTerrainBounds | Checks if the given position is inside the terrain bounds | 2 |
bool | isMasterClient | Check if current user is master client for online match | 3 |
bool | isOnline | Check if current mission is being played on an online match | 3 |
bool | isSameFaction | Check if two faction Ids are part of the same faction (Allies or Axis) | 2 |
Squad | MakeSquad | Create a new empty squad. You can add soldiers to this squad in order to make them react to squad orders | 3 |
bool | nextPhase | Force mission to skip to next phase | 7 |
void | playMusic | Plays a music track globally. | 7 |
bool | previousPhase | Force mission to skip to previous phase | 7 |
float | raycast | Casts a ray from an origin toward a direction. Used to test collisions and objects presence. The test is done trough a Unity Raycast. | 2 |
bool | setPhase | Changes the current phase to the one of index order | 4 |
void | setRaining | Activates the rain on the map. | 0 |
void | setSnowing | Activates the snow on the map. | 0 |
void | setTimeAndWeather | 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 | 3 |
void | setTimeOfDay | Sets the current time of day of the mission. NOTE: This function is CPU heavy | 8 |
void | setVictoryDefenders | Concludes the mission declaring defenders as winners | 7 |
void | setVictoryInvaders | Concludes the mission declaring invaders as winners | 6 |
void | showObjective | Display a new objective text | 3 |
global
Functions to manipulate global variables that can be accessed from any script and over the network.
Return | Function Name | Description | Vote |
---|---|---|---|
any | get | Get the value of a stored global variable | 3 |
any | myplayerget | Get the value of a stored global variable by my player. | 4 |
void | myplayerset | 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. | 3 |
any | playerget | Get the value of a stored global variable by a specific player. | 3 |
void | set | Set a global variable that can be referenced from any script and by any player in the room | 3 |
Soldier
Functions related to player actions and properties.
Return | Function Name | Description | Vote |
---|---|---|---|
bool | addNewItem | Add Item to the inventory of the soldier | 3 |
void | alertFor | Puts the soldier in an alert state for a defined time | 6 |
void | applyBleeding | Applies bleed status to the soldier | 6 |
void | boardVehicle | Order the soldier to approach and borar onto the specified vehicle if available. | 2 |
bool | canSwitchSeat | 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. | 6 |
void | carryBody | Force the soldier to carry a another incapacitated soldier | 8 |
void | damageSoldier | Apply damage to a soldier | 4 |
void | decreaseStamina | Decreases soldier's stamina | 6 |
void | disableHitByVehicleFor | Disable receiving damage from impacts with vehicles for some time | 3 |
bool | doingMelee | Check if the soldier is doing a melee attack | 6 |
void | executeOrdersRoutine | Executes the routine to process squad orders for the soldier. | 2 |
void | findCover | Finds a cover position near a specified position within a given radius. | 2 |
AiParams | getAiParams | Access AI parameters management | 2 |
Soldier | getCarriedBody | Get a reference to the incapacitated soldier carried by this unit | 8 |
string | getClassName | Returns the soldier's class name | 6 |
Vehicle | getCurrentVehicle | Returns the current vehicle the soldier is in | 6 |
float | getDistanceFromGround | Get the distance between the soldier and the ground below | 3 |
vec3 | getFacePosition | Get the world position of soldier's face | 7 |
string | getFaction | Gets the soldier's faction ID | 2 |
vec3 | getFireDirection | Return a vector representing the direction where the gun held by the soldier is pointed to | 6 |
string | getHeadgearId | Returns the current wearing headgear Id | 6 |
float | getHealth | Get the soldier's health | 2 |
vec3 | getMoveDirection | Returns the moving direction of the soldier | 6 |
string | getName | Returns the soldier's full name | 4 |
Soldier | getNearestInjured | Get the nearest wounded soldier around the current one | 6 |
Vehicle | getNearestVehicleToRepair | Returns the nearest vehicle that requires repair from the current soldier | 3 |
void | getOffVehicle | Kicks the soldier from the current vehicle | 6 |
string | getOwnerId | Get Id of the online player controlling this soldier (Including AIs being controlled by his machine). | 3 |
vec3 | getPosition | Get world position of the soldier | 4 |
Squad | GetSquad | Get the Squad that the soldier is currently in | 6 |
float | getSuppressionValue | Checks the suppression value of the soldier from the enemy fire. | 0 |
string | getUniformId | Get the Id of the uniform worn by the soldier | 3 |
integer | getUniqueId | 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. | 2 |
Vehicle | getVehicleSoldierIsExitingFrom | Get the vehicle the current soldier is exiting from | 6 |
vec3 | getVelocity | Returns the current soldier's velocity | 6 |
string | getVestId | Get the Id of the vest worn by the soldier | 3 |
bool | hasHeadgear | Check if the the soldier is wearing an headgear | 3 |
bool | hasRadio | Check if a soldier is wearing a radio | 3 |
bool | hasVest | Check if a soldier is wearing a vest | 6 |
void | healSoldier | Heals soldier of a certain amount | 6 |
void | incapacitate | Force incapacitate a soldier | 7 |
bool | isAI | Checks if the current soldier is controlled by the AI | 6 |
bool | isAiming | Checks if the current soldier is aiming the gun | 6 |
bool | isAlerted | Check if the soldier has spotted an enemy recently and is moving carefully | 6 |
bool | isAlive | Checks if the current soldier is alive | 7 |
bool | isAllied | Check if current soldier is part of Allies faction | 2 |
bool | isAmmoBoxCarrier | Check if soldier is carrying an ammo box | 3 |
bool | isATSoldier | Returns true if the current soldier is an Anti-Tank unit | 6 |
AiParams | isAxis | Check if current soldier is part of Axis faction | 2 |
bool | isBleeding | Check if the soldier is bleeding | 6 |
bool | isCarried | Returns true if the current soldier is getting carried | 6 |
bool | isCarryingBody | Check if the current soldier is carrying an incapacitated soldier | 6 |
bool | isCharging | Returns true if the current soldier is charging | 6 |
AiParams | isCivilian | Check if current soldier is part of Civilians faction | 2 |
bool | isCrawling | Returns true if the current soldier is crawling | 6 |
bool | isDead | Check if a soldier is dead | 3 |
bool | isEnteringVehicle | Returns true if the current soldier has started the entering vehicle animation | 6 |
bool | isExitingVehicle | Returns true if the current soldier has started the exiting vehicle animation | 6 |
bool | isFallingFromParachute | Checks if the current soldier is falling with a parachute | 3 |
bool | isFlameThrowerCarrier | Check if a soldier is a flamethrower carrier | 4 |
bool | isFromChargingFaction | Check if the soldier can execute a charge order | 6 |
bool | isGrounded | Returns true if the soldier is on the ground | 6 |
bool | isIncapacitated | Check if a soldier is incapacitated | 3 |
bool | isInsideVehicle | Check if the soldier is inside a vehicle | 3 |
bool | isJumping | Returns true if the current soldier is jumping | 6 |
bool | isMarksman | Returns true if the current soldier is a Marksman | 3 |
bool | isMechanic | Returns true if the current soldier is a mechanic | 7 |
bool | isMedic | Returns true if the current soldier is a medic | 6 |
bool | isMoving | Returns true if the current soldier is moving | 6 |
bool | isOnCover | Check if a soldier is taking cover | 6 |
bool | isOnFire | Returns true if the current soldier is on fire | 3 |
bool | isOnWater | Check if a soldier is walking inside water | 7 |
bool | isOutOfStamina | Returns true if the current soldier is out of stamina | 6 |
bool | isPlayer | Check if the soldier is a player | 6 |
bool | isPlayerFPS | Returns true if the current soldier is a player and in first person | 6 |
bool | isRadioman | Check if the current soldier is a Radioman | 3 |
bool | isReachingVehicleToMount | Check if a soldier is on his way to mount inside a vehicle | 6 |
bool | isReloading | Returns true if the current soldier is reloading a weapon | 6 |
bool | isRunning | Returns true if the current soldier is running | 3 |
bool | isSameFaction | Check if another soldier is in the same faction of this soldier | 2 |
bool | isSquadLeader | Returns true if the current soldier is the Squad Leader | 6 |
bool | isSquadReady | Check if soldier is in a squad, and the squad is marked as ready to receive orders | 0 |
bool | isStealth | Returns true if the soldier is moving stealthly | 3 |
bool | isSuppressed | Checks if the soldier is being suppressed | 0 |
bool | isSurrendering | Check if the soldier is surrendering | 6 |
bool | isTalking | Returns true if the current soldier is talking | 6 |
bool | isThrowing | Returns true if the current soldier is throwing something | 6 |
bool | isTowardWall | Returns true if the current soldier is facing a wall | 6 |
bool | isUsingVehicleTurret | Check if soldier is operating a turret | 4 |
void | jump | Makes the soldier jump. Notice: the jump movement is based on the current soldier velocity and direction. | 3 |
void | killSoldier | Kills the soldier | 6 |
void | leaveVehicle | Commands the soldier to eject from the current vehicle. | 2 |
void | moveTo | Moves the soldier to a specified position using CoverPosition with a new DestinationWithoutCover based on the given position and current pose. | 2 |
Soldier | myself | Can be called within a SoldierBrain script to acquire the soldier controlled by the script | 3 |
void | pauseAlert | 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 | 6 |
void | removeBleeding | Removes bleeding effect from soldier | 6 |
bool | removeItem | Remove one or multiple items from a soldier invenotory | 6 |
void | say | Makes the soldier say a line based on the VoiceClip Enum | 3 |
bool | setBrain | 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 | 3 |
void | setInVehicle | Teleport the soldier inside the specified vehicle. | 2 |
void | setNotAlerted | Force concludes the alert state of the soldier | 6 |
void | setOnFire | Sets the current soldier on fire. Notice: The fire does not damage the soldier. | 6 |
void | setPlayer | 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 | 6 |
void | setPose | Sets the soldier's pose based on the given integer. | 2 |
void | stop | Stops the soldier by resetting the cover position to the current position. | 2 |
void | stopIncapacitate | Stops a soldier from being incapacitated | 6 |
void | stopSurrendering | Cancel soldier surrendering action | 6 |
void | surrender | Force surrender the current soldier | 6 |
Squad
Class to handle a Squad controlling multiple Soldiers.
Return | Function Name | Description | Vote |
---|---|---|---|
bool | addSoldier | Add a Soldier to a squad | 3 |
void | alertEnemies | Alert all enemies of the presence of the squad for some time | 2 |
void | attackFromPoint | Orders the squad to attack from the specified waypoint within the given radius. | 2 |
void | boardVehicle | Orders the squad to board the specified vehicle. | 2 |
void | cancelRadioRequest | Cancels any active radio request by the squad. | 2 |
void | charge | Orders the squad to charge towards the specified position within the given radius. | 2 |
void | coverArea | Orders the squad to cover an area defined by a center position and radius. | 2 |
void | fireAtWill | Orders the squad to fire at will, canceling the stealth "hold fire" order, optionally playing an order animation. | 2 |
void | followLeader | Orders the squad to follow their leader, optionally playing an order animation. | 2 |
vec3 | getObjectivePosition | Returns the position of the squad's current objective, or the leader's position if none is set. | 2 |
float | getObjectiveRadius | Returns the radius of the squad's current objective area, or a default value if none exists. | 2 |
bool | hasAliveMembers | Returns whether the squad has any alive members. | 3 |
bool | hasFullySpawned | 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 | 0 |
bool | hasObjective | Returns whether the squad has an assigned objective. | 2 |
void | holdFire | Orders the squad to hold fire and move stealthy, optionally playing an order animation. | 2 |
void | leaveVehicle | Orders the squad to leave the specified vehicle. The force flag determines whether the leave order is forced. | 2 |
void | moveTo | Orders the squad to hold an area at the specified position with the given radius. | 2 |
bool | removeSoldier | Remove a Soldier from a Squad (Soldier will be put on a new Squad) | 3 |
void | repairVehicle | Orders the squad to repair the specified vehicle. | 2 |
void | setClosestObjective | Orders the squad to set their objective to the closest available one. | 2 |
void | setRandomObjective | Orders the squad to set a random objective. | 2 |
Vehicle
Functions to handle vehicle spawning and behavior.
Return | Function Name | Description | Vote |
---|---|---|---|
void | addNewItemToCargo | Add a new item to the cargo of the vehicle | 3 |
bool | canBeRepaired | Checks if the vehicle can be repaired | 2 |
any | canRecieveDamage | Checks if the vehicle can recieve any form of damage. | 2 |
bool | canRefillAmmo | Checks if is possible to refill ammo for the vehicle | 2 |
bool | canShootInDirection | Checks if someone on the vehicle can shoot in that direction | 2 |
bool | cargoContainsItem | Check if vehicle inventory contains a specific item | 3 |
integer | countEmptySeats | Counts the empty seats in the vehicle | 2 |
integer | countItems | Count how many items with a specific Id are found inside the inventory of the vehicle | 3 |
any | countPeopleInside | Counts all the people inside the vehicle | 2 |
void | damage | Apply damage to the hull of a vehicle | 3 |
void | damageEngine | Damage vehicle engine (if any) | 3 |
void | damageFuelTank | Damage vehicle fuel tank (if any) | 3 |
void | damageTracks | Damage vehicle tracks and/or wheels (if any) | 4 |
void | destroy | Disable the vehicle forever | 3 |
void | dropInfantry | Kicks all the soldier seated in the passenger seats | 3 |
void | emptyAllTurrets | Empties the magazines of all the turrets in the vehicle | 2 |
float | getDamage | Check life amount of a vehicle (hull integrity) | 3 |
Soldier | getDriver | Get reference to the Soldier driving the vehicle | 3 |
float | getEngineDamage | Check life amount of a vehicle engine (engine integrity) | 3 |
string | getFaction | Get faction Id of the vehicle | 2 |
float | getFueltankDamage | Check life amount of vehicle fuel tank | 3 |
Soldier | getGunner | Get reference to a soldier controlling a turret of the vehicle | 3 |
Soldier | getLeader | Get reference of the soldier in the commanding seat of the vehicle | 3 |
Soldier | getPassengers | Get all passengers of the vehicle | 3 |
float | getTracksDamage | Check life amount of vehicle tracks/wheels | 3 |
integer | getUniqueId | 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. | 2 |
bool | hasDriver | Checks if the vehicle has a driver | 3 |
bool | isArtilleryVehicle | Checks if the vehicle has any seat to be considered artillery | 3 |
bool | isBraking | Checks if the vehicle is braking | 3 |
bool | isDestroyed | Check if vehicle is fully destroyed | 4 |
bool | isDriverAlive | Checks if there's a driver and is alive | 3 |
bool | isEmpty | Check if vehicle is empty (No units are left inside) | 4 |
bool | isFull | Check if vehicle seats are all occupied | 4 |
void | kickEveryoneOut | Force everyone to leave the vehicle | 4 |
void | kickUnits | Force specific units to leave the vehicle | 4 |
void | removeItemFromCargo | Remove an item from the cargo of the vehicle | 4 |
void | repair | Set vehicle to fully repaired. Notice: This works only on vehicles that are not fully destroyed | 4 |