Avorion Script API Documentation

Sector Callbacks

Note: Callbacks have to be buffered in certain situations and won't happen immediately. When unregistering a callback during a callback, all callbacks that were buffered during the last frame may still be sent, even though they were unregistered.

callback onAIStateChanged(entityId, state)

Executed whenever the AI state of an entity changes

Parameters

entityId The id of the entity
state The id of the new state

callback onAllScriptValuesChanged(entityId)

Executed whenever all scripts values of an entity in the sector have been changed at once

Parameters

entityId The id of the entity

callback onBlockChanged(objectIndex, blockIndex, changeFlags)

Executed whenever a plan of an entity is changed in the sector.

Parameters

objectIndex The id of the entity
blockIndex The index of the block
changeFlags The flags of the block changes

callback onBlockDamaged(objectIndex, blockIndex, inflictorId, damage, damageType)

Executed whenever a block object is damaged in the sector. This callback is executed after the damage is dealt to the block. Don't remove the block in this callback, this will lead to a crash.

Parameters

objectIndex The index of the damaged object
blockIndex The index of the damaged block
inflictorId The id of the entity that inflicted the damage
damage The damage that was inflicted to the entity
damageType The type of damage

callback onBlockDestroyed(objectIndex, index, block, lastDamageInflictor, damageSource)

Executed whenever a block of a block object got destroyed This callback is executed *after* the block was destroyed

Parameters

objectIndex The id of the entity
index Index of the block
block The block (as removed from the plan)
lastDamageInflictor The index of the last entity that inflicted damage to the destroyed block
damageSource The source of damage

callback onBlockHealed(objectIndex, blockIndex, damage)

Executed whenever a block of an object is healed in the sector. Don't remove the block in this callback, this will lead to a crash.

Parameters

objectIndex The index of the healed object
blockIndex The index of the healed block
damage The damage the entity was healed for

callback onBlockPlanChanged(objectIndex, allBlocksChanged)

Executed whenever a plan of an entity is changed in the sector.

Parameters

objectIndex The id of the entity
allBlocksChanged A boolean that indicates whether all the blocks in the block plan have potentially changed

callback onBlocksAdded(objectIndex, wasRepaired, blockIndices)

Executed whenever new blocks are added to the entity. This callback is executed after the block was added.

Parameters

objectIndex The id of the entity
wasRepaired true if the callback was fired because of a repair operation, false otherwise
blockIndices The indices of the added blocks, as variable arguments list

callback onBlocksRemove(objectIndex, blockIndices)

Executed whenever a block will be removed from the plan by building (instead of combat). This callback is executed before the block is removed. IMPORTANT! This only fires on blocks that the player directly chose to be removed. Blocks that get removed because they don't have a connection to the root block any more get signalled after removal by 'onBlocksRemoved'.

Parameters

objectIndex The id of the entity
blockIndices The indices of the removed blocks, as variable arguments list

callback onBlocksRemoved(objectIndex, blockIndices)

Executed whenever a block is removed from the plan by building (instead of combat). This callback is executed after the block is removed.

Parameters

objectIndex The id of the entity
blockIndices The indices of the removed blocks, as variable arguments list

callback onBoardersDefeated(entityId, attackingFaction)

Executed whenever all boarders were defeated

Parameters

entityId The id of the entity
attackingFaction The index of the attacking faction

callback onBoardersLand(entityId, attackingFaction, firstLanding)

Executed when boarders land on an entity

Parameters

entityId The id of the entity
attackingFaction The index of the attacking faction
firstLanding True if these are the first boarders, false otherwise

callback onBoardingFight(entityId, attackingFaction)

Executed on every round of fighting with boarders

Parameters

entityId The id of the entity
attackingFaction The index of the attacking faction

callback onBoardingSuccessful(entityId, oldFactionIndex, newFactionIndex)

Executed whenever an entity was boarded successfully

Parameters

entityId The id of the entity
oldFactionIndex The index of the faction that owned the entity before boarding
newFactionIndex The index of the attacking faction that now owns the entity

callback onCargoChanged(objectIndex, delta, good)

Executed whenever the cargo of an entity in the sector changes. This callback is executed *after* the cargo was changed on the entity.

Parameters

objectIndex The id of the entity
delta The amount of cargo that changed
good The good that changed

callback onCargoLootCollected(collector, lootIndex, amount, good, owner)

Executed whenever trading good loot gets collected by a player

Parameters

collector The id of the entity that collected loot
lootIndex The index of the collected loot
amount The amount of goods that were collected
good The good that was inside the loot entity
owner The original owner of the cargo

callback onCollision(objectIndexA, objectIndexB, damageA, damageB, steererA, steererB)

