Key notes on upgrading existing mod for the CET 1.14+:
Don't use Game
object and any game types before onInit
.
Don't use GetMod()
before onInit
.
Don't pass excessive params to game functions. If the max number of params is 3, then passing 4 params will result in an error.
Update Observe()
/ Override()
handlers so they accept self
as the first param. Previously, some observers lacked the self
param:
If your mod stores player reference then unset it when game session ends.
An unreleased reference can lead to bugs such as disappearing footsteps.
Accessing Game.GetPlayer()
in onUpdate
will not cause the issue.
This can be achieved using next snippet or with GameSession
/ GameUI
libs:
Use corresponding getters for game systems instead of GetSingleton()
. For example, Game.GetTeleportationFacility()
instead of GetSingleton('gameTeleportationFacility')
.
New scripting capabilities were introduced in CET 1.14 to make it more convenient and simple:
All game classes are directly accessible by name. For example, entEntityId
, PlayerPuppet
.
All game enums are directly accessible by name. For example, gamedataStatType.BaseDamage
, gameGameVersion.Current
.
Classes can also be accessed by their aliases from redscript. For example, WeaponObject
instead of gameweaponObject
.
Classes have the conventional .new()
constructor. For example, MappinData.new()
.
A constructor can take an array of properties to create and initialize an object in a single statement. For example, EntityID.new({ hash = 12345 })
.
Static methods are accessible from classes using the dot. For example, ScriptedPuppet.IsDefeated(npc)
.
A static method can be called from an instance if the first parameter is of the same type. For example, vec4:Length()
instead of Vector4.Length(vec4)
.
The overloaded function is resolved based on passed parameters when called by its short name. For example, StatusEffectHelper.HasStatusEffect(target, gamedataStatusEffectType.Overheat)
.
Partial Variant
type support. ToVariant()
and FromVariant()
are only applicable to classes.
All new scripting features are optional. You're not required to rewrite an existing mod using these features.
The new API allows code that is also valid redscript or very close to its redscript counterpart. Thus, it simplifies the research and the transition to / from the redscript.
For example, this line looks exactly the same in Lua and in the redscript:
Constructing objects
Old API:
New API:
Constructor with initialization
Old API:
New API:
Scripted static call
Old API:
New API:
Shorthand static call
Old API:
New API:
Working with enums
Old API:
New API:
Variants