CreateSearchLight: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(Added a nice example) |
||
| Line 28: | Line 28: | ||
==Example== | ==Example== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | local helmetLanterns | ||
local function updateHelmetLantern() | |||
-- We need to do it this way because there isn't a setSearchLightStart/EndPosition for now | |||
-- Calculate light properties | |||
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) | |||
-- Finally, create the updated searchlight | |||
helmetLanterns[#helmetLanterns + 1] = createSearchLight(helmetPos, targetPos, 0, 15) | |||
-- We need to keep two searchlights, so they have time to render visible and look nice | |||
if #helmetLanterns > 2 then | |||
destroyElement(helmetLanterns[1]) | |||
table.remove(helmetLanterns, 1) | |||
end | |||
end | |||
local function manageHelmetLantern() | |||
local helmetLanternOff = not helmetLanterns | |||
playSoundFrontEnd(helmetLanternOff and 37 or 38) | |||
if helmetLanternOff then | |||
-- Let updateHelmetLantern take care of creating and updating the effect | |||
helmetLanterns = {} | |||
addEventHandler("onClientPreRender", root, updateHelmetLantern) | |||
else | |||
-- Stop updateHelmetLantern doing its job and clear variables | |||
removeEventHandler("onClientPreRender", root, updateHelmetLantern) | |||
for _, helmetLight in ipairs(helmetLanterns) do | |||
destroyElement(helmetLight) | |||
end | |||
helmetLanterns = nil | |||
end | |||
end | |||
-- Allow the player to turn the helmet light or on off using /turnlight or pressing O | |||
addCommandHandler("turnlight", manageHelmetLantern) | |||
bindKey("o", "down", manageHelmetLantern) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See also== | ==See also== | ||
{{Client_searchlight_functions}} | {{Client_searchlight_functions}} | ||
Revision as of 18:16, 8 December 2015
This function creates a searchlight. A searchlight is a spotlight which looks like the one available in the Police Maverick.
Syntax
searchlight createSearchLight ( float startX, float startY, float startZ, float endX, float endY, float endZ, float startRadius, float endRadius [, bool renderSpot = true ] )
OOP Syntax Help! I don't understand this!
- Method: SearchLight.create(...)
Required Arguments
- startX: the X coordinate where the searchlight light cone will start.
- startY: the Y coordinate where the searchlight light cone will start.
- startZ: the Z coordinate where the searchlight light cone will start.
- endX: the X coordinate of the direction where the searchlight will point to.
- endY: the Y coordinate of the direction where the searchlight will point to.
- endZ: the Z coordinate of the direction where the searchlight will point to.
- startRadius: the radius of the searchlight's light cone in its beginning.
- endRadius: the radius of the searchlight's light cone in its end.
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.
- renderSpot: if true, the searchlight will lighten the surface where it ends.
Returns
If every argument is correct, this function returns a searchlight element. Otherwise, it returns false.
Example
local helmetLanterns
local function updateHelmetLantern()
-- We need to do it this way because there isn't a setSearchLightStart/EndPosition for now
-- Calculate light properties
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)
-- Finally, create the updated searchlight
helmetLanterns[#helmetLanterns + 1] = createSearchLight(helmetPos, targetPos, 0, 15)
-- We need to keep two searchlights, so they have time to render visible and look nice
if #helmetLanterns > 2 then
destroyElement(helmetLanterns[1])
table.remove(helmetLanterns, 1)
end
end
local function manageHelmetLantern()
local helmetLanternOff = not helmetLanterns
playSoundFrontEnd(helmetLanternOff and 37 or 38)
if helmetLanternOff then
-- Let updateHelmetLantern take care of creating and updating the effect
helmetLanterns = {}
addEventHandler("onClientPreRender", root, updateHelmetLantern)
else
-- Stop updateHelmetLantern doing its job and clear variables
removeEventHandler("onClientPreRender", root, updateHelmetLantern)
for _, helmetLight in ipairs(helmetLanterns) do
destroyElement(helmetLight)
end
helmetLanterns = nil
end
end
-- Allow the player to turn the helmet light or on off using /turnlight or pressing O
addCommandHandler("turnlight", manageHelmetLantern)
bindKey("o", "down", manageHelmetLantern)
See also
- createSearchLight
- getSearchLightEndPosition
- getSearchLightEndRadius
- getSearchLightStartPosition
- getSearchLightStartRadius
- setSearchLightEndPosition
- setSearchLightEndRadius
- setSearchLightStartPosition
- setSearchLightStartRadius