Lua System: Difference between revisions

From Spring
Jump to navigationJump to search
Jk (talk | contribs)
Applied LuaConstant template to constant numbers.
 
(21 intermediate revisions by 4 users not shown)
Line 2: Line 2:


=All Lua Contexts=
=All Lua Contexts=
'''Script.Kill'''
{{LuaCallout
  ( ) -> nil
|prefix = Script.
|name = Kill
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


'''Script.GetName'''
  ( ) -> string luaInstanceName <span class=note>(e.g. "LuaUI", "LuaRules", "LuaGaia", ...)</span>


'''Script.GetSynced'''
{{LuaCallout
  ( ) -> boolean is_synced
|prefix = Script.
|name = GetName
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|string}} luaInstanceName
|info = Returns the luaInstanceName (e.g. "LuaUI", "LuaRules", "LuaGaia", ...).
}}


'''Script.GetFullCtrl'''
  ( ) -> boolean has_fullctrl


'''Script.GetFullRead'''
{{LuaCallout
  ( ) -> boolean has_fullread
|prefix = Script.
|name = GetSynced
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|bool}} is_synced
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


'''Script.GetCtrlTeam'''
  ( ) -> number ctrl_teamID


'''Script.GetReadTeam'''
{{LuaCallout
  ( ) -> number read_teamID
|prefix = Script.
|name = GetFullCtrl
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|bool}} has_fullctrl
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


'''Script.GetReadAllyTeam'''
  ( ) -> number read_allyTeamID


'''Script.GetSelectTeam'''
{{LuaCallout
  ( ) -> number select_teamID <span class=note>(defines which teamunits can be selected via Spring.SelectUnitMap/Spring.SelectUnitArray)</span>
|prefix = Script.
|name = GetFullRead
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|bool}} has_fullread
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


'''Script.GetGlobal'''
  ( ) -> nil | <span class=warning>table globalEnv (returns nil if not in dev-mode)</span>


'''Script.GetRegistry'''
{{LuaCallout
  ( ) -> nil | <span class=warning>table registryEnv (returns nil if not in dev-mode)</span>
|prefix = Script.
|name = GetCtrlTeam
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|number}} ctrl_teamID
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


'''Script.GetCallInList'''
 
  ( ) -> table <span class=note>known_callins</span>
{{LuaCallout
|prefix = Script.
|name = GetReadTeam
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|number}} read_teamID
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix = Script.
|name = GetReadAllyTeam
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|number}} read_allyTeamID
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix = Script.
|name = GetSelectTeam
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|number}} select_teamID
|info = Defines which teamunits can be selected via Spring.SelectUnitMap/Spring.SelectUnitArray.
}}
 
 
{{LuaCallout
|prefix = Script.
|name = GetGlobal
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|table}} globalEnv
|info = Returns nil if not in dev-mode.
}}
 
 
{{LuaCallout
|prefix = Script.
|name = GetRegistry
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|table}} registryEnv
|info = Returns nil if not in dev-mode.
}}
 
 
{{LuaCallout
|prefix = Script.
|name = GetCallInList
|arg1 =
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|table}} known_callins
|info = Known CallIns are:
}}
   <span class=note>known_callins = {
   <span class=note>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)
     ["CallInName"] = { unsynced = boolean, controller = boolean }, (`controller` is true for<br>      all CallIns which's return values are used by the engine for synced code,<br>      e.g. "AllowUnitCreation" is a controller)
     ...
     ...
   }
   }
</span>


==special team constants==
number '''Script.NO_ACCESS_TEAM'''


number '''Script.ALL_ACCESS_TEAM'''
{{LuaCallout
|prefix = Script.
|name = IsEngineMinVersion
|arg1 = major {{bracket}}, minor {{bracket}}, commits {{rbracket}}{{rbracket}}
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|boolean}} isMinVersion
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


==Special team constants==


