Scripts
Explain how to load custom lua file
The use of dofile() is being deprecated in versions v.1.9 and later of Cyber Engine Tweaks. Please see the Modding Introduction page on how to create a proper mod.

Getting started

You can write commands directly in the console but for more complex scripts, you may use files.
The console will look for files where Cyberpunk2077.exe is located, ideally you will put your files in a folder dedicated to that, for example official Cyber Engine Tweaks files are located in plugins/cyber_engine_tweaks/scripts, here we will assume you put your custom .lua file in this scripts folder.
You can execute your file by typing in console:
1
dofile("plugins/cyber_engine_tweaks/scripts/myfile.lua") -- DEPRECATED
Copied!

Functions

There are 2 function types and 2 handle types.

Global functions

They do not need a handle and are all located in the Game object. Sample:
1
Game.PrintHealth()
2
-- or
3
Game.AddToInventory("Items.money", 500)
Copied!

Handle functions

They require a handle (more on that later). Assuming you have a player handle:
1
print(player:IsNaked())
2
print(player:IsMoving())
3
player:OnDied()
Copied!

Handles

Handles are a way to pass an object to the function. For example IsNaked makes no sense without telling the engine for which object we want to know this information.

Singleton

These handles are static, there is only one in the game, for example the gameTimeSystem is a singleton so there is no need to tell the script engine which one you want. That being said you need a singleton handle so it knows you want to call a function on that system.
Sample:
1
gameTime = GetSingleton("gameTimeSystem")
2
print(gameTime:GetGameTime())
3
gameTime:SetGameTimeByHMS(12,0,0) -- 12h0m0s
Copied!

Regular handles

These handles are not unique, for example, the game contains multiple NPCs so there are as many handles as NPCs. Currently as far as I know we can only get the handle of the player by calling the global function Game.GetPlayer().
Sample:
1
player = Game.GetPlayer()
2
if player:IsNaked() then
3
player:OnDied() -- kill the player if it's naked
4
end
Copied!
1
player = Game.GetPlayer()
2
ts = Game.GetTransactionSystem()
3
4
tid = TweakDBID.new("Items.money")
5
itemid = ItemID.new(tid)
6
7
result = ts:GiveItem(player, itemid, 100000)
8
if result then
9
print("We added " .. tostring(itemid) .. " to the inventory!")
10
else
11
print("Failed to add " .. tostring(itemid))
12
end
Copied!

Helpers

If you need to dump the content of a type, you can use the Dump function like the following:
1
player = Game.GetPlayer()
2
dmp = Dump(player, false)
3
print(dmp)
Copied!
You can also call DumpType for a static type you want to know about but don't have an instance of:
1
type = DumpType("gameItemID", false)
2
print(type)
Copied!
dump_player.txt
9KB
Text
Result of Dump
Last modified 1yr ago