Executed whenever two block objects collided in the sector

Parameters

objectIndexA The index of the one colliding object
objectIndexB The index of the other colliding object
damageA The damage that is inflicted to object A
damageB The damage that is inflicted to object B
steererA The steerer ID of objectA. When an object is docked, not the object itself but the steerer is the one responsible for collisions
steererB The steerer ID of objectB. When an object is docked, not the object itself but the steerer is the one responsible for collisions

callback onCraftSeatEntered(entityId, seat, playerIndex, firstPlayer)

Executed whenever a player enters a craft

Parameters

entityId The id of the entity
seat The seat index
playerIndex The index of the player that entered the seat
firstPlayer A bool indicating whether the craft's seats were empty before

callback onCraftSeatLeft(entityId, seat, playerIndex, playersRemaining)

Executed whenever a player leaves a craft

Parameters

entityId The id of the entity
seat The seat index that was previously occupied
playerIndex The index of the player that left the seat
playersRemaining A bool indicating whether there are still players on the craft

callback onCrewChanged(index)

Executed whenever the crew of a entity in the sector changes. This callback is executed *after* the crew was changed on the entity.

Parameters

index The id of the entity

callback onCrewChanged(index, delta, profession)

Executed whenever the crew of an entity in the sector changes. This callback is executed *after* the crew was changed on the entity.

Parameters

index The id of the entity
delta The amount of crewmen that changed
profession The profession of the crew that changed

callback onCrewLootCollected(collector, lootIndex)

Executed whenever trading good loot gets collected by a player

Parameters

collector The id of the entity that collected loot
lootIndex The index of the collected loot

callback onDamaged(objectIndex, amount, inflictor, damageSource, damageType)

Executed whenever an entity is damaged in the sector.

Parameters

objectIndex The index of the damaged object
amount The amount of damage that was dealt
inflictor The id of the entity that dealt the damage
damageSource The source of damage
damageType The type of damage

callback onDestroyed(index, lastDamageInflictor)

Executed whenever an entity with durability was destroyed in the sector

Parameters

index The id of the entity that was destroyed
lastDamageInflictor The index of the last entity that inflicted damage to the destroyed entity

callback onDockedByEntity(dockeeId, dockerId)

Executed whenever an entity was docked to another entity

Parameters

dockeeId The id of the entity that was docked (child)
dockerId The id of the docking entity (parent)

callback onEntityCreated(entityId)

Executed whenever a new entity is created in the sector

Parameters

entityId The index of the new entity

callback onEntityDocked(dockerId, dockeeId)

Executed whenever an entity docks to another entity

Parameters

dockerId The id of the docking entity (parent)
dockeeId The id of the entity that was docked (child)

callback onEntityEntered(shipIndex)

Executed whenever a entity enters the sector.

Parameters

shipIndex The index of the entity that entered the sector

callback onEntityJump(shipId, x, y, sectorChangeType)

Executed whenever a entity jumps into another sector.

Parameters

shipId The id of the entity that will jump out of the sector
x The x coordinate of the target sector
y The y coordinate of the target sector
sectorChangeType SectorChangeType enum what kind of sector change it is

callback onEntityRemoved(entityId)

Executed whenever an entity was removed from the sector

Parameters

entityId The index of the entity that was removed

callback onEntityUndocked(dockerId, dockeeId)

Executed whenever an entity undocks from another entity

Parameters

dockerId The id of the docking entity (parent)
dockeeId The id of the entity that was docked (child)

callback onFighterAdded(entityId, squadIndex, fighterIndex, landed)

Executed whenever a fighter is added to an entity in the sector

Parameters

entityId The id of the entity
squadIndex The index of the squad
fighterIndex The index of the fighter in the squad
landed A boolean whether the fighter landed or got added otherwise

callback onFighterLanded(entityId, squadIndex, fighterId)

Executed whenever a fighter lands in a hangar in the sector

Parameters

entityId The id of the entity the fighter landed on
squadIndex The index of the squad
fighterId The id of the fighter that landed

callback onFighterRemove(entityId, squadIndex, fighterIndex, started)

Executed whenever a fighter is removed from an entity in the sector, before it gets removed

Parameters

entityId The id of the entity
squadIndex The index of the squad
fighterIndex The index of the fighter in the squad
started A boolean whether the fighter started or got removed otherwise

callback onFighterRemoved(entityId, squadIndex, fighterIndex, started)

Executed whenever a fighter is removed from an entity in the sector, after it got removed

Parameters

entityId The id of the entity
squadIndex The index of the squad
fighterIndex The index of the fighter in the squad
started A boolean whether the fighter started or got removed otherwise

