GetSearchLightEndPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Has example)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}
{{Client function}}
{{Needs_Example}}
This function gets the end position of a [[Element/Searchlight|searchlight]] element.
 
{{New feature/item|3.0160|1.6|7683|This function gets the end position of a [[Element/Searchlight|searchlight]] element.}}


==Syntax==  
==Syntax==  
Line 19: Line 17:
==Example==
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- TODO
local helmetLantern
 
local function updateHelmetLantern()
    local helmetPos, playerMatrix = Vector3(getPedBonePosition(localPlayer, 6)), getElementMatrix(localPlayer)
    local targetPos = Vector3(playerMatrix[4][1] + playerMatrix[2][1] * 3, playerMatrix[4][2] + playerMatrix[2][2] * 3, playerMatrix[4][3] + playerMatrix[2][3] * 3)
    -- If the searchlight we use for the effect doesn't exist, create it
    -- If it is already created, then simply update its start and end positions
    if not helmetLantern then
        helmetLantern = createSearchLight(helmetPos, targetPos, 0, 15)
local a , b = getSearchLightEndPosition(helmetLantern)
outputChatBox(a .." "..b)
    else
        setSearchLightStartPosition(helmetLantern, helmetPos)
        setSearchLightEndPosition(helmetLantern, targetPos)
    end
end
 
local function manageHelmetLantern()
    local helmetLanternOff = not helmetLantern
    playSoundFrontEnd(helmetLanternOff and 37 or 38)
    if helmetLanternOff then
        -- Let updateHelmetLantern take care of creating and updating the effect
        addEventHandler("onClientPreRender", root, updateHelmetLantern)
    else
        -- Stop updateHelmetLantern doing its job and clear variables
        removeEventHandler("onClientPreRender", root, updateHelmetLantern)
        destroyElement(helmetLantern)
        helmetLantern = nil
    end
end
 
-- Allow the player to turn the helmet lantern or on off by using /togglelantern or pressing O
addCommandHandler("togglelantern", manageHelmetLantern)
bindKey("o", "down", manageHelmetLantern)
</syntaxhighlight>
</syntaxhighlight>


==See also==
==See also==
{{Client_searchlight_functions}}
{{Client_searchlight_functions}}

Latest revision as of 17:08, 2 January 2022

This function gets the end position of a searchlight element.

Syntax

float float float getSearchLightEndPosition ( searchlight theSearchLight )

OOP Syntax Help! I don't understand this!

Method: searchLight:getEndPosition(...)
Variable: .endPosition
Counterpart: setSearchLightEndPosition


Required Arguments

  • theSearchLight: the searchlight to get the position where the searchlight's light cone ends.

Returns

If the specified searchlight element is valid, this function will return three float, which are the three coordinates of searchlight's end position. If not, it will return false plus an error message.

Example

local helmetLantern

local function updateHelmetLantern()
    local helmetPos, playerMatrix = Vector3(getPedBonePosition(localPlayer, 6)), getElementMatrix(localPlayer)
    local targetPos = Vector3(playerMatrix[4][1] + playerMatrix[2][1] * 3, playerMatrix[4][2] + playerMatrix[2][2] * 3, playerMatrix[4][3] + playerMatrix[2][3] * 3)
    -- If the searchlight we use for the effect doesn't exist, create it
    -- If it is already created, then simply update its start and end positions
    if not helmetLantern then
        helmetLantern = createSearchLight(helmetPos, targetPos, 0, 15)
		local a , b = getSearchLightEndPosition(helmetLantern)
		outputChatBox(a .." "..b)
    else
        setSearchLightStartPosition(helmetLantern, helmetPos)
        setSearchLightEndPosition(helmetLantern, targetPos)
    end
end

local function manageHelmetLantern()
    local helmetLanternOff = not helmetLantern
    playSoundFrontEnd(helmetLanternOff and 37 or 38)
    if helmetLanternOff then
        -- Let updateHelmetLantern take care of creating and updating the effect
        addEventHandler("onClientPreRender", root, updateHelmetLantern)
    else
        -- Stop updateHelmetLantern doing its job and clear variables
        removeEventHandler("onClientPreRender", root, updateHelmetLantern)
        destroyElement(helmetLantern)
        helmetLantern = nil
    end
end

-- Allow the player to turn the helmet lantern or on off by using /togglelantern or pressing O
addCommandHandler("togglelantern", manageHelmetLantern)
bindKey("o", "down", manageHelmetLantern)

See also