CreateLight: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ {{Client function}} {{Needs_Example}} {{New feature/item|9.07048|1.4.0|7048|This function creates a 3D light to the world.}} {{Note|The direction of the light aff...") |
m (Remove createShadow from syntax) |
||
(22 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client function}} | {{Client function}} | ||
{{New feature/item| | {{New feature/item|3.0150|1.5.0|7048|This function creates a 3D [[Element/Light|light]] in the world.}} | ||
{{Note| | |||
{{Note|The direction of the light | * The direction of the light only has any effect if the light type is ''spot light''. | ||
* One light will only apply illumination effects to [[Element/Ped|peds]], [[Element/Player|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== | ==Syntax== | ||
<syntaxhighlight lang="lua">light createLight ( int lightType, float posX, float posY, float | <syntaxhighlight lang="lua">light createLight ( int lightType, float posX, float posY, float posZ [, float radius = 3, int r = 255, int g = 0, int b = 0, float dirX = 0, float dirY = 0, float dirZ = 0 ] )</syntaxhighlight> | ||
{{OOP||[[Light]]}} | {{OOP||[[Light]]}} | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''lightType:''' An integer representing the type of light to create. | *'''lightType:''' An integer representing the type of light to create. | ||
*''' | {{Light_types}} | ||
*''' | *'''posX:''' A floating point number representing the X coordinate on the map. | ||
*''' | *'''posY:''' A floating point number representing the Y coordinate on the map. | ||
*'''posZ:''' A floating point number representing the Z coordinate on the map. | |||
===Optional Arguments=== | ===Optional Arguments=== | ||
Line 25: | Line 28: | ||
*'''dirY:''' A floating point number representing the light direction's Y coordinate on the map. | *'''dirY:''' A floating point number representing the light direction's Y coordinate on the map. | ||
*'''dirZ:''' A floating point number representing the light direction's Z coordinate on the map. | *'''dirZ:''' A floating point number representing the light direction's Z coordinate on the map. | ||
=== Returns === | === Returns === | ||
Line 31: | Line 33: | ||
== Example == | == Example == | ||
This example will make every player to look completely black without using shaders. It will also dark vehicles he uses too. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | local lightRadius = 2 * getElementRadius(localPlayer) -- Every standard player model has the same radius, so save it for quicker access | ||
</syntaxhighlight> | 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)</syntaxhighlight> | |||
==Changelog== | ==Changelog== | ||
{{ChangelogHeader}} | {{ChangelogHeader}} | ||
{{ChangelogItem|1. | {{ChangelogItem|1.5.0-3.0152|Addendum to r7048 (Applied source patch #8737 (PointLight Creation) by Lex128.)}} | ||
== See Also == | == See Also == | ||
{{ | {{Client_light_functions}} |
Latest revision as of 16:53, 18 July 2024
This function creates a 3D light in the world.
Syntax
light createLight ( int lightType, float posX, float posY, float posZ [, float radius = 3, int r = 255, int g = 0, int b = 0, float dirX = 0, float dirY = 0, float dirZ = 0 ] )
OOP Syntax Help! I don't understand this!
- Method: Light(...)
Required Arguments
- lightType: An integer representing the type of light to create.
- 0: Point light, which illuminates surroundings evenly across the light radius.
- 1: Spot light, which illuminates the direction of the light defined by dirX, dirY and dirZ.
- 2: Dark light, which darkens its surrounding elements to full black.
- posX: A floating point number representing the X coordinate on the map.
- posY: A floating point number representing the Y coordinate on the map.
- posZ: A floating point number representing the Z coordinate on the map.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- radius: A floating point number representing the radius of the light.
- r: An integer number representing the amount of red to use in the colouring of the light (0 - 255).
- g: An integer number representing the amount of green to use in the colouring of the light (0 - 255).
- b: An integer number representing the amount of blue to use in the colouring of the light (0 - 255).
- dirX: A floating point number representing the light direction's X coordinate on the map.
- dirY: A floating point number representing the light direction's Y coordinate on the map.
- dirZ: A floating point number representing the light direction's Z coordinate on the map.
Returns
Returns the light element if creation was successful, false otherwise.
Example
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)
Changelog
Version | Description |
---|
1.5.0-3.0152 | Addendum to r7048 (Applied source patch #8737 (PointLight Creation) by Lex128.) |