Lua doc lua_bindings

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

NameTypeDescription
fleet.idintFleet ID
fleet.namestringFleet name
fleet.flagship_idintThe flagship's ship ID
fleet.flagship_namestringThe flagship's name
fleet.member_countintTotal ships (flagship + members)
fleet.formation_typestring"v", "blob", "sphere", or "line"
fleet.faction_idstringFlagship's faction ID
fleet.sector_idintSector the fleet is in (flagship's sector)
fleet.solar_system_idintSolar system the fleet is in
fleet.x / y / zfloatFlagship position
fleet.status_messagestringFlagship status message
fleet.shieldfloatSum of shield across all ships
fleet.shield_maxfloatSum of shield_max across all ships
fleet.hullfloatSum of hull across all ships
fleet.hull_maxfloatSum of hull_max across all ships
fleet.energyfloatMin energy across all ships (can we fight)
fleet.energy_maxfloatMin energy_max across all ships
fleet.speedfloatMin current speed across all ships
fleet.max_speedfloatMin max_speed across all ships (the slowest sets fleet pace)
fleet.module_countintTotal installed modules across all ships
fleet.modules_activeintTotal currently-active modules across all ships
fleet.locked_target_countintTotal locks across all ships
fleet.cargo_usedintTotal cargo volume in use
fleet.cargo_maxintTotal cargo capacity
fleet.is_cargo_fullboolTrue if any ship's cargo is at capacity
fleet.is_dockedboolTrue only when every ship is docked
fleet.docked_at_idintFlagship's docking station ID, 0 otherwise
fleet.travelingboolTrue while an autonomous fleet.travel_to(...) is in progress

Methods

Action methods iterate the fleet and queue per-ship commands automatically.

MethodDescription
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

NameTypeDescription
sector.idintSector ID
sector.namestringSector name
sector.solar_system_idintParent solar system ID
sector.is_activeboolWhether sector is active
sector.space_object_countintNumber of objects in sector
sector.x / y / zfloatPosition coordinates

Methods

MethodDescription
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

NameTypeDescription
solar_system.idintSolar system ID
solar_system.namestringSolar system name
solar_system.securityfloatSecurity level
solar_system.threat_levelfloatThreat level
solar_system.faction_idstringControlling faction ID
solar_system.is_activeboolWhether system is active
solar_system.x / y / zfloatPosition coordinates
solar_system.sector_countintNumber of sectors
solar_system.jumpgate_countintNumber of jumpgates

Methods

MethodDescription
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

NameTypeDescription
player.idintPlayer ID
player.namestringPlayer name
player.moneyfloatAvailable currency
player.net_worthfloatNet worth (currency + asset value)
player.faction_idstringPlayer faction ID
player.current_ship_idintID of the player's currently piloted ship
player.discovered_percentagefloatFraction of the galaxy the player has explored
player.ship_countintNumber of ships the player owns

Methods

MethodDescription
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.

NameShapeUse case
vAttack wedge, wings spread back and outward (XZ plane)Standard pursuit / attack
blobTight asymmetric cluster within ~250 unitsDefensive mutual coverage
sphere8 members on cube vertices (~300 unit radius), leader at centreAll-round 3D coverage
lineAll ships side-by-side on the X axisMaximum broadside firepower

market — Market Operations

Queue buy/sell commands and read live order data for any station.

Action methods

MethodDescription
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:

FieldTypeDescription
pricenumberPrice per unit
quantityintOriginal order quantity
remaining_quantityintUnits still available
station_idintStation the order is posted at
item_idstringItem ID
user_idstringPlayer 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.

FieldTypeDescription
idstringItem ID
namestringDisplay name
descriptionstringItem description
base_pricenumberBase market price
volumenumberVolume per unit (m³)
massnumberMass per unit
raritystringcommon, uncommon, rare, epic, legendary
classstringItem class
group_idstringItem group ID
module_typestringModule type if applicable
factory_typestringFactory type for manufactured items
ammo_typestringAmmo type for weapons
sizestringFrigate, Battleship, or Capital
damagenumberWeapon damage
rangenumberWeapon range
rofnumberRate of fire
cooldownnumberModule cooldown
active_energynumberEnergy used on activation
passive_energynumberPassive 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:

FieldTypeDescription
idstringGroup ID
namestringGroup name
descriptionstringGroup description
parent_idstringParent group ID, empty if top-level
categorystringCategory label
is_activeboolWhether the group is active
sort_orderintDisplay 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

MethodDescription
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)