Lua UnsyncedRead

From Spring
Jump to: navigation, search

Development < Lua Scripting < Lua UnsyncedRead

Unsynced Read

Replay/Spectating

Spring.IsReplay

 ( ) -> nil | boolean

Spring.GetReplayLength New in version 92.0

 ( ) -> nil | number (in gameframes)

Spring.GetSpectatingState

 ( ) -> boolean spectating, boolean fullView, boolean fullSelect

Game/Menu Name

Spring.GetGameName New in version 104.0

 ( ) -> string name

Returns the name from Modinfo.lua.

Spring.GetMenuName New in version 104.0

 ( ) -> string name

ModUI

Spring.GetModUICtrl

 ( ) -> boolean

MyInfo

Spring.GetMyAllyTeamID

 ( ) -> number

Spring.GetMyTeamID

 ( ) -> number

Spring.GetMyPlayerID

 ( ) -> number

Local Player,Team,Ally

Redundant same as the GetMyXYZ functions!

Spring.GetLocalPlayerID

 ( ) -> number playerID

Spring.GetLocalTeamID

 ( ) -> number teamID

Spring.GetLocalAllyTeamID

 ( ) -> number allyID

Team/Player Info

Spring.GetPlayerRoster

 ( [number sortType] | [number sortType], [bool showPathingPlayers] ) ->
   nil | playerTable = {
           [1] = {
             string  name,
             number  playerID,
             number  teamID,
             number  allyTeamID,
             boolean spectator,
             number  cpuUsage,
             number  pingTime
           },
           etc...
         }
  if pingTime is == -1, the player is pathfinding, in order to find the progress, use:
  cpuUsage&0x1 if it's PC or BO, cpuUsage& 0xFE to get path res, (cpuUsage>>8)*1000
  for the progress
   Sort codes:
    1 = Sort by allies  (the default)
    2 = Sort by teamID
    3 = Sort by playerName
    4 = Sort by CPU usage
    5 = Sort by ping time

Spring.GetTeamColor

 ( number teamID ) -> nil | number r, number g, number b,  number a

Spring.GetTeamOrigColor

 ( number teamID ) -> nil | number r, number g, number b,  number a

Spring.GetPlayerTraffic

 ( number playerID [, number packetID] ) -> number

Sound

Spring.GetSoundStreamTime

 ( ) -> number playedTime, number totalTime

Camera

Spring.GetCameraNames

 ( ) -> { [camName] = number camNum, ... }

Spring.GetCameraState

 ( ) -> { "name" = string, "mode" = number camIdx, state1 = number, state2 = number, ... }

See Lua_camState for details about Spring.GetCameraState output.

Spring.GetCameraPosition

 ( ) -> number x, number y, number z

Spring.GetCameraDirection

 ( ) -> number forward_x, number forward_y, number forward_z

Spring.GetCameraFOV

 ( ) -> number fov

Spring.GetCameraVectors

 ( ) -> vectorTable = {
   forward   = { [1] = number x, [2] = number y, [3] = number z },
   up        = { [1] = number x, [2] = number y, [3] = number z },
   right     = { [1] = number x, [2] = number y, [3] = number z },
   top       = { [1] = number x, [2] = number y, [3] = number z },
   bottom    = { [1] = number x, [2] = number y, [3] = number z },
   leftside  = { [1] = number x, [2] = number y, [3] = number z },
   rightside = { [1] = number x, [2] = number y, [3] = number z }
 }

Inview

Spring.GetVisibleUnits

 ( [number teamID = -1 [, number radius = 30 [, boolean Icons = true ]]] )
   -> nil | unitTable = { [1] = number unitID, ... }

Spring.GetVisibleFeatures

 ( [number allyTeamID = -1 [, number radius = 30 [, boolean Icons = true [, boolean geos = true ]]]] )
   -> nil | featureTable = { [1] = number featureID, ... }

Spring.IsAABBInView

 ( number minX, number minY, number minZ,
   number maxX, number maxY, number maxZ ) -> nil | boolean

