GetSearchLightColor

From Multi Theft Auto: Wiki
Revision as of 09:53, 16 September 2026 by Arran Fortuna (talk | contribs) (Created page with "__NOTOC__ {{Client function}} This function gets the color of a searchlight element. ==Syntax== <syntaxhighlight lang="lua"> int int int int getSearchLightColor ( searchlight theSearchLight ) </syntaxhighlight> ===Required Arguments=== *'''theSearchLight''': the searchlight to get the color of. ===Returns=== Returns four integers representing the red, green, blue and alpha components of the searchlight's color, each ranging from 0 to 255. Inval...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function gets the color of a searchlight element.

Syntax

int int int int getSearchLightColor ( searchlight theSearchLight )

Required Arguments

  • theSearchLight: the searchlight to get the color of.

Returns

Returns four integers representing the red, green, blue and alpha components of the searchlight's color, each ranging from 0 to 255. Invalid arguments raise an error.

The default color is red 200, green 200, blue 255 and alpha 0.

[[{{{image}}}|link=|]] Note: The alpha component is stored and returned, but does not affect the searchlight's appearance.

Example

This example creates a searchlight above the player and displays its default color.

addCommandHandler("getlightcolor", function()
    local x, y, z = getElementPosition(localPlayer)
    local searchLight = createSearchLight(x, y, z + 10, x, y, z, 0, 5)

    if not searchLight then
        return
    end

    local r, g, b, a = getSearchLightColor(searchLight)
    outputChatBox(("Searchlight color: R=%d, G=%d, B=%d, A=%d"):format(r, g, b, a))

    -- Remove the demonstration light after 10 seconds.
    setTimer(destroyElement, 10000, 1, searchLight)
end)

See also