Lua SyncedCtrl

From Spring
Jump to: navigation, search

Development < Lua Scripting < Lua SyncedCtrl

Game End

Spring.KillTeam New in version 83.0

 ( number teamID ) -> nil

Will declare a team to be dead ( no further orders can be assigned to such teams's units ), Gaia team cannot be killed.

Spring.GameOver New in version 83.0

 ( {number allyTeamID1, number allyTeamID2, ...} ) -> nil

Will declare game over, a list of winning allyteams can be passed, if undecided ( like when dropped from the host ) it should be empty ( no winner ), in the case of a draw with multiple winners, all should be listed

RulesParams

string values are new since 95.0. Attention: Numeric paramValues in quotes will be converted to number.

Spring.SetUnitRulesParam

 ( number unitID, string paramName, number|string paramValue [, table losAccess] ) -> nil
  possible keys for the losAccess table are:
   `private` : only readable by the ally (default)
   `allied`  : readable by ally + ingame allied
   `inlos`   : readable if the unit is in LOS
   `inradar` : readable if the unit is in AirLOS
   `public`  : readable by all
  note: if one condition is fulfilled all beneath it are too (e.g. if an unit is in LOS it
can read params with `inradar=true` even if the param has `inlos=false`) note2: all GameRulesParam are public, TeamRulesParams can just be `private`,`allied`
and/or `public` note3: You can read RulesParams from any Lua enviroments! With those losAccess
policies you can limit their access.

Spring.SetFeatureRulesParam new since 102.0

 ( number featureID, string paramName, number|string paramValue [, table losAccess] ) -> nil
  see above for further documentation of losAccess

Spring.SetTeamRulesParam

 ( number teamID, string paramName, number|string paramValue [, table losAccess] ) -> nil
  see above for further documentation of losAccess

Spring.SetGameRulesParam

 ( string paramName, number|string paramValue [, table losAccess] ) -> nil
  see above for further documentation of losAccess

Resources

Spring.AddTeamResource

 ( number teamID, string "metal" | "energy", number amount ) -> nil

Spring.UseTeamResource

 ( number teamID, 
   string "metal" | "energy",number amount |
   { metal = number amount, energy = number amount}
 ) -> nil | boolean hadEnough

Spring.SetTeamResource

 ( number teamID, string res, number amount ) -> nil

 possible values for res are:
   "m"  = metal
   "e"  = energy
   "ms"  = metal storage
   "es"  = energy storage

Spring.SetTeamShareLevel

 ( number teamID, string "metal" | "energy", number amount ) -> nil

Spring.ShareTeamResource 0.82 and later

 ( number teamID_src, number teamID_recv, string "metal" | "energy", number amount ) -> nil

Teams

Spring.SetAlly New in version 98.0

 ( number firstAllyTeamID, number secondAllyTeamID, boolean ally ) -> nil

Changes the value of the (one-sided) alliance between: firstAllyTeamID -> secondAllyTeamID

Spring.AssignPlayerToTeam New in version 98.0 7ed9a7e3

 ( number playerID, number teamID)

Spring.SetGlobalLos New in version 101.0

 ( number allyTeamID, bool globallos )

Unit Handling

Spring.CreateUnit note: offmap positions are clamped! (you still can use MoveCtrl todo so)

 ( string "defName" | number unitDefID,
   number x, number y, number z,
   (number facing | string "facing"),
   number teamID
   [, boolean build = false] 
   [, boolean flattenGround = true]
   [, number unitID]
   [, number builderID]) -> number unitID | nil (meaning unit was not created)

 possible values for facing are:
   "south" | "s" | 0
   "east"  | "e" | 1
   "north" | "n" | 2
   "west"  | "w" | 3
 if build is true the unit is created in "being built" state, with buildProgress = 0
 unitID and builderID are New in version 92.0, the former allowing to spawn a unit with
 a specific ID.

Spring.DestroyUnit

 ( number unitID
   [, boolean selfd = false]
   [, boolean reclaimed = false]
   [, number attackerID ] ) -> nil

selfd := makes the unit act like it self-destructed
reclaimed := don't show any DeathSequences, don't leave a wreckage.
  NOTE this does _not_ give back the resources to the team!

Spring.TransferUnit

 ( number unitID,
   numer newTeamID
   [, boolean given = true ] ) -> nil

if given=false, the unit is captured


Unit Control

Spring.SetUnitCosts

 ( number unitID, { 
    [ buildTime  = number amount ],
    [ metalCost  = number amount ],
    [ energyCost = number amount ]
  } ) -> nil

Spring.SetUnitTooltip

 ( number unitID, string "tooltip" ) -> nil

Spring.SetUnitHealth

 ( number unitID,
   number health |
   { [ health   = number health ],
     [ capture  = number capture ],
     [ paralyze = number paralyze ],
     [ build    = number build ] }
 ) -> nil

Spring.SetUnitMaxHealth

 ( number unitID, number maxHealth ) -> nil

Spring.AddUnitDamage

 ( number unitID, number damage
   [, number paralyze = 0 [, number attackerID = -1 [, number weaponID = -1
     [, number impulse_x [, number impulse_y [, number impulse_z ]]] ]]] ) -> nil

Spring.SetUnitStockpile

 ( number unitID [, number stockpile [, number buildPercent ]]) -> nil

Spring.SetUnitExperience

 ( number unitID, number experience ) -> nil

Spring.SetUnitFuel Removed from version 101.0

 ( number unitID, number fuel ) -> nil

Spring.SetUnitCrashing New in version 83.0

 ( number unitID, boolean crashing ) -> boolean success

Spring.SetUnitLineage Removed from version 83.0

 ( number unitID, number teamID [, boolean isRoot] ) -> nil

Spring.SetUnitNeutral

 ( number unitID, boolean neutral ) -> nil

Spring.SetUnitTarget userTarget & success new in version 95.0, setting nil target new in 99.0, weaponNum new in 102.0

 ( number unitID,
   number enemyUnitID | number x, number y, number z, | nil,
   [ boolean dgun = false [, boolean userTarget = false [, number weaponNum = -1 ]]] ) ->  success

Spring.SetUnitMaxRange

 ( number unitID, number maxRange ) -> nil

Spring.SetUnitMass New in version 101.0

 ( number unitID, number mass ) -> nil

Spring.SetUnitBlocking crushable new in version 85.0

 ( number unitID, boolean blocking [, boolean collide [, boolean crushable]] ) -> nil

Spring.SetUnitBlocking New in version 95.0 changed parameters:

 number unitID,
 boolean isBlocking,
 boolean isSolidObjectCollidable,
 boolean isProjectileCollidable,
 boolean isRaySegmentCollidable,
 boolean crushable,
 boolean blockEnemyPushing,
 boolean blockHeightChanges

Spring.SetUnitMetalExtraction    "depth" corresponds to metal extraction rate (value range similar to "extractsMetal" unitDef)

 ( number unitID, number depth [,number range] ) -> nil

Spring.SetUnitBuildSpeed

 ( number builderID,
   number buildSpeed, [ number repairSpeed [, number reclaimSpeed
 [,number resurrectSpeed [, number captureSpeed [, number terraformSpeed ]] ]]] ) -> nil

Spring.SetUnitNanoPieces New in version 92.0

 ( number builderID, table pieces ) -> nil

This saves a lot of engine calls, by replacing: function script.QueryNanoPiece() return currentpiece end Use it!

Spring.UnitAttach New in version 101.0

 ( number transporterID, number passengerID, number pieceNum ) -> nil

Spring.UnitDetach New in version 101.0

 ( number passengerID ) -> nil

Spring.UnitDetachFromAir New in version 101.0

 ( number passengerID ) -> nil

Spring.SetUnitLoadingTransport New in version 101.0

 ( number passengerID, number transportID ) -> nil

Disables collisions between the two units to allow colvol intersection during the approach.

Spring.SetUnitPieceParent New in version 101.0

 ( number unitID, number AlteredPiece, number ParentPiece ) -> nil

Changes the pieces hierarchy of a unit, by attaching a piece to a new parent.

Spring.SetUnitPieceMatrix New in version 104.0

 ( number unitID, number pieceNum, table matrix )

Sets the local (i.e. parent-relative) matrix of the given piece if any of the first three elements are non-zero, and also blocks all script animations from modifying it until {0, 0, 0} is passed (matrix should be an array of 16 floats, but is not otherwise sanity-checked).

Spring.SetUnitArmored armorMultiple new in version 0.83.x

 ( number unitID, boolean armored [, number armorMultiple] ) -> nil

Spring.SetUnitShieldState

 ( number unitID [, number weaponID = -1] [, boolean enabled] [, number power] ) -> nil

Spring.SetUnitFlanking

 ( number unitID, string "mode", number mode ) -> nil
 ( number unitID, string "moveFactor", number factor) -> nil
 ( number unitID, string "minDamage", number minDamage ) -> nil
 ( number unitID, string "mazDamage", number maxDamage ) -> nil
 ( number unitID, string "dir", number x, number y, number z) -> nil

Spring.SetUnitWeaponState

 ( number unitID, number weaponNum, table states ) -> nil
 ( number unitID, number weaponNum, string key, number value ) -> nil
 format of the states table:
   {
     ["reloadState"     = number value,]
     ["reloadFrame"     = number value,] (synonym for reloadState!)
     ["reloadTime"      = number value,]
     ["accuracy"        = number value,]
     ["sprayAngle"      = number value,]
     ["range"           = number value,] (*)
     ["projectileSpeed" = number value,]
     ["burst"           = number value,]
     ["burstRate"       = number value,]
     ["projectiles"     = number value,]
     ["salvoLeft"       = number value,]
     ["nextSalvo"       = number value,]
     ["aimReady"        = number value,] (<>0.0f := true)
   }
 (*) if you change the range of a weapon with dynamic damage
 make sure you use SetUnitWeaponDamages to change dynDamageRange as well.
 

Spring.SetUnitWeaponDamages New in version 101.0

 ( number unitID, number weaponNum | "selfDestruct" | "explode", table damages ) -> nil
 ( number unitID, number weaponNum | "selfDestruct" | "explode", string key, number value ) -> nil
 format of the damages table:
  {
     ["paralyzeDamageTime" = number value,]  
     ["impulseFactor"      = number value,]
     ["impulseBoost"       = number value,]
     ["craterMult"         = number value,]
     ["craterBoost"        = number value,]
     ["dynDamageExp"       = number value,]
     ["dynDamageMin"       = number value,]
     ["dynDamageRange"     = number value,]
     ["dynDamageInverted"  = number value,] (<>0.0f := true)
     ["craterAreaOfEffect" = number value,]
     ["damageAreaOfEffect" = number value,]
     ["edgeEffectiveness"  = number value,]
     ["explosionSpeed"     = number value,]
     [number armorType     = number value,] (changes the damage against this armor type)
   }
 

Spring.SetUnitCollisionVolumeData

 ( number unitID, number scaleX, number scaleY, number scaleZ,
   number offsetX, number offsetY, number offsetX,
   number vType, number tType, number Axis
 ) -> nil
 enum COLVOL_TYPES {
     COLVOL_TYPE_DISABLED = -1,
     COLVOL_TYPE_ELLIPSOID = 0,
     COLVOL_TYPE_CYLINDER,
     COLVOL_TYPE_BOX,
     COLVOL_TYPE_SPHERE,
     COLVOL_NUM_TYPES       // number of non-disabled collision volume types
   };
   enum COLVOL_TESTS {
     COLVOL_TEST_DISC = 0,
     COLVOL_TEST_CONT = 1,
     COLVOL_NUM_TESTS = 2   // number of tests
   };
   enum COLVOL_AXES {
     COLVOL_AXIS_X   = 0,
     COLVOL_AXIS_Y   = 1,
     COLVOL_AXIS_Z   = 2,
     COLVOL_NUM_AXES = 3    // number of collision volume axes
   };
 

Spring.SetUnitPieceCollisionVolumeData

 ( number unitID, number pieceIndex, boolean enable, 
   number scaleX, number scaleY, number scaleZ,
   number offsetX, number offsetY, number offsetZ
   [, number volumeType [, number primaryAxis]]
 ) -> nil

As of 101.0 this is 1-based piece index argument (was 0-based).

Spring.SetUnitTravel

 ( number unitID, number travel [, number travelPeriod] ) -> nil

Spring.SetUnitMoveGoal used by default commands to get in build-,attackrange etc.

 (number unitID, number goalx, number goaly, number goalz 
 [, number goalRadius [, number moveSpeed [, bool moveRaw ]]] )

New in version 98.0 moveRaw: allow unit to dumbly move to a coordinate without calculating path.

Spring.SetUnitLandGoal New in version 101.0

 (number unitID, number goalx, number goaly, number goalz [, number goalRadius ] ) -> nil

Used in conjunction with Spring.UnitAttach et al to re-implement old airbase & fuel system in lua.

Spring.ClearUnitGoal New in version 102.0

 (number unitID) -> nil

Spring.SetUnitPhysics drag new in version 95.0

 ( number unitID,
   number posx, number posy, number posz,
   number velx, number vely, number velz,
   number rotx, number roty, number rotz,
   number dragx, number dragy, number dragz,
 ) -> nil

Spring.SetUnitPosition

 ( number unitID, number x, number z [, boolean alwaysAboveSea] ) -> nil

Spring.SetUnitDirection New in version 90.0

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

Spring.SetUnitVelocity

 ( number unitID, number velx, number vely, number velz ) -> nil

Spring.SetUnitRotation

 ( number unitID, number rotx, number roty, number rotz ) -> nil

Spring.AddUnitImpulse

 ( number unitID, number x, number y, number z [, decayRate ] ) -> nil

Spring.AddUnitSeismicPing

 ( number unitID, number pingSize ) -> nil

Spring.RemoveBuildingDecal

 ( number unitID ) -> nil

Spring.SetUnitMidAndAimPos New in version 89.0

 ( number unitID, 
   number mpx, number mpy, number mpz, 
   number apx, number apy, number apz, 
   [, boolean relative] ) -> boolean success

mpx, mpy, mpz: new middle position of unit

apx, apy, apz: new position that enemies aim at on this unit

relative: are the new coordinates relative to world or unit coordinates?


Spring.SetUnitRadiusAndHeight New in version 89.0

 ( number unitID, number radius, number height ) -> boolean success

Spring.UnitWeaponFire

 ( number unitID, number weaponID ) -> nil

Spring.UnitWeaponHoldFire

 ( number unitID, number weaponID ) -> nil

Unit LOS

Spring.SetUnitCloak

 ( number unitID,
   boolean cloaked | number scriptCloak,
   [ number decloakDistance | boolean decloakAbs ] ) -> nil
 
 If the 2nd argument is a number, the value works like this:
  1:=normal cloak
  2:=for free cloak (cost no E)
  3:=for free + no decloaking (except the unit is stunned)
  4>=ultimative cloak (no ecost, no decloaking, no stunned decloak)
 The decloak distance is only changed if the 3th argument is a number or a boolean.
  If the boolean is false it takes the default decloak distance for that unitdef,
  if the boolean is true it takes the absolute value of it.

Spring.SetUnitSonarStealth

 ( number unitID, boolean sonarStealth ) -> nil

Spring.SetUnitStealth

 ( number unitID, boolean stealth ) -> nil

Spring.SetUnitAlwaysVisible

 ( number unitID, boolean alwaysVisible ) -> nil

Spring.SetUnitLosMask

 ( number unitID, number allyTeam, number los | table losTypes ) -> nil

the 3th argument is either the bit-and combination of the following numbers:

 LOS_INLOS     = 1
 LOS_INRADAR   = 2
 LOS_PREVLOS   = 4
 LOS_CONTRADAR = 8

or a table of the following form:

 losTypes = {
   [los = boolean,]
   [radar = boolean,]
   [prevLos = boolean,]
   [contRadar = boolean,]
 }

Spring.SetUnitLosState

 ( number unitID, number allyTeam, number los | table losTypes ) -> nil
 see above for more info on the arguments

Spring.SetUnitSensorRadius

 ( number unitID, string type, number radius ) -> nil | number newRadius
 type can be:
 "los","airLos","radar","sonar","seismic","radarJammer","sonarJammer"


Spring.SetRadarErrorParams New in version 95.0

 (number allyTeamID, number allyteamErrorSize 
 [, number baseErrorSize [, number baseErrorMult ]]) -> nil


Spring.SetUnitPosErrorParams New in version 95.0

 (number unitID, number posErrorVector.x, number posErrorVector.y, number posErrorVector.z,
 number posErrorDelta.x, number posErrorDelta.y, number posErrorDelta.z
 [ , number nextPosErrorUpdate]) --> nil

Unit Resourcing

Spring.SetUnitResourcing

 ( number unitID,
   string res, number amount |
   { res = number amount, ... }
 ) -> nil

 possible values for res are: "[u|c][u|m][m|e]"
      unconditional | conditional
                use | make
              metal | energy

Spring.AddUnitResource

 ( number unitID, string "m" | "e", number amount ) -> nil

Spring.UseUnitResource

 ( number unitID, string "m" | "e", number amount ) -> nil | boolean okay
 ( number unitID, { ["m" | "metal" | "e" | "energy"] = amount, ... } ) -> nil | boolean okay

Spring.SetUnitHarvestStorage New in version 97.0

 ( number unitid, number metal )

See also harvestStorage UnitDef tag.

Feature Handling

Spring.CreateFeature

 ( string "defName" | number featureDefID, 
   number x, number y, number z
   [, number heading 
   [, number AllyTeamID 
   [, number featureID ]]] ) -> number featureID

Spring.DestroyFeature

 ( number featureID ) -> nil

Spring.TransferFeature

 ( number featureID, number teamID ) -> nil


Feature Control

Spring.SetFeatureHealth

 ( number featureID, number health) -> nil

Spring.SetFeatureResources New in version 104.0

 ( number featureID, number metal, number energy [, number reclaimTime [, number reclaimLeft ]] )

Spring.SetFeatureReclaim

 ( number featureID, number reclaimLeft) -> nil

Spring.SetFeatureResurrect

 ( number featureID, number unitDefID | string unitDefName [, number facing | string "facing" [, number progress ]] ) -> nil

 possible values for facing are:
   "south" | "s" | 0
   "east"  | "e" | 1
   "north" | "n" | 2
   "west"  | "w" | 3

New in version 104.0 Second param can now be a number id instead of a string name, this also allows cancelling ressurection by passing -1. The level of progress can now be set via the additional 4th param.

Spring.SetFeaturePosition

 ( number featureID, number x, number y, number z [, boolean snapToGround]) -> nil

Spring.SetFeatureDirection

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

Spring.SetFeatureRotation New in version 101.0

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

Spring.SetFeatureVelocity New in version 95.0

Spring.SetFeaturePhysics New in version 95.0

(like their feature counterparts at Lua_SyncedCtrl#Unit_Control)

Spring.SetFeatureMoveCtrl

 ( number featureID [, boolean enable [, number* args]]) to control feature movement
  the number* arguments are parsed as follows and all optional
  if enable is true:
    [, velVector(x,y,z) -- initial velocity for feature
    [, accVector(x,y,z) -- acceleration added every frame
    ]]
  if enable is false:
    [, velocityMask(x,y,z) -- dimensions in which velocity is allowed to build when not using MoveCtrl
    [,  impulseMask(x,y,z) -- dimensions in which impulse is allowed to apply when not using MoveCtrl
    [, movementMask(x,y,z) -- dimensions in which feature is allowed to move when not using MoveCtrl
    ]]]

As of spring 103.0 it is necessary to unlock feature movement on x,z axis before changing feature physics. For example use "Spring.SetFeatureMoveCtrl(featureID,false,1,1,1,1,1,1,1,1,1)" to unlock all movement prior to making SetFeatureVelocity calls.

Spring.SetFeatureNoSelect

 ( number featureID, boolean noSelect ) -> nil

Spring.SetFeatureAlwaysVisible

 ( number featureID, boolean enable ) -> nil

Spring.SetFeatureCollisionVolumeData

 ( number featureID, number scaleX, number scaleY, number scaleZ,
   number offsetX, number offsetY, number offsetX,
   number vType, number tType, number Axis
 ) -> nil
 check Spring.SetUnitCollisionVolumeData for further explanation of the arguments

Spring.SetFeaturePieceCollisionVolumeData New in version 101.0

 ( number featureID, number pieceIndex, boolean enable, 
   number scaleX, number scaleY, number scaleZ,
   number offsetX, number offsetY, number offsetZ
   [, number volumeType [, number primaryAxis]]
 ) -> nil

Spring.SetFeatureMidAndAimPos New in version 89.0

 ( number unitID, 
   number mpx, number mpy, number mpz, 
   number apx, number apy, number apz, 
   [, boolean relative] ) -> boolean success
 check Spring.SetUnitMidAndAimPos for further explanation of the arguments


Spring.SetFeatureRadiusAndHeight New in version 89.0

 ( number unitID, number radius, number height ) -> boolean success

Spring.SetFeatureMass New in version 101.0

 ( number featureID, number mass ) -> nil

Spring.SetFeatureBlocking

 (number featureID, boolean blocking, boolean collidable) --> boolean

Spring.SetFeatureBlocking New in version 95.0 changed parameters:

 number featureID,
 boolean isBlocking,
 boolean isSolidObjectCollidable,
 boolean isProjectileCollidable,
 boolean isRaySegmentCollidable,
 boolean crushable,
 boolean blockEnemyPushing,
 boolean blockHeightChanges

Lua to COB

Spring.CallCOBScript

 ( number unitID, number funcID | string funcName, number retArgs, COBArg1, COBArg2, ... )
   -> nil | number returnValue, number retArg1, number retArg2, ...

Spring.CallCOBScriptCB
broken in 0.78.2.1; will be removed with the introduction of Lua as COB replacement

 ( number unitID, number funcID | string funcName, number retArgs, COBArg1, COBArg2, ... )
   -> nil | number returnValue, number CallbackData, number retArg1, number retArg2, ...

Spring.GetCOBScriptID

 ( number unitID, string funcName ) -> nil | number funcID


Note: Don't use Spring.[Get|Set]UnitCOBValue in LUS just because you are familar with it since bos/cob, use the mighty LuaSpringAPI instead!

Spring.GetUnitCOBValue

 ( number unitID [, boolean splitData=false], number COBValue
   [, number param1 [,number param2 [, number param3 [, number param4 ] ] ] ] )
 -> number result | number result1, number result2
 you find the possible values for `COBValue` in Lua_ConstCOB
  also see Custom_Variables

Spring.SetUnitCOBValue

 ( number unitID, number COBValue, number param1 [,number param2] ) -> nil
 you find the possible values for `COBValue` in Lua_ConstCOB
  also see Custom_Variables

Give Order

options can also be a bitmask; e.g. 0 instead of an empty table (can avoid performance hit on table creation)
see Lua CMDs for relevant constants

Spring.GiveOrderToUnit

 ( number unitID,
   number cmdID,
   params = {number, etc...},
   options = {"alt", "ctrl", "shift", "right"} ) -> nil

Spring.GiveOrderToUnitMap

 ( unitMap = { [unitID] = dontCare, etc... },
   number cmdID,
   params = {number, etc...},
   options = {"alt", "ctrl", "shift", "right"} ) -> nil

Spring.GiveOrderToUnitArray

 ( unitArray = { [1] = unitID, etc... },
   number cmdID,
   params = {number, etc...},
   options = {"alt", "ctrl", "shift", "right"} ) -> nil

Spring.GiveOrderArrayToUnitMap

 ( unitMap = { [number unitID] = dontCare, etc... },
   orderArray = {
     { number cmdID,
       {number, etc...},     params
       {"alt", "ctrl", "shift", "right"}   options
     }, ..
   }
 ) -> nil

Spring.GiveOrderArrayToUnitArray

 ( unitArray = { [1] = number unitID, etc... },
   orderArray = {
     { number cmdID,
       {number, etc...},    params
       {"alt", "ctrl", "shift", "right"}   options
     }, ..
   }
 ) -> nil

Ground

Grass

Spring.AddGrass

 ( number x, number z ) -> nil

Spring.RemoveGrass

 ( number x, number z ) -> nil

Heightmap

Note that x & z coords are in worldspace (Game.mapSizeX/Z), still the heightmap resolution is Game.squareSize.

Spring.LevelHeightMap

 ( number x1, number z1 [, number x2, number z2], number height ) -> nil

Spring.AdjustHeightMap (heightmap[x][z] += height;)

 ( number x1, number z1 [, number x2, number z2], number height ) -> nil

Spring.RevertHeightMap

 ( number x1, number z1 [, number x2, number z2], number origFactor ) -> nil



Spring.SetHeightMapFunc

 ( lua_function [, arg1 ,[ arg2 [, ... ] ] ) -> nil | number absTotalHeightMapAmountChanged
Example code:
Spring.SetHeightMapFunc(function()
	for z=0,Game.mapSizeZ, Game.squareSize do
		for x=0,Game.mapSizeX, Game.squareSize do
			Spring.SetHeightMap( x, z, 200 + 20 * math.cos((x + z) / 90) )
		end
	end
end)

Spring.AddHeightMap can only be called in SetHeightMapFunc()

 ( number x, number z, number height ) -> nil | number newHeight

Spring.SetHeightMap can only be called in SetHeightMapFunc()

 ( number x, number z, number height [,number terraform = 1] ) -> nil | number absHeightDiff

the terraform argument is a scaling factor: so if 0 nothing will be changed (the terraform starts) and if it is 1 the terraform will be finished.




Spring.LevelSmoothMesh

 ( number x1, number z1 [, number x2, number z2], number height ) -> nil

Spring.AdjustSmoothMesh

 ( number x1, number z1 [, number x2, number z2], number height ) -> nil

Spring.RevertSmoothMesh

 ( number x1, number z1 [, number x2, number z2], number origFactor ) -> nil

Spring.SetSmoothMeshFunc

 ( lua_function [, arg1 ,[ arg2 [, ... ] ] ) -> nil | number absTotalHeightMapAmountChanged

Spring.AddSmoothMesh can only be called in SetSmoothMeshFunc()

 ( number x, number z, number height ) -> nil | number newHeight

Spring.SetSmoothMesh can only be called in SetSmoothMeshFunc()

 ( number x, number z, number height [,number terraform = 1] ) -> nil | number absHeightDiff

TerrainTypes

Spring.SetMapSquareTerrainType

 ( number x, number z, int newType ) -> nil | int oldType

Spring.SetTerrainTypeData

 ( int typeIndex
 [, number speedTanks = nil ]
 [, number speedKBOTs = nil ]
 [, number speedHovers = nil ]
 [, number speedShips = nil ] ) -> nil | boolean true

Spring.SetSquareBuildingMask New in version 103.0

 ( number x, number z, int mask ) -> nil

See also buildingMask unitdef tag.

MetalAmount

Spring.SetMetalAmount New in version 83.0

 ( number x, number z, number metalAmount)

x & z coords are in worldspace/16
metalAmount must be between 0 and 255*maxMetal (with maxMetal from the .smd or mapinfo.lua)

Command Descriptions

Doesn't work in unsynced code!

Spring.EditUnitCmdDesc

 ( number unitID, number cmdDescID, table cmdArray ) -> nil

 structure of cmdArray:
 {
   [ id          = int ],
   [ type        = int ],
   [ name        = string ],
   [ action      = string ],
   [ tooltip     = string ],
   [ texture     = string ],
   [ cursor      = string ],
   [ queueing    = boolean ],
   [ hidden      = boolean ],
   [ disabled    = boolean ],
   [ showUnique  = boolean ],
   [ onlyTexture = boolean ],
   [ params      = { string = string, ... } ]
 }

queueing is New in version 101.0 and allows custom commands to be non-queueing (handy for state toggles).

Spring.InsertUnitCmdDesc

 ( number unitID [, number cmdDescID ] , table cmdArray ) -> nil

Spring.RemoveUnitCmdDesc

 ( number unitID [, number cmdDescID ] ) -> nil

Other

Spring.SetNoPause

 ( boolean noPause ) -> nil

Spring.SetUnitToFeature

 ( boolean tofeature ) -> nil

an ugly global switch that can be used to block units turning into features when they finish being built (like *A DT's do, which have the isFeature tag) thread

Spring.SetExperienceGrade

 ( number expGrade [, number ExpPowerScale [, number ExpHealthScale [, number ExpReloadScale ]]] ) -> nil
 expGrade defines how often UnitExperience() will be called,
 Prior to 104.0 it is based on the following equation:
    (int) [exp/(exp+1)] / expGrade
 Post 104.0 it is the raw change.

Spring.SpawnExplosion New in version 104.0

 ( number posX = 0, number posY = 0, number posZ = 0,
   number dirX = 0, number dirY = 0, number dirZ = 0,
   table explosionParams
 ) -> nil
 possible keys of explosionParams are:
   weaponDef = number,
   owner = number,
   hitUnit = number,
   hitFeature = number,
   craterAreaOfEffect = number,
   damageAreaOfEffect = number,
   edgeEffectiveness = number,
   explosionSpeed = number,
   gfxMod = number,
   impactOnly = boolean,
   ignoreOwner = boolean,
   damageGround = boolean,
 


Spring.SpawnCEG

 ( string "cegname" | number cegID,
   number posX = 0, number posY = 0, number posZ = 0,
   number dirX = 0, number dirY = 0, number dirZ = 0,
   number radius = 0, number damage = 0
 ) -> nil | boolean success, cegID

cegID new in 95.0

Spring.SpawnSFX New in version 104.0

 ( number unitID, number sfxID,
   number posX = 0, number posY = 0, number posZ = 0,
   number dirX = 0, number dirY = 0, number dirZ = 0,
   number radius = 0, number damage = 0
   [, boolean absolute ]
 ) -> nil | boolean success

Equal to the UnitScript versions of EmitSFX, but takes position and direction arguments (in either unit- or piece-space) instead of a piece index.

Projectiles

Spring.SpawnProjectile

 ( number weaponDefID, table projectileParams ) -> nil | number projectileID
 possible keys of projectileParams are:
   pos = {number x, number y, number z},
   end = {number x, number y, number z},
   speed = {number x, number y, number z},
   spread = {number x, number y, number z},
   error = {number x, number y, number z},
   owner = number,
   team = number,
   ttl = number,
   gravity = number,
   tracking = number,
   maxRange = number,
   startAlpha = number,
   endAlpha = number,
   model = string,
   cegTag = string,
 

Spring.DeleteProjectile New in version 101.0

 ( number projID ) -> nil

Silently removes projectiles (no explosion).

Spring.SetProjectileTarget

Pre 95.0: ( number projectileID,

   [ number targetID, string targetTypeStr ] | [ number posX, number posY, number posZ ] ) 
   -> nil | boolean validTarget

Post 95.0: ( number projectileID,

   [ number targetID [, number targetType]]  |  [number posX, number posY, number posZ]) 
   --> nil | boolean validTarget
 targetTypeStr can be one of: 
   'u' - unit
   'f' - feature
   'p' - projectile
 while targetTypeInt is one of:
   string.byte('g') := GROUND
   string.byte('u') := UNIT
   string.byte('f') := FEATURE
   string.byte('p') := PROJECTILE
 

Spring.SetProjectileIgnoreTrackingError New in version 101.0

 ( number projID, bool ignore ) -> nil

Spring.SetProjectileIsIntercepted New in version 99.0

 ( number projID ) -> nil

Spring.SetProjectileMoveControl (disables engine movecontrol, so lua can fully control the physics)

 ( number projID, boolean enable ) -> nil

Spring.SetProjectilePosition

 ( number projID [, number x = 0 [, number y = 0 [, number z = 0 ]]] ) -> nil

Spring.SetProjectileVelocity

 ( number projID [, number x = 0 [, number y = 0 [, number z = 0 ]]] ) -> nil

Spring.SetProjectileCollision

 ( number projID ) -> nil

Spring.SetProjectileGravity

 ( number projID [, number grav = 0] ) -> nil

Spring.SetProjectileSpinAngle New in version 95.0 Deprecated

 ( number projID [, number spinAngle = 0] ) -> nil

Spring.SetProjectileSpinSpeed New in version 95.0 Deprecated

 ( number projID [, number speed = 0] ) -> nil

Spring.SetProjectileSpinVec New in version 95.0 Deprecated

 ( number projID [, number x = 0 [, number y = 0 [, number z = 0]]] ) -> nil

Spring.SetProjectileCEG

 ( number projID, string ceg_name ) -> nil

Spring.SetPieceProjectileParams New in version 95.0

 (number projectileID,
 [ number explosionFlags, [ number spinAngle, [ number spinSpeed,
 [ number spinVector.x, [ number spinVector.y, [ number spinVector.z ]]]]]]) --> nil

Spring.SetProjectileAlwaysVisible New in version 95.0

   (number projectileID, boolean alwaysVisible) --> nil

Spring.SetProjectileDamages New in version 101.0

 ( number unitID, number weaponNum, table damages ) -> nil
 ( number unitID, number weaponNum, string key, number value ) -> nil
 format of the damages table:
  {
     ["paralyzeDamageTime" = number value,]  
     ["impulseFactor"      = number value,]
     ["impulseBoost"       = number value,]
     ["craterMult"         = number value,]
     ["craterBoost"        = number value,]
     ["dynDamageExp"       = number value,]
     ["dynDamageMin"       = number value,]
     ["dynDamageRange"     = number value,]
     ["dynDamageInverted"  = number value,] (<>0.0f := true)
     ["craterAreaOfEffect" = number value,]
     ["damageAreaOfEffect" = number value,]
     ["edgeEffectiveness"  = number value,]
     ["explosionSpeed"     = number value,]
     [number armorType     = number value,] (changes the damage against this armor type)
   }