-
Notifications
You must be signed in to change notification settings - Fork 6
Script Extensions
TweakXL extends TweakDBInterface
with additional functions for accessing records and flats.
class TweakDBInterface {
static func GetFlat(path: TweakDBID) -> Variant
static func GetRecord(path: TweakDBID) -> ref<TweakDBRecord>
static func GetRecords(type: CName) -> array<ref<TweakDBRecord>>
static func GetRecordCount(type: CName) -> Uint32
static func GetRecordByIndex(type: CName, index: Uint32) -> ref<TweakDBRecord>
static func GetRecords(keys: array<TweakDBID>) -> array<ref<TweakDBRecord>>
static func GetRecordIDs(type: CName) -> array<TweakDBID>
}
For example, you can enumerate all records of some type:
for record in TweakDBInterface.GetRecords(n"Achievement_Record") {
Log(ToString((record as Achievement_Record).EnumName()));
}
With generic getter you can check if flat exists and get the type name:
let flat = TweakDBInterface.GetFlat(t"PreventionSystem.setup.totalEntitiesLimit");
Log(ToString(IsDefined(flat)));
Log(ToString(VariantTypeName(flat)));
The TweakDBManager
provides functions to modify TweakDB data.
class TweakDBManager {
static func SetFlat(path: TweakDBID, value: Variant) -> Bool
static func CreateRecord(path: TweakDBID, type: CName) -> Bool
static func CloneRecord(path: TweakDBID, base: TweakDBID) -> Bool
static func UpdateRecord(path: TweakDBID) -> Bool
}
After changing record properties with SetFlat()
, you must call UpdateRecord()
to propagate the changes to existing record instances.
Scriptable tweaks allow you to modify TweakDB at a very early stage, right after TweakDB initialization.
abstract class ScriptableTweak {
protected cb func OnApply() -> Void
}
Similar to scriptable systems, you must define your own class derived from ScriptableTweak
.
When TweakDB is initialized, the loader instantiates all of the scriptable tweaks and calls OnApply
callbacks.
Example #1:
public class EnableMoreSpawns extends ScriptableTweak {
protected cb func OnApply() -> Void {
TweakDBManager.SetFlat(t"PreventionSystem.setup.totalEntitiesLimit", 40);
}
}
Example #2:
public class ThisIsEpic extends ScriptableTweak {
protected cb func OnApply() -> Void {
for record in TweakDBInterface.GetRecords(n"Clothing") {
this.MakeEpic(record);
}
for record in TweakDBInterface.GetRecords(n"WeaponItem") {
this.MakeEpic(record);
}
}
protected func MakeEpic(record: ref<TweakDBRecord>) -> Void {
TweakDBManager.SetFlat(record.GetID() + t".quality", t"Quality.Epic");
TweakDBManager.UpdateRecord(record.GetID());
}
}
Scriptable tweak lifecycle
TweakDB initialization happens at such early stage thatGameInstance
is not ready yet. This makes all game systems unavailable duringOnApply
callback.
To allow CET TweakDB Editor to show your flats and records with human-readable names,
TweakDBManager
provides alternative functions taking CName
instead TweakDBID
as the first argument.
class TweakDBManager {
static func SetFlat(name: CName, value: Variant) -> Bool
static func CreateRecord(name: CName, type: CName) -> Bool
static func CloneRecord(name: CName, base: TweakDBID) -> Bool
}
When the CName
version is used, the name will be registered and CET will recognize it.
When the TweakDBID
version is used, newly created flats and records can only be seen as hashes.