Skip to content

Mod Lua Capabilities and Load order

Ian Norton edited this page Apr 27, 2024 · 6 revisions

Lua Script Order

The game loads a separate lua interpreter (process/sandbox) for each vehicle screen (navigation, holomap, damage, control, logistics etc), one for the HUD and one for the pause screen.

Scripts are loaded in the following order:

  • library_enum.lua
  • library_util.lua
  • library_vehicle.lua
  • library_ui.lua
  • screen/pause/hud script

It helps to think of there being one file made up of the above concatenated in order. Lua loads and processes as it goes. Once loaded the begin() function will be called once.

Then there will be periodic calls to the input functions and finally the update() function. eg:

# once per screen
begin()

# once per refresh (slower for non-connected screens)
input_pointer(hovered, x, y)
input_scroll(dy)
input_axis(x, y, z, w)
update()

# some screens (pause, transmissions) also support input_text when keys are pressed
input_text(text)

# before a refresh if you press a key
input_event(event, action)

Capabilities

There seem to be four groups of access and support functions open to each lua instance.

HUD

  • able to inspect the x,y,z (lon, alt, lat) position of all objects in the game world (bombs, torps, missiles, ships, aircraft, vehicles, turrets)
  • able to inspect the movement vector (pitch, heading, slip) of all units
  • able to inspect the linear speed of all units
  • able to inspect the hardpoint content of all units (what kind of weapon)
  • able to inspect multiplayer names and who is manually in control of units
  • able to inspect ammunition and health values on all units
  • obtains positions of units using the vehicle:get_position() method of vehicle objects
  • cannot view waypoints
  • cannot play sounds
  • can draw on the screen using the triangles interface
  • can change screen background areas to one of the special backgrounds (ocean current, depth etc)
  • can read most of the game settings values (eg key bindings, but also volume settings)

Control Screen

  • able to inspect the x,z (lon, lat) position of all objects in the game world (bombs, missiles, ships, aircraft, vehicles, turrets)
    • can obtain the altitude of units by measuring the vertical distance between a drydock (known alt=0) and the unit
  • able to inspect the hardpoint content of all units (what kind of weapon)
  • able to inspect multiplayer names and who is manually in control of units
  • able to inspect ammunition and health values on all units
  • obtains positions of units using the vehicle:get_position_xz() method of vehicle objects
  • can view/add/remove/edit waypoints
  • can draw on the screen using the triangles interface
  • can change screen background areas to one of the special backgrounds (ocean current, depth etc)
  • can play sounds/transmissions
  • can read most of the game settings values (eg key bindings, but also volume settings)
  • can manage the loadout of units attached to a carrier
  • can manage the loadout of a carrier attached to a drydock
  • can launch a carrier from the drydock
  • can launch/dock a unit from/to the carrier
  • can manage purchase orders for island turrets
  • can view barge content
  • can manage logistics orders and barge orders
  • can manage factory produciton
  • can read the carrier's depth sensors
  • can get the ocean depth, fog, wind and precipitation values from any map point

Holomap

Same as control screens, but also:

  • Toggle some aspects of the holomap rendering (turn islands/units on/off)
  • Cannot play sounds

Pause

Same as control screens, but also:

  • Can transfer players between carriers
  • Can return to bridge
  • Can save/load games (single player or desktop host only)
  • Can invite to hosted multiplayer
  • Can manage most game settings
  • Can kick/ban players in multiplayer
  • Cannot play sounds