Lua System

From Spring

Development < Lua Scripting < Lua System

All Lua Contexts

Script.Kill

 ( ) -> nil

Script.GetName

 ( ) -> string luaInstanceName (e.g. "LuaUI", "LuaRules", "LuaGaia", ...)

Script.GetSynced

 ( ) -> boolean is_synced

Script.GetFullCtrl

 ( ) -> boolean has_fullctrl

Script.GetFullRead

 ( ) -> boolean has_fullread

Script.GetCtrlTeam

 ( ) -> number ctrl_teamID

Script.GetReadTeam

 ( ) -> number read_teamID

Script.GetReadAllyTeam

 ( ) -> number read_allyTeamID

Script.GetSelectTeam

 ( ) -> number select_teamID (defines which teamunits can be selected via 
Spring.SelectUnitMap/Spring.SelectUnitArray)

Script.GetGlobal

 ( ) -> nil | table globalEnv (returns nil if not in dev-mode)

Script.GetRegistry

 ( ) -> nil | table registryEnv (returns nil if not in dev-mode)

Script.GetCallInList

 ( ) -> table known_callins
 known_callins = {
   ["CallInName"] = { unsynced = boolean, controller = boolean }, (`controller` is true for
all CallIns which's return values are used by the engine for synced code,
e.g. "AllowUnitCreation" is a controller) ... }

Script.IsEngineMinVersion

 ( major [, minor [, commits ]] ) -> nil | boolean isMinVersion

special team constants

number Script.NO_ACCESS_TEAM

number Script.ALL_ACCESS_TEAM

LuaUI only

Spring.SetShockFrontFactors

 ( [number minArea], [number minPower], [number distAdj] ) -> nil

Script.UpdateCallIn

 ( string callin_name ) -> nil


LuaGadgets only

Synced

number COBSCALE

Script.AddActionFallback

 ( string command, string help ) -> nil | boolean

Script.RemoveActionFallback

 ( string command ) -> nil | boolean

Script.UpdateCallIn

 ( string callin_name ) -> nil

Script.SetWatchFeature Enables the `UnitFeatureCollision` callin for a specific FeatureDef.

 ( number featureDefID, boolean enable ) -> nil

Script.GetWatchFeature

 ( number featureDefID ) -> nil | boolean enabled

Script.SetWatchUnit Enables the `UnitUnitCollision`, `UnitFeatureCollision` and `UnitMoveFailed` callins for a specific UnitDef.

 ( number unitDefID, boolean enable ) -> nil

Script.GetWatchUnit

 ( number unitDefID ) -> nil | boolean enabled

Script.SetWatchWeapon Enables the `Explosion` and (as of 0.83+) `ProjectileCreated` and `ProjectileDestroyed` callins for a specific WeaponDef.

 ( number weaponDefID, boolean enable ) -> nil

Script.GetWatchWeapon

 ( number weaponDefID ) -> nil | boolean enabled

SendToUnsynced

 ( arg1, arg2, ... ) -> nil
 Just nil, number, string and boolean datatypes are allowed as arguments!
NO tables, userdatas, ...

CallAsTeam LOS checking depends on the `selected` team, this functions allows to select another one

 ( number teamID, lua_function f, arg1, arg2, ... ) -> nil
 ( table access, lua_function f, arg1, arg2, ... ) -> nil
 access = {
   [ctrl = number teamID,]
   [read = number teamID,]
   [select = number teamID,]
 }

Unsynced

Script.UpdateCallIn

 ( string callin_name ) -> nil

CallAsTeam LOS checking depends on the `selected` team, this functions allows to select another one

 ( number teamID, lua_function f, arg1, arg2, ... ) -> nil
 ( table access, lua_function f, arg1, arg2, ... ) -> nil
 access = {
   [ctrl = number teamID,]    (limits Spring.GiveOrderXYZ)
   [read = number teamID,]    (limits reading of unit params, e.g. Spring.GetUnitLosState)
   [select = number teamID,]    (limits Spring.SelectUnitXYZ)
 }

LuaRules only

Synced

Script.PermitHelperAIs

 ( boolean permit ) -> nil