Spring.IsSphereInView

 ( number x, number y, number z [, number radius ] ) -> nil | boolean

Spring.IsUnitIcon

 ( number unitID ) -> nil | boolean

Spring.IsUnitInView

 ( number unitID ) -> nil | boolean

Spring.IsUnitVisible

 ( number unitID [, number radius [, boolean checkIcons] ] ) -> nil | boolean

Screen Trace

Spring.WorldToScreenCoords

 ( number x, number y, number z ) -> number x, number y, number z

Spring.TraceScreenRay

 ( number mouseX, number mouseY [, boolean onlyCoords 
 [, boolean useMinimap [, boolean includeSky [, boolean ignoreWater [, number D] ] ] ] ] )
   -> nil |
   string "unit",    number unitID    |
   string "feature", number featureID |
   string "ground",  { [1] = number x, [2] = number y, [3] = number z }

New in version 101.0 Exended to allow a custom plane, parameters are (0, 1, 0, D=0) where D is the offset D can be specified in the third argument (if all the bools are false) or in the seventh (as shown). Intersection coordinates are returned in t[4],t[5],t[6] when the ray goes offmap and includeSky is true), or when no unit or feature is hit (or onlyCoords is true).

to get map coordinates under mouse cursor: input mouse coordinates obtained via GetMouseState() and pass true for the onlyCoords parameter. Be careful as going off map will result in nil:

  local mouseX, mouseY = Spring.GetMouseState()
  print ("Mouse coordinates: (" .. mouseX .. ", " .. mouseY .. ")")
  local desc, args = Spring.TraceScreenRay(mouseX, mouseY, true)
  if nil == desc then return end -- off map
  local x = args[1]
  local y = args[2]
  local z = args[3]
  print ("World coordinates: (" .. x .. ", " .. y .. ", " .. z .. ")")


Spring.GetPixelDir New in version 95.0

 ( number x, number y ) -> number dirx, number diry, number dirz

Screen & Window Geometry

Spring.GetViewGeometry

 ( ) -> number viewSizeX, number viewSizeY, number viewPosX, number viewPosY

Spring.GetWindowGeometry

 ( ) -> number winSizeX, number winSizeY, number winPosX, number winPosY

Spring.GetScreenGeometry (is missing multiscreen support!)

 ( ) -> number screenSizeX, number screenSizeY, number ZERO, number ZERO


Unit

Spring.IsUnitAllied

 ( number unitID ) -> nil | boolean

Spring.GetUnitViewPosition

 ( number unitID [, boolean midPos = false ] ) -> nil | number x, number y, number z

Spring.GetUnitTransformMatrix

 ( number unitID [, boolean invert = false] ) -> nil | number a11, number a12 ..., number a44    (4x4 matrix)

Spring.GetUnitSelectionVolumeData

 ( number unitID )
 -> number scaleX, number scaleY, number scaleZ,
 number offsetX, number offsetY, number offsetZ,
 number volumeType, number testType, number primaryAxis, boolean disabled

Selected Units

Spring.GetSelectedUnits

 ( ) -> { [1] = unitID, ... }

Spring.GetSelectedUnitsSorted

 ( ) -> { [number unitDefID] = { [1] = [number unitID], etc...}, ... }

Spring.GetSelectedUnitsCounts

 ( ) -> { [number unitDefID] = number count, etc... }

Spring.GetSelectedUnitsCount

 ( ) -> number count

Spring.IsUnitSelected

 ( number unitID ) -> nil | boolean

Unit Groups

Spring.GetUnitGroup

 ( number unitID ) -> nil | number

Spring.GetGroupList

 ( ) -> nil | {
   [number] = number unitCount,
   ...
 }

Spring.GetSelectedGroup

 ( ) -> number

Spring.GetGroupAIName

 ( number groupID ) -> string aiName

Spring.GetGroupAIList

 ( ) -> {
   [1] = string aiName, ...
 }

Spring.GetGroupUnits

 ( number groupID ) -> nil | {
   [1] = number unitID, ...
 }

