Skip to content

Light Client

Light is a powerful module to create and manage dynamic light sources with smooth transitions in your RedM script. It allows for easily creating, moving, and fading lights with full control over color, intensity, and range.

Tips for using lights :

  • Performance: Lights are relatively expensive to render. Keep the number of active lights to a minimum.
  • Range: Smaller light ranges (5-15 units) often look better and are more efficient.
  • Transitions: The ease parameter allows for smooth transitions when changing properties, creating more natural-looking effects.
  • Colors: Different colors create different moods - warm colors (orange, yellow) for fires, cool colors (blue, cyan) for magical effects, etc.

JO Functions

jo.light.create()

Creates a new light with the given properties

Syntax

lua
jo.light.create(coords, intensity, rgb, range, ease)

Parameters

coords : vector3

The position where the light will be created

intensity : float Optional

The light intensity from 0.0 to 1.0 - default:1.0

rgb : table Optional

RGB color values as a table {r,g,b} - default:{255, 160, 122}

range : float Optional

The range/radius of the light - default:10.0

ease : float Optional

Transition time in milliseconds - default:1000

Return Value

Type : LightClass

The created light object

Example

lua
-- Create a red light at coordinates (100, 200, 30)
local myLight = jo.light.create(
    vec3(100.0, 200.0, 30.0), -- position
    0.8,                      -- intensity
    { 255, 0, 0 },            -- RGB (red)
    10.0,                     -- range
    500                       -- ease time (ms)
)

LightClass Methods

LightClass:delete()

Marks a light for deletion and starts fading it out

Syntax

lua
LightClass:delete()

Example

lua
-- Create a light
local myLight = jo.light.create(vec3(100.0, 200.0, 30.0))

-- Later, remove the light with a fade-out effect
myLight:delete()

LightClass:setCoords()

Sets new target coordinates for the light

Syntax

lua
LightClass:setCoords(coords)

Parameters

coords : vector3

The new target position

Example

lua
local myLight = jo.light.create(vec3(100.0, 200.0, 30.0))

-- Move the light to a new position with smooth transition
myLight:setCoords(vec3(110.0, 210.0, 35.0))

LightClass:setIntensity()

Sets new target intensity for the light

Syntax

lua
LightClass:setIntensity(intensity)

Parameters

intensity : float

The new target intensity from 0.0 to 1.0

Example

lua
local myLight = jo.light.create(vec3(100.0, 200.0, 30.0))

-- Dim the light to half brightness
myLight:setIntensity(0.5)

LightClass:update()

Updates the light properties based on elapsed time

Syntax

lua
LightClass:update(deltaTime)

Parameters

deltaTime : float

Time elapsed since last update in ms

Example

lua
-- Note: This method is generally used internally
-- but can be called manually if needed
local myLight = jo.light.create(vec3(100.0, 200.0, 30.0))
myLight:update(16) -- Update with 16ms delta time

Last updated: