setTrafficLightState | Multi Theft Auto: Wiki Skip to content

setTrafficLightState

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


Sets the current traffic light state. This state controls the traffic light colors. For instance, state 1 will cause the north and south traffic lights to be amber, and the ones left and east will turn red.

Syntax

bool setTrafficLightState ( int state )
Required Arguments
  • state: If an integer is provided, the state you wish to use (possible values: 0-9). Else, one of the following strings: auto : Sets the traffic lights default behavior (switches the colors automatically). disabled : Turns traffic lights off.

Returns

  • bool: value

Returns true if the state was successfully set, false otherwise.

Code Examples

shared

This example causes all traffic lights to be out of order. (flashing amber)

function handleTrafficLightsOutOfOrder()
-- See if the lights are currently off
local lightsOff = getTrafficLightState() == 9
if lightsOff then
-- If they're off, turn them on
setTrafficLightState(6)
else
-- If they're on, turn them off
setTrafficLightState(9)
end
end
-- Repeat it every half a second
setTimer(handleTrafficLightsOutOfOrder,500,0)

See Also

World Functions