{{LuaConstant
|type = number
|name = NO_ACCESS_TEAM
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
{{LuaConstant
|type = number
|name = ALL_ACCESS_TEAM
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


=LuaUI only=
=LuaUI only=
'''Spring.SetShockFrontFactors'''
  ( [number minArea], [number minPower], [number distAdj] ) -> nil


'''Script.UpdateCallIn'''
{{LuaCallout
  ( string callin_name ) -> nil
|prefix = Spring.
|name = SetShockFrontFactors
|arg1 = {{type|number}} minArea
|arg2 = {{type|number}} minPower
|arg3 = {{type|number}} distAdj
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}




{{LuaCallout
|prefix = Spring.
|name = UpdateCallIn
|arg1 = {{type|string}} callin_name
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


=LuaGadgets only=
=LuaGadgets only=
==Synced==
==Synced==
number '''COBSCALE'''


'''Script.AddActionFallback'''
{{LuaConstant
  ( string command, string help ) -> nil | boolean
|type = number
|name = COBSCALE
|info =Number containing the cobscale factor, which is applied to transform the variables assigned via unit cob animation scripts for use inside the engine (default: 65536).
}}
 
 
{{LuaCallout
|prefix = Script.
|name = AddActionFallback
|arg1 = {{type|string}} command
|arg2 = {{type|string}} help
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|boolean}} ???
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix = Script.
|name = RemoveActionFallback
|arg1 = {{type|string}} command
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|boolean}} ???
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix = Script.
|name = UpdateCallIn
|arg1 = {{type|string}} callin_name
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix = Script.
|name = SetWatchFeature
|arg1 = {{type|number}} featureDefID
|arg2 = {{type|boolean}} enable
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = Enables the `UnitFeatureCollision` callin for a specific [[Gamedev:FeatureDefs|FeatureDef]].
}}
 
 
{{LuaCallout
|prefix = Script.
|name = GetWatchFeature
|arg1 = {{type|number}} featureDefID
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|boolean}} enabled
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix = Script.
|name = SetWatchUnit
|arg1 = {{type|number}} unitDefID
|arg2 = {{type|boolean}} enable
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = Enables the `UnitUnitCollision`, `UnitFeatureCollision` and `UnitMoveFailed` callins for a specific [[Gamedev:UnitDefs|UnitDef]].
}}


'''Script.RemoveActionFallback'''
  ( string command ) -> nil | boolean


'''Script.UpdateCallIn'''
{{LuaCallout
  ( string callin_name ) -> nil
|prefix = Script.
|name = GetWatchUnit
|arg1 = {{type|number}} unitDefID
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|boolean}} enabled
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}


'''Script.SetWatchWeapon''' <span class=note>Enables the `Explosion` callin for a specific WeaponDef.</span>
  ( number weaponDefID, boolean enable ) -> nil


'''Script.GetWatchWeapon'''
{{LuaCallout
  ( number weaponDefID ) -> nil | boolean enabled
|prefix = Script.
|name = SetWatchWeapon
|arg1 = {{type|number}} weaponDefID
|arg2 = {{type|boolean}} enable
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = Enables the `Explosion` and (as of 0.83+) `ProjectileCreated` and `ProjectileDestroyed` callins for a specific WeaponDef.
}}


'''SendToUnsynced'''
  ( arg1, arg2, ... ) -> nil
  <span class=warning>Just nil, number, string and boolean datatypes are allowed as arguments! NO tables, userdatas, ...</span>