Spring.GetGroupUnitsSorted

 ( number groupID ) -> nil | {
   [number unitDefID] = {number unitID, ...}, ...
 }

Spring.GetGroupUnitsCounts

 ( number groupID ) -> nil | {
   [number unitDefID] = number count, ...
 }

Spring.GetGroupUnitsCount

 ( number groupID ) -> nil | number count

Feature

Spring.GetFeatureSelectionVolumeData

 ( number unitID )
 -> number scaleX, number scaleY, number scaleZ,
 number offsetX, number offsetY, number offsetZ,
 number volumeType, number testType, number primaryAxis, boolean disabled

Projectiles

Spring.GetVisibleProjectiles New in version 95.0

  ([ number allyTeamID = -1
  [ , boolean addSyncedProjectiles = true
  [ , boolean addWeaponProjectiles = true
  [ , boolean addPieceProjectiles = true ]]]]
  ) --> nil | {[1] = projectileID, ...}


UI

Spring.GetUICommands New in version 101.0

 ( ) -> nil | {
   [1] = {
     command=string,
     description=string,
     synced=bool,
     cheat=bool,
   }, ...
 }

Returns a list of available UI commands.

GUI Settings

Spring.IsGUIHidden

 ( ) -> nil | boolean

Spring.HaveShadows

 ( ) -> nil | boolean

Spring.HaveAdvShading

 ( ) -> nil | boolean

Spring.GetWaterMode

 ( ) -> nil | number mode, string "mode"
   mode numbers:
     0 - basic
     1 - reflective
     2 - dynamic
     3 - refractive
     4 - bumpwater
     default - unknown

Spring.GetMapDrawMode

 ( ) -> nil | "normal" | "height" | "metal" | "pathTraversability" | "los"

Spring.GetDrawSelectionInfo Returns whether "Selected units" text is displayed.

 ( ) -> boolean

Unit & Feature GUI States

Spring.GetUnitLuaDraw

 ( number unitID ) -> nil | boolean

Spring.GetUnitNoDraw

 ( number unitID ) -> nil | boolean

Spring.GetUnitNoMinimap

 ( number unitID ) -> nil | boolean

Spring.GetUnitNoSelect

 ( number unitID ) -> nil | boolean

Spring.GetFeatureLuaDraw

 ( number featureID ) -> nil | boolean

Spring.GetFeatureNoDraw

 ( number featureID ) -> nil | boolean

Minimap

Spring.GetMiniMapGeometry

 ( ) -> number posX, number posY, number sizeX, number sizeY,
   boolean minimized, boolean maximized

Spring.GetMiniMapDualScreen

 ( ) -> boolean false | string "left" | string "right"

Spring.IsAboveMiniMap

 ( number x, number y ) -> nil | boolean


(Build-)Menu

Spring.GetActiveCommand

 ( ) -> nil | number index (, number cmd_id, number cmd_type, string cmd_name)

Spring.GetDefaultCommand

 ( ) -> nil | number index (, number cmd_id, number cmd_type, string cmd_name)

Spring.GetActiveCmdDescs

 ( ) -> nil | {
   [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, .. }
   }, ...
 }

Spring.GetActiveCmdDesc

 ( number index ) -> nil | {
     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, .. }
 }

Spring.GetCmdDescIndex

 ( number cmdID ) -> nil | number index

Spring.GetActivePage

 ( ) -> nil | number pageNum, number maxPages

Build Facing

Spring.GetBuildFacing

 ( ) -> nil | number

Spring.GetBuildSpacing

 ( ) -> nil | number

GatherMode & InvertQueueKey

Spring.GetGatherMode

 ( ) -> nil | number

Spring.GetInvertQueueKey

 ( ) -> nil | boolean

Mouse States

Spring.GetMouseState

 ( ) -> number X, number Y,
   boolean leftPressed, boolean middlePressed, boolean rightPressed,
   boolean offscreen

X, Y are the screen coordinates, not world ones. This coordinate system starts in the lower left corner.

