> For the complete documentation index, see [llms.txt](https://solaartw.gitbook.io/developer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://solaartw.gitbook.io/developer/documentation/utilities/cyberpunk-engine-tweaks/guides/scripts.md).

# 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](https://wiki.redmodding.org/cyber-engine-tweaks/introduction) on how to create a proper mod.

### Getting started <a href="#getting-started" id="getting-started"></a>

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:dofile("plugins/cyber\_engine\_tweaks/scripts/myfile.lua") -- DEPRECATED

### Functions <a href="#functions" id="functions"></a>

There are 2 function types and 2 handle types.

#### Global functions <a href="#global-functions" id="global-functions"></a>

They do not need a handle and are all located in the `Game` object. Sample:Game.PrintHealth()-- orGame.AddToInventory("Items.money", 500)[Global](https://wiki.redmodding.org/cyber-engine-tweaks/functions/global)

#### Handle functions <a href="#handle-functions" id="handle-functions"></a>

They require a handle (more on that later). Assuming you have a `player` handle:print(player:IsNaked())print(player:IsMoving())player:OnDied()[Player](https://wiki.redmodding.org/cyber-engine-tweaks/functions/player)

### Handles <a href="#handles" id="handles"></a>

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 <a href="#singleton" id="singleton"></a>

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:gameTime = GetSingleton("gameTimeSystem")print(gameTime:GetGameTime())gameTime:SetGameTimeByHMS(12,0,0) -- 12h0m0s

#### Regular handles <a href="#regular-handles" id="regular-handles"></a>

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:player = Game.GetPlayer()if player:IsNaked() thenplayer:OnDied() -- kill the player if it's nakedendplayer = Game.GetPlayer()ts = Game.GetTransactionSystem()​tid = TweakDBID.new("Items.money")itemid = ItemID.new(tid)​result = ts:GiveItem(player, itemid, 100000)if result thenprint("We added " .. tostring(itemid) .. " to the inventory!")elseprint("Failed to add " .. tostring(itemid))end

### Helpers <a href="#helpers" id="helpers"></a>

If you need to dump the content of a type, you can use the [Dump](https://wiki.redmodding.org/cyber-engine-tweaks/functions/misc#dump) function like the following:player = Game.GetPlayer()dmp = Dump(player, false)print(dmp)You can also call [DumpType](https://wiki.redmodding.org/cyber-engine-tweaks/functions/misc#dumptype) for a static type you want to know about but don't have an instance of:type = DumpType("gameItemID", false)print(type)​dump\_player.txt9KBTextResult of Dump
