Lua_SyncedRead - beyond-all-reason/springrts_engine_wiki_mirror GitHub Wiki

Development < Lua Scripting <

Game

Special TeamID Variables

The following special TeamIDs are not supported by all functions. For Widgets, instead of Spring.MY_UNITS, use Spring.GetLocalTeamID().

GameStates

RulesParams

The following functions allow to save data per game, team and unit. The advantage of it is that it can be read from anywhere (even from LuaUI and AIs!) String values are new since 95.0.

Mod-/Map-Options

Warning: boolean values are not transfered from C to Lua correctly. For this reason the respective option has to be converted to a number and checked accordingly via an IF statement as shown below:

if (tonumber(Spring.GetModOptions.exampleOption) == 1) then...end

The following check therefore is insufficient!

if (Spring.GetModOptions.exampleOption) then...end

Speed/Time

Vectors

Sides/Factions

or

or

Teams

StartBoxes/StartPositions

Player,Team,Ally Lists/Info

Note: AIs are associated to teamIDs (and do not have playerIDs). Code to cycle through AI teamIDs can be found here

or

 table stats = {
      [1] = {
        "time"             = number,
        "frame"            = number,
        "metalUsed"        = number,
        "metalProduced"    = number,
        "metalExcess"      = number,
        "metalReceived"    = number,
        "metalSent"        = number,
        "energyUsed"       = number,
        "energyProduced"   = number,
        "energyExcess"     = number,
        "energyReceived"   = number,
        "energySent"       = number,
        "damageDealt"      = number,
        "damageReceived"   = number,
        "unitsProduced"    = number,
        "unitsDied"        = number,
        "unitsReceived"    = number,
        "unitsSent"        = number,
        "unitsCaptured"    = number,
        "unitsOutCaptured" = number,
        "unitsKilled"      = number
      }, ...
   }

Teams/PlayersAllied

Units

GetUnits

    radius     = unit radius
    px, py, pz = unit position
    [(nx * px) + (ny * py) + (nz * pz) + (d - radius)]  <=  0

Unit Informations

unitStates = {
    "firestate" = number,
    "movestate" = number,
    "repeat" = boolean,
    "cloak" = boolean,
    "active" = boolean,
    "trajectory" = boolean,
    ["autoland" = boolean,]
    ["autorepairlevel" = number,]
    ["loopbackattack" = boolean]
  }

or

or

defDimensions =    {
      "height" = number,
      "radius" = number,
      "midx"   = number,
      "minx"   = number,
      "maxx"   = number,
      "midy"   = number,
      "miny"   = number,
      "maxy"   = number,
      "midz"   = number,
      "minz"   = number,
      "maxz"   = number
    }

Unit Weapon Informations

or

  "reloadState" == "reloadFrame"
  "reloadTime"
  "accuracy"
  "sprayAngle"
  "range"
  "projectileSpeed"
  "burst"
  "burstRate"
  "projectiles"

  The following 4 tags were added in 104.0:
  "salvoError"
  "salvoLeft"
  "nextSalvo"
  "targetMoveError"
  "paralyzeDamageTime"
  "impulseFactor"
  "impulseBoost"
  "craterMult"
  "craterBoost"
  "dynDamageExp"
  "dynDamageMin"
  "dynDamageRange"
  "dynDamageInverted"
  "craterAreaOfEffect"
  "damageAreaOfEffect"
  "edgeEffectiveness"
  "explosionSpeed"
  - or -
  an armor type index to get the damage against it.

or

Unit LOS

Unit Pieces

pieceInfo = {
    "name"     = string "piecename",
    "isEmpty"  = boolean,
    "children" = { [1] = string "piecename", ... },
    "min"      = { [1] = number x, [2] = number y, [3] = number z },
    "max"      = { [1] = number x, [2] = number y, [3] = number z },
    "offset"   = { [1] = number x, [2] = number y, [3] = number z },
    "parent" = string "parentpiecename",
  }

CommandQueues

Spring.GetCommandQueue function is identical to Spring.GetUnitCommands function. Here only Spring.GetUnitCommands will be listed:

or

commandQueueTable = {
     [1] = {
       "id"      = number,
       "params"  = { [1] = number, ...},
       "options" = {
         "coded"    = number,
         "alt"      = boolean,
         "ctrl"     = boolean,
         "shift"    = boolean,
         "right"    = boolean,
         "internal" = boolean,
         "meta"    = boolean
       }
     }, ...
   }

or

commandQueueTable = {
     [1] = {
       "id"      = number,
       "params"  = { [1] = number, ...},
       "options" = {
         "coded"    = number,
         "alt"      = boolean,
         "ctrl"     = boolean,
         "shift"    = boolean,
         "right"    = boolean,
         "internal" = boolean,
         "meta"    = boolean
       }
     }, ...
   }

Command Descriptions/Buttons

commandDescTable = {
      [1] = {
        "id"          = number,
        "type"        = number,
        "name"        = string,
        "action"      = string,
        "tooltip"     = string,
        "texture"     = string,
        "cursor"      = string,
        "hidden"      = boolean,
        "disabled"    = boolean,
        "showUnique"  = boolean,
        "onlyTexture" = boolean,

        "params"      = { [1] = string, ... }
     }, ...
   }

Features

GetFeatures

Feature Informations

Feature Pieces

Works analogue to #Unit_Pieces

pieceInfo = {
    "name"     = string "piecename",
    "isEmpty"  = boolean,
    "children" = { [1] = string "piecename", ... },
    "min"      = { [1] = number x, [2] = number y, [3] = number z },
    "max"      = { [1] = number x, [2] = number y, [3] = number z },
    "offset"   = { [1] = number x, [2] = number y, [3] = number z },
    "parent" = string "parentpiecename",
  }

COB

Ground

Elevation is y. Water level is always at y=0. Ground height can be changed during play (terraform or deformation).

or

Test Orders

blocking can be:
    0 - blocked
    1 - mobile unit in the way
    2 - free  (or if featureID is != nil then with a blocking feature that can be reclaimed)

  facing can be:
    0, "s", "south"
    1, "e", "east"
    2, "n", "north"
    3, "w", "west"

PathFinding

table waypoints = {
   [1] = { x,y,z }, ...
   }

table waypointIndices= {
     [1] = startIdxOfDetailedPath,
     [2] = startIdxOfDetailedEstimatedPath1,
     [3] = startIdxOfDetailedEstimatedPath2,
   }

  GetUnitEstimatedPath() returns 2 tables:
    1 table the waypoints and 1 table with indices (in the waypoint table)
    when a new (more lazy) pathfinding algorithm  begins.
    So the waypoint table contains 3 different levels of details.

LOS

Projectiles

Pre version 95.0 return arguments: -> nil | number targetID, string targetTypeStr

  targetTypeStr could be one of:
    'u' - unit
    'f' - feature
    'p' - projectile

  while targetTypeInt was one of:
    string.byte('g') := GROUND
    string.byte('u') := UNIT
    string.byte('f') := FEATURE
    string.byte('p') := PROJECTILE

The string tag can be:
  "paralyzeDamageTime"
  "impulseFactor"
  "impulseBoost"
  "craterMult"
  "craterBoost"
  "dynDamageExp"
  "dynDamageMin"
  "dynDamageRange"
  "dynDamageInverted"
  "craterAreaOfEffect"
  "damageAreaOfEffect"
  "edgeEffectiveness"
  "explosionSpeed"
  - or -
  an armor type index to get the damage against it.

category: Lua

⚠️ **GitHub.com Fallback** ⚠️