Lua Bindings
Reference documentation generated from lua_bindings.md.
Lua Bindings
Bindings are global tables available in every Lua script. They provide read access to game state and action methods that queue server commands for execution on the next tick.
Scripts run at the fleet level. A solo ship is a fleet of one — same API, same callbacks. Action methods on fleet iterate every member of the fleet and queue per-ship commands; aggregate properties combine ship-level values (sums for pools, mins for weakest link
stats).
Properties vs. methods. Properties are plain fields and must be accessed without parentheses (e.g., fleet.is_docked, sector.name, fleet.member_count). The runtime snapshots their values into the binding table before each callback. Methods — actions that queue commands and array/object queries — are called normally (e.g., fleet.activate_all_modules(), sector.get_enemy_ids()).
fleet — The Script's Fleet
The primary binding. Every script controls a fleet; solo ships are wrapped in a singleton fleet automatically.
Properties
| Name | Type | Description |
|---|---|---|
fleet.id | int | Fleet ID |
fleet.name | string | Fleet name |
fleet.flagship_id | int | The flagship's ship ID |
fleet.flagship_name | string | The flagship's name |
fleet.member_count | int | Total ships (flagship + members) |
fleet.formation_type | string | "v", "blob", "sphere", or "line" |
fleet.faction_id | string | Flagship's faction ID |
fleet.sector_id | int | Sector the fleet is in (flagship's sector) |
fleet.solar_system_id | int | Solar system the fleet is in |
fleet.x / y / z | float | Flagship position |
fleet.status_message | string | Flagship status message |
fleet.shield | float | Sum of shield across all ships |
fleet.shield_max | float | Sum of shield_max across all ships |
fleet.hull | float | Sum of hull across all ships |
fleet.hull_max | float | Sum of hull_max across all ships |
fleet.energy | float | Min energy across all ships (can we fight) |
fleet.energy_max | float | Min energy_max across all ships |
fleet.speed | float | Min current speed across all ships |
fleet.max_speed | float | Min max_speed across all ships (the slowest sets fleet pace) |
fleet.module_count | int | Total installed modules across all ships |
fleet.modules_active | int | Total currently-active modules across all ships |
fleet.locked_target_count | int | Total locks across all ships |
fleet.cargo_used | int | Total cargo volume in use |
fleet.cargo_max | int | Total cargo capacity |
fleet.is_cargo_full | bool | True if any ship's cargo is at capacity |
fleet.is_docked | bool | True only when every ship is docked |
fleet.docked_at_id | int | Flagship's docking station ID, 0 otherwise |
fleet.traveling | bool | True while an autonomous fleet.travel_to(...) is in progress |
Methods
Action methods iterate the fleet and queue per-ship commands automatically.
| Method | Description |
|---|---|
fleet.get_member_ids() | 1-based array of all ship IDs (flagship first) |
fleet.get_locked_target_ids() | Union of locked target IDs across the fleet (deduped) |
fleet.contains(ship_id) | true if ship_id is the flagship or a fleet member. Use this in callbacks to filter events that pass a source_id or member ship ID. |
fleet.get_inventory() | Returns array of {item_id, name, quantity, volume} aggregated across the fleet |
fleet.lock_target(target_id) | Every member begins locking the target |
fleet.unlock_target(target_id) | Every member releases its lock |
fleet.warp_to(sector_id) | Warp the fleet to a sector in the current solar system |
fleet.dock(station_id) | Dock the whole fleet at a station |
fleet.undock() | Undock every docked member |
fleet.jump(jumpgate_id) | Jump the whole fleet through a jumpgate |
fleet.travel_to(sector_id) | Travel to any sector in the galaxy. The server chains undock / warp / jump as needed and fires on_travel_finished(sector_id) on arrival or on_travel_failed(reason) if no route exists. Calling again with a different target retargets the in-flight trip. |
fleet.activate_all_modules([target_id]) | Activate every module on every ship |
fleet.deactivate_all_modules() | Deactivate every module on every ship |
fleet.align_to(target_id) | Every member faces the target |
fleet.keep_at_range(target_id, distance) | Every member maintains distance from the target |
fleet.orbit_at_range(target_id, distance) | Every member orbits the target on the XZ plane |
fleet.set_status(message) | Set the status message on every member |
fleet.broadcast(message) | Flagship broadcasts to all of the player's other fleets |
fleet.transfer_inventory(target_id, item_id, amount) | Flagship transfers items to a station |
fleet.unload_to_station(item_id) | Each docked member unloads item_id to its station |
sector — Current Sector
Read-only information about the sector the ship is currently in.
Properties
| Name | Type | Description |
|---|---|---|
sector.id | int | Sector ID |
sector.name | string | Sector name |
sector.solar_system_id | int | Parent solar system ID |
sector.is_active | bool | Whether sector is active |
sector.space_object_count | int | Number of objects in sector |
sector.x / y / z | float | Position coordinates |
Methods
| Method | Description |
|---|---|
sector.get_space_object_ids() | All object IDs |
sector.get_asteroid_ids() | Asteroid IDs |
sector.get_station_ids() | Station IDs |
sector.get_enemy_ids() | Enemy IDs (by faction standing) |
sector.get_enemy_ids_by_types({"type1", ...}) | Enemy IDs filtered by scale types, ordered by type priority. Types: "frigate", "battleship", "capital", "station" |
sector.get_friend_ids() | Friendly IDs |
sector.get_neutral_ids() | Neutral IDs |
sector.get_closest_enemy_id() | Nearest enemy ID, or 0 |
sector.get_closest_asteroid_id() | Nearest asteroid ID, or 0 |
sector.get_closest_station_id() | Nearest station ID, or 0 |
sector.distance_to(object_id) | Distance to object |
sector.get_space_object(object_id) | Object details as table (id, name, type, factionid, x, y, z, speed, isship, isstation, isasteroid, shield, hull) |
solar_system — Current Solar System
Read-only information about the solar system the ship is in.
Properties
| Name | Type | Description |
|---|---|---|
solar_system.id | int | Solar system ID |
solar_system.name | string | Solar system name |
solar_system.security | float | Security level |
solar_system.threat_level | float | Threat level |
solar_system.faction_id | string | Controlling faction ID |
solar_system.is_active | bool | Whether system is active |
solar_system.x / y / z | float | Position coordinates |
solar_system.sector_count | int | Number of sectors |
solar_system.jumpgate_count | int | Number of jumpgates |
Methods
| Method | Description |
|---|---|
solar_system.get_sector_ids() | Sector IDs |
solar_system.get_jumpgate_ids() | Jumpgate IDs |
solar_system.get_station_ids() | Station IDs |
solar_system.get_asteroid_belt_ids() | Asteroid belt IDs |
solar_system.get_jump_distance(solar_system_id) | Jump distance to another system, or -1 |
solar_system.connects_to(solar_system_id) | Whether directly connected |
player — Owning Player
Read-only information about the player that owns this ship, plus lookups into the player's other ships. Used most often inside on_broadcast_received to resolve the broadcasting ship's location.
Properties
| Name | Type | Description |
|---|---|---|
player.id | int | Player ID |
player.name | string | Player name |
player.money | float | Available currency |
player.net_worth | float | Net worth (currency + asset value) |
player.faction_id | string | Player faction ID |
player.current_ship_id | int | ID of the player's currently piloted ship |
player.discovered_percentage | float | Fraction of the galaxy the player has explored |
player.ship_count | int | Number of ships the player owns |
Methods
| Method | Description |
|---|---|
player.get_ship_ids() | 1-based array of all owned ship IDs |
player.get_ships() | 1-based array of ship tables (see fields below) |
player.get_ship_by_id(ship_id) | Single ship table, or nil if the ship is not owned by the player |
Each ship table from get_ships() / get_ship_by_id() has these fields: id, name, shield, shield_max, hull, hull_max, energy, energy_max, speed, max_speed, sector_id, solar_system_id, is_docked, docked_at_id, traveling, blueprint_id, status_message, faction_id, script_running, scale.
Formation types
Read fleet.formation_type to inspect; formation control is engine-driven.
| Name | Shape | Use case |
|---|---|---|
v | Attack wedge, wings spread back and outward (XZ plane) | Standard pursuit / attack |
blob | Tight asymmetric cluster within ~250 units | Defensive mutual coverage |
sphere | 8 members on cube vertices (~300 unit radius), leader at centre | All-round 3D coverage |
line | All ships side-by-side on the X axis | Maximum broadside firepower |
market — Market Operations
Queue buy/sell commands and read live order data for any station.
Action methods
| Method | Description |
|---|---|
market.buy(station_id, item_id, quantity, max_price) | Buy from the cheapest available sell orders up to max_price |
market.sell(station_id, item_id, quantity, min_price) | Sell to the highest available buy orders at or above min_price |
market.create_buy_order(station_id, item_id, quantity, price) | Post a buy order; money is deducted upfront |
market.create_sell_order(station_id, item_id, quantity, price) | Post a sell order; items are removed from station inventory upfront |
Query methods
market.get_sell_orders(station_id, item_id)
Returns a 1-based array of sell order tables at the given station, sorted by ascending price.
Each entry:
| Field | Type | Description |
|---|---|---|
price | number | Price per unit |
quantity | int | Original order quantity |
remaining_quantity | int | Units still available |
station_id | int | Station the order is posted at |
item_id | string | Item ID |
user_id | string | Player ID if a player order, empty string for station orders |
market.get_buy_orders(station_id, item_id)
Returns a 1-based array of buy order tables at the given station (same fields as above).
Example
function on_timer(timer_name)
if timer_name ~= "tick" then return end
local station_id = ship.docked_at_id
if station_id == 0 then return end
-- Find cheapest sell order for hull blocks
local orders = market.get_sell_orders(station_id, "hull")
if #orders > 0 then
local best = orders[1] -- already sorted lowest first
local item = items.get_item("hull")
if best.price < item.base_price * 0.95 then
market.buy(station_id, "hull", best.remaining_quantity, best.price)
end
end
set_timer("tick", 10)
end
items — Item & Group Data
Read-only access to the game's item catalogue and item groups.
Methods
items.get_item(item_id)
Returns a table of item fields, or nil if the item does not exist.
| Field | Type | Description |
|---|---|---|
id | string | Item ID |
name | string | Display name |
description | string | Item description |
base_price | number | Base market price |
volume | number | Volume per unit (m³) |
mass | number | Mass per unit |
rarity | string | common, uncommon, rare, epic, legendary |
class | string | Item class |
group_id | string | Item group ID |
module_type | string | Module type if applicable |
factory_type | string | Factory type for manufactured items |
ammo_type | string | Ammo type for weapons |
size | string | Frigate, Battleship, or Capital |
damage | number | Weapon damage |
range | number | Weapon range |
rof | number | Rate of fire |
cooldown | number | Module cooldown |
active_energy | number | Energy used on activation |
passive_energy | number | Passive energy drain |
items.get_all_items()
Returns a 1-based array of all items (same table structure as get_item).
items.get_items_by_group(group_id)
Returns a 1-based array of items belonging to the given group.
items.get_all_groups()
Returns a 1-based array of all item group tables.
Each group entry:
| Field | Type | Description |
|---|---|---|
id | string | Group ID |
name | string | Group name |
description | string | Group description |
parent_id | string | Parent group ID, empty if top-level |
category | string | Category label |
is_active | bool | Whether the group is active |
sort_order | int | Display sort order |
items.get_group(group_id)
Returns a single group table, or nil if not found.
Example
function init()
-- Print all weapons with damage > 100
local all = items.get_all_items()
for i = 1, #all do
local item = all[i]
if item.damage > 100 then
print(item.name .. " dmg=" .. item.damage .. " range=" .. item.range)
end
end
-- Find cheapest ore group item on the market
local ore_items = items.get_items_by_group("ore")
local best_price = math.huge
local best_id = nil
for i = 1, #ore_items do
local orders = market.get_sell_orders(params.station_id, ore_items[i].id)
if #orders > 0 and orders[1].price < best_price then
best_price = orders[1].price
best_id = ore_items[i].id
end
end
if best_id then
market.buy(params.station_id, best_id, 10, best_price)
end
end
stats — Statistics Tracking
Register and track custom statistics with automatic time-series consolidation.
Methods
| Method | Description |
|---|---|
stats.register_stat(name, rule) | Register a custom stat. Rules: "sum", "last", "average" |
stats.push_stat(name, value) | Push a value to a custom stat |
stats.get_stat_history(name, resolution) | Get entity stat history. Resolution: "realtime", "shortterm", "midterm", "longterm" |
stats.get_global_stat_history(name, resolution) | Get global stat history (same resolutions) |