'''CallAsTeam''' <span class=note>LOS checking depends on the `selected` team, this functions allows to select another one</span>
{{LuaCallout
  ( number teamID, lua_function f, arg1, arg2, ... ) -> nil
|prefix = Script.
  ( table <span class=note>access</span>, lua_function f, arg1, arg2, ... ) -> nil
|name = GetWatchWeapon
|arg1 = {{type|number}} weaponDefID
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|boolean}} enabled
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix = Script.
|name = GetWatchWeapon
|arg1 = {{type|number}} weaponDefID
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}} {{pipe}} {{type|boolean}} enabled
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix =
|name = SendToUnsynced
|arg1 = arg1
|arg2 = arg2
|arg3 = ...
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = Just nil, number, string and boolean datatypes are allowed as arguments! NO tables, userdatas, ...
}}
 
 
{{LuaCallout
|prefix =
|name = CallAsTeam
|arg1 = {{type|number}} teamID
|arg2 = lua_function f
|arg3 = arg1
|arg4 = arg2
|arg5 = ...
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info =
}}
or <br>
{{LuaCallout
|prefix =
|name = CallAsTeam
|arg1 = {{type|table}} access
|arg2 = lua_function f
|arg3 = arg1
|arg4 = arg2
|arg5 = ...
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = LOS checking depends on the `selected` team, this functions allows to select another one.
}}
   <span class=note>access = {
   <span class=note>access = {
     [ctrl = number teamID,]
     [ctrl = number teamID,]
Line 92: Line 511:


==Unsynced==
==Unsynced==
'''Script.UpdateCallIn'''
  ( string callin_name ) -> nil


'''CallAsTeam''' <span class=note>LOS checking depends on the `selected` team, this functions allows to select another one</span>
{{LuaCallout
  ( number teamID, lua_function f, arg1, arg2, ... ) -> nil
|prefix = Script.
  ( table <span class=note>access</span>, lua_function f, arg1, arg2, ... ) -> nil
|name = UpdateCallIn
|arg1 = {{type|string}} callin_name
|arg2 =
|arg3 =
|arg4 =
|arg5 =
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 
 
{{LuaCallout
|prefix =
|name = CallAsTeam
|arg1 = {{type|number}} teamID
|arg2 = lua_function f
|arg3 = arg1
|arg4 = arg2
|arg5 = ...
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info =
}}
or <br>
{{LuaCallout
|prefix =
|name = CallAsTeam
|arg1 = {{type|table}} access
|arg2 = lua_function f
|arg3 = arg1
|arg4 = arg2
|arg5 = ...
|arg6 =
|arg7 =
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = LOS checking depends on the `selected` team, this functions allows to select another one.
}}
 
   <span class=note>access = {
   <span class=note>access = {
     [ctrl = number teamID,]
     [ctrl = number teamID,]   (limits Spring.GiveOrderXYZ)
     [read = number teamID,]
     [read = number teamID,]   (limits reading of unit params, e.g. Spring.GetUnitLosState)
     [select = number teamID,]
     [select = number teamID,]   (limits Spring.SelectUnitXYZ)
   }</span>
   }</span>


=LuaRules only=
=LuaRules only=
==Synced==
==Synced==
'''Script.PermitHelperAIs'''
  ( boolean permit ) -> nil


'''Spring.SetUnitRulesParam'''
{{LuaCallout
  ( number unitID, string paramName, number paramValue, table <span class=note>losAccess</span> ) -> nil
|prefix = Script.
  <span class=note>possible values for the losAccess table are:
|name = PermitHelperAIs
    `private` : only readable by the ally (default)
|arg1 = {{type|boolean}} permit
    `allied`  : readable by ally + ingame allied
|arg2 =  
    `inlos`  : readable if the unit is in LOS
|arg3 =  
    `inradar` : readable if the unit is in AirLOS
|arg4 =
    `public`  : readable by all
|arg5 =
  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`)
|arg6 =
  note2: all GameRulesParam are public, TeamRulesParams can just be `private`,`allied` and/or `public`
|arg7 =
  </span>
|arg8 =
|arg9 =
|return = {{type|nil}}
|info = <font color="maroon" style="font-weight:600">No description available</font>
}}
 


'''Spring.SetTeamRulesParam'''
[[category: Lua]]
  ( number teamID, string paramName, number paramValue, table <span class=note>losAccess</span> ) -> nil
  <span class=note>see above further documentation of losAccess</span>


'''Spring.SetGameRulesParam'''
[[category: Lua]]
  ( string paramName, number paramValue, table <span class=note>losAccess</span> ) -> nil
  <span class=note>see above further documentation of losAccess</span>

Latest revision as of 22:17, 28 February 2021

Development < Lua Scripting < Lua System

All Lua Contexts

Script.Kill ( )
return: nil

No description available


Script.GetName ( )
return: string luaInstanceName

Returns the luaInstanceName (e.g. "LuaUI", "LuaRules", "LuaGaia", ...).


Script.GetSynced ( )
return: bool is_synced

No description available


Script.GetFullCtrl ( )
return: bool has_fullctrl

No description available


Script.GetFullRead ( )
return: bool has_fullread

No description available


Script.GetCtrlTeam ( )
return: number ctrl_teamID

No description available


Script.GetReadTeam ( )
return: number read_teamID

No description available


Script.GetReadAllyTeam ( )
return: number read_allyTeamID

No description available


Script.GetSelectTeam ( )
return: number select_teamID

Defines which teamunits can be selected via Spring.SelectUnitMap/Spring.SelectUnitArray.


Script.GetGlobal ( )
return: nil | table globalEnv

Returns nil if not in dev-mode.


Script.GetRegistry ( )
return: nil | table registryEnv

Returns nil if not in dev-mode.


Script.GetCallInList ( )
return: table known_callins

Known CallIns are:
 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 ]] )
return: nil | boolean isMinVersion

No description available

Special team constants

number NO_ACCESS_TEAM

No description available


number ALL_ACCESS_TEAM

No description available

LuaUI only

Spring.SetShockFrontFactors ( number minArea, number minPower, number distAdj )
return: nil

No description available


Spring.UpdateCallIn ( string callin_name )
return: nil

No description available

LuaGadgets only

Synced

number COBSCALE

Number containing the cobscale factor, which is applied to transform the variables assigned via unit cob animation scripts for use inside the engine (default: 65536).


Script.AddActionFallback ( string command, string help )
return: nil | boolean ???

No description available


Script.RemoveActionFallback ( string command )
return: nil | boolean ???

No description available


Script.UpdateCallIn ( string callin_name )
return: nil

No description available


Script.SetWatchFeature ( number featureDefID, boolean enable )
return: nil

Enables the `UnitFeatureCollision` callin for a specific FeatureDef.


Script.GetWatchFeature ( number featureDefID )
return: nil | boolean enabled

No description available


Script.SetWatchUnit ( number unitDefID, boolean enable )
return: nil

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


Script.GetWatchUnit ( number unitDefID )
return: nil | boolean enabled

No description available


Script.SetWatchWeapon ( number weaponDefID, boolean enable )
return: nil

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


Script.GetWatchWeapon ( number weaponDefID )
return: nil | boolean enabled

No description available


Script.GetWatchWeapon ( number weaponDefID )
return: nil | boolean enabled

No description available


SendToUnsynced ( arg1, arg2, ... )
return: nil

Just nil, number, string and boolean datatypes are allowed as arguments! NO tables, userdatas, ...


CallAsTeam ( number teamID, lua_function f, arg1, arg2, ... )
return: nil

or
CallAsTeam ( table access, lua_function f, arg1, arg2, ... )
return: nil

LOS checking depends on the `selected` team, this functions allows to select another one.
 access = {
   [ctrl = number teamID,]
   [read = number teamID,]
   [select = number teamID,]
 }

Unsynced

Script.UpdateCallIn ( string callin_name )
return: nil

No description available


CallAsTeam ( number teamID, lua_function f, arg1, arg2, ... )
return: nil

or
CallAsTeam ( table access, lua_function f, arg1, arg2, ... )
return: nil

LOS checking depends on the `selected` team, this functions allows to select another one.
 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 )
return: nil

No description available