createLight | Multi Theft Auto: Wiki Skip to content

createLight

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function creates a 3D light in the world.

Note

The direction of the light only has any effect if the light type is spot light . One light will only apply illumination effects to peds , players , wheels and number plates (like a emergency vehicle siren light does). Two or more lights will apply illumination effects to everything (excluding objects) that is in range of, at least, two of them.

Syntax

createLight ( )

Code Examples

client

This example will make every player to look completely black without using shaders. It will also dark vehicles he uses too.

local lightRadius = 2 * getElementRadius(localPlayer) -- Every standard player model has the same radius, so save it for quicker access
local lights = { [localPlayer] = createLight(2, 0, 0, 0, lightRadius) } -- Initialize our light table with the one that the local player will use for the effect
local function addPlayerDarkLight()
-- Create a new dark light for that player
lights[source] = createLight(2, 0, 0, 0, lightRadius)
end
addEventHandler("onClientPlayerJoin", root, addPlayerDarkLight)
local function removePlayerDarkLight()
-- Destroy the light of that player and remove references
destroyElement(lights[source])
lights[source] = nil
end
addEventHandler("onClientPlayerQuit", root, removePlayerDarkLight)
-- Make the dark light assigned to each player to move with his center, so we achieve the desired effect
local function updateLightPositions()
for player, light in pairs(lights) do
if isElementStreamedIn(player) then
setElementPosition(light, getPedBonePosition(player, 2))
end
end
end
addEventHandler("onClientPreRender", root, updateLightPositions)