AreVehicleLightsOn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
{{New feature/item|3.0160|1.5.7|19626|This function is used to find out whether the lights of the vehicle are on.}}
{{New feature/item|3.0158|1.5.7|19626|This function is used to find out whether the lights of the vehicle are on.}}
 
{{Note|
Note that this is different to [[getVehicleOverrideLights]] in that this function will return '''true''' if the lights were turned on by natural causes: unless [[setVehicleOverrideLights]] is used, vehicles always automatically disable their lights between 06:00 and 07:00 and enable them between 20:00 and 21:00.
*This is different to [[getVehicleOverrideLights]] because this function will return '''true''' if the lights were turned on by natural causes.
* Unless [[setVehicleOverrideLights]] is used, vehicles always automatically disable their lights at 06:25 and enable them at 20:26.}}


==Syntax==
==Syntax==
Line 17: Line 18:


==Example==
==Example==
{{Example}}
This example checks if your vehicle lights are on/off and tells you the reason
<syntaxhighlight lang="lua">addCommandHandler('checkMyLights' , function ()
if not isPedInVehicle(localPlayer) then
outputChatBox('Please enter your vehicle first' , 150 , 50 , 0 )
return end
local message = ''
local myVehicle = getPedOccupiedVehicle(localPlayer)
local checkIfOverrided = getVehicleOverrideLights(myVehicle)
if checkIfOverrided == 0 then
if areVehicleLightsOn(myVehicle) then
local h , m = getTime()
if h > 6 and h < 20 then
message = 'on. Reason: You are in a dark place' -- vehicle lights turn on in some dark places during the day like this position  x:-1513  y:-287  z:6
else
message = 'on. Reason: It is night'
end
else
message = 'off. Reason: It is day'
end
elseif checkIfOverrided == 1 then
message = 'off. Reason: They are forced off'
else
message = 'on. Reason: They are forced on'
end
outputChatBox('Your vehicle lights are turned '..message , 0 , 150 , 50 )
end)</syntaxhighlight>
 
==Requirements==
{{Requirements|n/a|1.5.7-9.19626|}}


==See Also==
==See Also==
{{Client vehicle functions}}
{{Client vehicle functions}}

Latest revision as of 13:48, 25 October 2020

This function is used to find out whether the lights of the vehicle are on.

[[{{{image}}}|link=|]] Note:
  • This is different to getVehicleOverrideLights because this function will return true if the lights were turned on by natural causes.
  • Unless setVehicleOverrideLights is used, vehicles always automatically disable their lights at 06:25 and enable them at 20:26.

Syntax

bool areVehicleLightsOn ( vehicle theVehicle )

OOP Syntax Help! I don't understand this!

Method: vehicle:areLightsOn(...)
Variable: .lightsOn


Required Arguments

  • theVehicle: the vehicle you wish to retrieve the lights state of.

Returns

Returns true if the lights are on, false otherwise.

Example

This example checks if your vehicle lights are on/off and tells you the reason

addCommandHandler('checkMyLights' , function ()
if not isPedInVehicle(localPlayer) then
outputChatBox('Please enter your vehicle first' , 150 , 50 , 0 )
return end
local message = ''
local myVehicle = getPedOccupiedVehicle(localPlayer)
local checkIfOverrided = getVehicleOverrideLights(myVehicle)
	if checkIfOverrided == 0 then
		if areVehicleLightsOn(myVehicle) then
			local h , m = getTime()
			if h > 6 and h < 20 then
				message = 'on. Reason: You are in a dark place' -- vehicle lights turn on in some dark places during the day like this position   x:-1513  y:-287  z:6
			else
				message = 'on. Reason: It is night'
			end
		else
			message = 'off. Reason: It is day'
		end
	elseif checkIfOverrided == 1 then
		message = 'off. Reason: They are forced off'
	else
		message = 'on. Reason: They are forced on'
	end
	
outputChatBox('Your vehicle lights are turned '..message , 0 , 150 , 50 )
end)

Requirements

Minimum server version n/a
Minimum client version 1.5.7-9.19626

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.5.7-9.19626" />

See Also