Skip to content

Injection & Execution

Run code in contexts other than the injected console — the FiveM isolated runtime, another resource's environment, or a resource's NUI.

All of these take code as a string

code is Lua (or, for InjectJS, JavaScript) passed as a string, usually via a [[ long bracket ]]. It runs in the target context, so your outer script's locals are not available inside it.


Asterion.Isolated

Runs code inside the FiveM isolated Lua runtime — the same environment as your own resource. Use it when natives must run in a real Citizen thread rather than the injected context.

Asterion.Isolated(code)
Argument Type Description
code string Lua source to run in the isolated runtime.

Example

Asterion.Isolated([[
    Citizen.CreateThread(function()
        TeleportToWaypoint()
    end)
]])

Asterion.InjectResource

Injects Lua code into the running resource name through its scripting environment. The code shares the resource's global table, so it can read and write existing globals and call the resource's functions.

Asterion.InjectResource(name, code)
Argument Type Description
name string The target resource name.
code string Lua source to run inside it.

Example

Asterion.InjectResource("my-hud", [[
    SendNUIMessage({ type = "hide" })
]])

Asterion.InjectResource2

Like InjectResource, but a safer, stealthier variant.

Asterion.InjectResource2(name, code)
Argument Type Description
name string The target resource name.
code string Lua source to run inside the resource.

Example

Asterion.InjectResource2("vrp", [[
    vRP.closeMenu()
]])

Asterion.InjectThread

Injects code as a new Citizen thread inside resource, attributed to file (used for stack traces / identification).

Asterion.InjectThread(resource, file, code)
Argument Type Description
resource string The target resource name.
file string A filename the thread is attributed to (e.g. "client.lua").
code string Lua source to run as the new thread.

Example

Asterion.InjectThread("esx_status", "client.lua", [[
    ESX.SetPlayerData("money", 999999)
]])

Asterion.HijackResource

Replaces the next execution tick of resource with code. Runs with the resource's full environment and permissions.

Asterion.HijackResource(resource, code)
Argument Type Description
resource string The target resource name.
code string Lua source to run in place of the next tick.

Example

Asterion.HijackResource("es_extended", [[
    print(ESX.GetPlayerData().job.name)
]])

One-shot

HijackResource only affects the next tick. For something that must run continuously, use InjectThread or wrap it in an Asterion.Thread.


Asterion.InjectJS

Executes JavaScript code in the NUI context of resource.

Asterion.InjectJS(resource, code)
Argument Type Description
resource string The resource whose NUI frame to target.
code string JavaScript source to run in the NUI.

Example

Asterion.InjectJS("my-hud", [[
    document.getElementById('health').style.display = 'none';
]])