Skip to content

Threads

Run Lua code repeatedly in the background without blocking the console.


Asterion.Thread

Starts a repeating background thread.

local id = Asterion.Thread(code, interval)

Parameters

Argument Type Default Description
code string Lua source executed on every tick.
interval integer 500 Milliseconds between executions.

Returns

Type Description
integer A thread id you pass to StopThread.

Example

local tid = Asterion.Thread([[
    local ped = PlayerPedId()
    SetEntityHealth(ped, 200)
]], 1000)

code is an isolated string

The body runs on its own — locals declared outside the [[ ]] block are not visible inside it. Keep everything the thread needs inside the string, and save the returned id in your outer script so you can stop it later.


Asterion.StopThread

Stops the thread with the given id.

Asterion.StopThread(id)

Parameters

Argument Type Default Description
id integer nil The id returned by Thread. Pass nil or omit to stop all threads.

Example

-- stop one specific thread
Asterion.StopThread(tid)

-- stop every running thread
Asterion.StopThread()

Panic button

A bare Asterion.StopThread() is the fastest way to kill every loop you have started — handy while you are experimenting.