Scheduler System

The scheduler provides utilities for managing repeating tasks and game loops with clean cleanup capabilities.

scheduler:setTick

Creates a repeating task that runs every game frame.

Parameters:

  • fn (function) - Function to execute each frame

Returns: SetTickCookie - A function to stop the tick

Type Definition:

---@alias SetTickCookie fun()

Usage:

local stopTick = scheduler:setTick(function()
    -- This runs every frame
    local playerPos = GetEntityCoords(PlayerPedId())
    DrawMarker(1, playerPos.x, playerPos.y, playerPos.z - 1.0, 0, 0, 0, 0, 0, 0, 2.0, 2.0, 1.0, 255, 0, 0, 100, false, true, 2, false, nil, nil, false)
end)

-- Stop the tick when no longer needed
stopTick()

scheduler:clearTick

Stops a previously created tick.

Parameters:

  • endTick (SetTickCookie) - The function returned by setTick

Usage:

Complete Scheduler Example

Best Practices

Scheduler Management

  • Always store tick references for cleanup

  • Clear ticks when no longer needed

  • Use resource stop handlers for automatic cleanup

Last updated