New in version 104.0 Sixth return value offscreen

For world coordinates see Spring.TraceScreenRay

Spring.GetMouseCursor

 ( ) -> string name, number scale

Spring.GetMouseStartPosition

 ( number mouseButton ) -> nil | number pressedX, number pressedY,
   number camPosX, number camPosY, number camPosZ,
   number dirX, number dirY, number dirZ

(Hot-)Keys

Spring.GetKeyState

 ( number key ) -> nil | boolean

Spring.GetModKeyState

 ( ) -> boolean alt, boolean ctrl, boolean meta, boolean shift

Spring.GetPressedKeys

 ( ) -> {
   [number code] = boolean,
   [string name] = boolean, New in version 99.0
   ...
 }

Spring.GetKeyCode

 ( string keysym ) -> number

Spring.GetKeySymbol

 ( number key ) -> string "keysym1", string "keysym2"

Spring.GetKeyBindings

 ( string keyset ) -> nil | {
   [1] = {
     [string actionCmd] = string actionExtra,
     command   = string actionCmd,    New in version 97
     boundWith = string boundWith,    New in version 97
     extra     = string actionExtra,  New in version 97
   }, ...
 }

Spring.GetActionHotKeys

 ( string action ) -> nil | { [1] = string hotKey, ... }

Console

Spring.GetLastMessagePositions

 ( ) -> nil | {
   [1] = { number X, number Y, number Z },
   ...
 }

Spring.GetConsoleBuffer

 ( [number maxLines] ) -> nil | {
   [1] = {
     text = string,
     priority = number
  }, ...
 }

Spring.GetCurrentTooltip

 ( ) -> string

LOS Colors

Spring.GetLosViewColors

 ( ) -> always = {r,g,b}, LOS = {r,g,b}, radar = {r,g,b}, jam = {r,g,b}, radar2 = {r,g,b}  New in version 100

Config

Spring.GetConfigParams same information as spring --list-config-vars

 ( ) -> table {
   {
     name = string,
     type = string,
     [ description = string, ]
     [ defaultValue = string, ]
     [ minimumValue = string, ]
     [ maximumValue = string, ]
     [ safemodeValue = string, ]
     [ declarationFile = string, ]
     [ declarationLine = number, ]
     [ readOnly = bool, ]
   },
   ...
 }

Spring.GetConfigInt

 ( string name [, number default ] ) -> nil | number

Spring.GetConfigFloat New in version 104.0

 ( string name [, number default ] ) -> nil | number

Spring.GetConfigString

 ( string name [, string default ] ) -> nil | string

FPS & GetDrawFrame

Spring.GetFPS

 ( ) -> number

Spring.GetDrawFrame

 ( ) -> number low 16bit, number high 16bit

Spring.GetVideoCapturingMode New in version 104.0

 ( ) -> boolean videoCaptureAllowed

Time

Spring.GetGameSpeed New in version 98.0

 ( ) -> number userSpeedFactor, number speedFactor, boolean paused

Spring.GetFrameTimeOffset

 ( ) -> nil | number

Spring.GetLastUpdateSeconds

 ( ) -> nil | number

Spring.GetHasLag

 ( ) -> boolean

Spring.GetTimer

 ( ) -> timer

Spring.GetFrameTimer New in version 102.0

 ( ) -> timer

Get a timer for the start of the frame, this should give better results for camera interpolations.

Spring.DiffTimers

 ( timer cur, timer ago, [boolean inMilliseconds]) -> number seconds

New in version 95.0 optional third argument (boolean) to return dt in milliseconds

Rendering

Spring.GetMapSquareTexture

 (number texSqrX, number texSqrY, number texMipLvl, string luaTexName) -> boolean success

Logging

Spring.GetLogSections

 ( ) -> table { "KeyBindings" = LOG.INFO, "Font" = LOG.INFO, "Sound" = LOG.WARNING, ... }

Misc

Spring.GetClipboard New in version 98.0

 ( ) -> string text