callback onFighterStarted(entityId, squadIndex, fighterId)

Executed whenever a fighter starts from a hangar in the sector

Parameters

entityId The id of the entity the fighter started from
squadIndex The index of the squad
fighterId The id of the fighter that started

callback onHealed(objectIndex, amount, inflictor)

Executed whenever an entity is healed in the sector.

Parameters

objectIndex The index of the damaged entity
amount The amount of damage that was healed
inflictor The id of the entity that dealt the damage

callback onHullHit(objectIndex, blockIndex, shooterIndex, damage, location)

Executed whenever a block object is hit by a shot in the sector. Don't delete the block that is hit by the shot, this will lead to a crash.

Parameters

objectIndex The index of the object that got shot at
blockIndex The index of the block that was hit by the shot
shooterIndex The index of the craft that fired the shot
damage The damage the shot dealt to the object
location The impact location

callback onInventoryItemLootCollected(collector, lootIndex)

Executed whenever inventory item loot gets collected by an entity

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the loot that was collected

callback onLootCollected(collector, lootIndex)

Executed whenever loot gets collected by anyone, be it player or AI faction

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the collected loot

callback onMaterialLootCollected(collector, lootIndex, materialType, value)

Executed whenever material loot gets collected by an entity

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the loot that was collected
materialType The type of material contained in the loot
value The amount of material the loot contained

callback onMoneyLootCollected(collector, lootIndex, value)

Executed whenever money loot gets collected by an entity

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the collected loot
value The amount of credits the loot contained

callback onPlanModifiedByBuilding(shipIndex)

Executed whenever the plan of an entity was modified by building, meaning adding or removing blocks.

Parameters

shipIndex The index of the ship

callback onPlayerEntered(playerIndex, sectorChangeType)

Executed whenever a player enters the sector. This callback is executed immediately before the contents of the sector are sent to the player

Parameters

playerIndex Index of the player
sectorChangeType The kind of sector change that is happening

callback onPlayerLeft(playerIndex, sectorChangeType)

Executed whenever a player leaves the sector. Executed after the player left.

Parameters

playerIndex Index of the player
sectorChangeType The kind of sector change that is happening

callback onRestoredFromDisk(time)

Executed when a sector is loaded/restored from disk. This callback is called after the "restore" callback, for both entity and sector scripts.

Parameters

time The time since the sector has been last updated. This value can be 0 or too small after database corruptions.

callback onScriptAdded(entityId, scriptIndex, scriptPath)

Executed after a script was added to an entity in the sector

Parameters

entityId The id of the entity
scriptIndex The index of the new script
scriptPath The path of the new script

callback onScriptRemoved(entityId, oldScriptIndex, scriptPath)

Executed after a script was removed from an entity in the sector

Parameters

entityId The id of the entity
oldScriptIndex The old index of the script that was removed
scriptPath The path of the old script

callback onScriptValueChanged(entityId, name, value)

Executed whenever a script value of an entity in the sector was changed

Parameters

entityId The id of the entity
name The name of the value
value The new value

callback onSectorGenerated(time)

Executed when a sector is generated/created for the first time for both entity and sector scripts.

Parameters

time The time the game has been running already. This value can be 0 or too small after database corruptions.

callback onSetForDeletion(entityId, deletionType)

Executed whenever an entity is to be deleted.

Parameters

entityId The index of the entity that is to be deleted
deletionType The deletion type

callback onShieldActivate(entityId)

Executed whenever a shield activates in the sector

Parameters

entityId The id of the entity

callback onShieldDamaged(entityId, amount, damageType, inflictorId)

Executed whenever a shield is damaged in the sector

Parameters

entityId The id of the entity
amount The amount of damage inflicted
damageType The type of damage dealt
inflictorId The id of the entity that inflicted the damage

callback onShieldDeactivate(entityId)

Executed whenever a shield deactivates in the sector

Parameters

entityId The id of the entity

callback onShieldHealed(entityId, amount)

Executed whenever a shield is healed in the sector

Parameters

entityId The id of the entity
amount The amount of damage healed

callback onShieldHit(objectIndex, shooterIndex, damage, location)

Executed whenever an object's shield is hit by a shot in the sector.

Parameters

objectIndex The index of the object that got shot at
shooterIndex The index of the craft that fired the shot
damage The damage the shot dealt to the object
location The impact location

callback onShotCreated(shotIndex)

Executed whenever a new shot is created in the sector

Parameters

shotIndex The index of the new shot

callback onShotFired(entityId)

Executed whenever a shot is fired in the sector

Parameters

entityId The index of the firing entity (weapon)

