SetElementLighting: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Update note)
Line 19: Line 19:


==Example==
==Example==
{{Needs Example}}
<syntaxhighlight lang="lua">addEventHandler("onClientPedsProcessed",root,function()
    for _, v in pairs(getElementsByType('player')) do -- All players lighting set to 10
        setElementLighting(v, 10)
    end
    for _, v in pairs(getElementsByType('vehicle')) do -- All vehicles lighting set to 10
        setElementLighting(v, 10)
    end
end)</syntaxhighlight>
 
<syntaxhighlight lang="lua">addEventHandler("onClientPedsProcessed",root,function()
    setElementLighting(localPlayer, 10) -- Set the lighting value of our player to 10
end)</syntaxhighlight>


==See Also==
==See Also==
{{Client element functions}}
{{Client element functions}}

Revision as of 09:22, 6 January 2025

ADDED/UPDATED IN VERSION 1.6.0 r22862:
This function changes the lighting value for the specified element. This can be a player, ped, vehicle, object, weapon.
[[{{{image}}}|link=|]] Note: Lighting is calculated in real-time every frame. Therefore, to correctly override the lighting, you should use this function in combination with the onClientPedsProcessed event, not only for peds, but also for vehicles and objects.

Syntax

bool setElementLighting ( element theElement, float lighting )

OOP Syntax Help! I don't understand this!

Method: element:setLighting(...)
Variable: .lighting
Counterpart: getElementLighting


Required Arguments

  • theElement: The element whose lighting you want to change.
  • lighting: The lighting value that you want to set.

Returns

Returns true if the function was successful, false otherwise. This function can fail if called right after element creation.

Example

addEventHandler("onClientPedsProcessed",root,function()
    for _, v in pairs(getElementsByType('player')) do -- All players lighting set to 10
        setElementLighting(v, 10)
    end
    for _, v in pairs(getElementsByType('vehicle')) do -- All vehicles lighting set to 10
        setElementLighting(v, 10)
    end
end)
addEventHandler("onClientPedsProcessed",root,function()
    setElementLighting(localPlayer, 10) -- Set the lighting value of our player to 10
end)

See Also