callback onShotHit(objectIndex, shooterIndex, location)

Executed whenever a block object is hit by a shot in the sector.

Parameters

objectIndex The index of the object that got shot at
shooterIndex The index of the craft that fired the shot
location The impact location

callback onSquadAdded(entityId, index)

Executed whenever a squad is added to an entity in the sector

Parameters

entityId The id of the entity
index The index of the squad

callback onSquadOrdersChanged(entityId, squadIndex, orders, targetId)

Executed whenever the orders of a squad change in the sector

Parameters

entityId The id of the entity
squadIndex The index of the squad
orders The orders of the squad
targetId The target assigned to the fighters

callback onSquadRemove(entityId, index)

Executed whenever a squad is removed from an entity in the sector, before the squad gets removed

Parameters

entityId The id of the entity
index The index of the squad

callback onSquadRemoved(entityId, index)

Executed whenever a squad is removed from an entity in the sector, after the squad got removed

Parameters

entityId The id of the entity
index The index of the squad

callback onStartFiring(entityId)

Executed whenever an entity starts firing in the sector

Parameters

entityId The index of the firing entity (weapon)

callback onStopFiring(entityId)

Executed whenever an entity stops firing in the sector

Parameters

entityId The index of the firing entity (weapon)

callback onSystemsChanged(shipIndex)

Executed whenever the systems of a ship in the sector changed. This callback is executed *after* the system was changed on the entity.

Parameters

shipIndex The index of the ship

callback onSystemUpgradeLootCollected(collector, lootIndex)

Executed whenever system upgrade loot gets collected by an entity

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the loot that was collected

callback onTorpedoHit(objectIndex, shooterIndex, torpedoIndex)

Executed whenever a block object is hit by a torpedo in the sector.

Parameters

objectIndex The index of the object that got shot at
shooterIndex The index of the craft that fired the torpedo
torpedoIndex The index of the torpedo that hit the object

callback onTorpedoHullHit(objectIndex, blockIndex, shooterIndex, damage, torpedoIndex)

Executed whenever a block object is hit by a torpedo in the sector. Don't delete the block that is hit by the torpedo, this will lead to a crash.

Parameters

objectIndex The index of the object that got shot at
blockIndex The index of the block that was hit by the torpedo
shooterIndex The index of the craft that fired the torpedo
damage The damage the torpedo dealt to the object
torpedoIndex The index of the torpedo that hit the object

callback onTorpedoLaunched(entityId, torpedoId)

Executed whenever a torpedo was launched from an entity

Parameters

entityId The id of the entity
torpedoId The id of the launched torpedo

callback onTorpedoShieldHit(objectIndex, shooterIndex, damage, torpedoIndex)

Executed whenever an object's shield is hit by a torpedo in the sector.

Parameters

objectIndex The index of the object that got shot at
shooterIndex The index of the craft that fired the torpedo
damage The damage the torpedo dealt to the object
torpedoIndex The index of the torpedo that hit the object

callback onTurretAdded(shipIndex, turretIndex)

Executed whenever a turret was added to a ship in the sector

Parameters

shipIndex The id of the entity that turret was attached to
turretIndex The index of the turret

callback onTurretDestroyed(turretIndex, shipIndex, lastDamageInflictor)

Executed whenever a turret was destroyed in the sector

Parameters

turretIndex The index of the turret that was destroyed
shipIndex The id of the entity that turret was attached to
lastDamageInflictor The index of the last entity that inflicted damage to the destroyed entity

callback onTurretLootCollected(collector, lootIndex)

Executed whenever turret loot gets collected by an entity controlled by AI

Parameters

collector The id of the entity which collected the loot
lootIndex The index of the collected loot

callback onTurretRemoved(shipIndex, turretIndex)

Executed whenever a turret was removed in the sector

Parameters

shipIndex The id of the entity that turret was attached to
turretIndex The index of the turret

callback onTurretRemovedByPlayer(shipIndex, turretIndex)

Executed whenever a turret was removed from a ship by the player in the sector

Parameters

shipIndex The id of the entity that turret was attached to
turretIndex The index of the turret

callback onUndockedFromEntity(dockeeId, dockerId)

Executed whenever an entity was undocked from another entity

Parameters

dockeeId The id of the entity that was docked (child)
dockerId The id of the docking entity (parent)

Overview
Home Functions Search
Search:

This is the official documentation for the scripting API of Avorion. This documentation is automatically generated and not necessarily complete. Depending on the context in which functions exist, some documentation such as descriptions, return values or variable names or types may be missing.

Work in Progress. Documentation of Avorion Version: 2.5.7 c8e4beec84f7