{"name":"switchLight","title":"switchLight","type":"command","url":"https://community.bistudio.com/wiki/switchLight","revid":364994,"updated":"2024-07-04T19:58:05Z","groups":["Lights"],"status":"ok","games":{"ofp":"1.00","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.00","arma3_since":"0.50","locality":{"effect":"local"},"description":"Controls whether a lamp is lit or not.\n\n> [!NOTE]\n> This command was originally designed to only work with `CfgNonAIVehicles` class `\"StreetLamp\"` only.\n> Since Arma 3 v1.92 this command was extended to work with street lights and some prop lights, like portable construction light.","syntaxes":[{"syntax":"lamp switchLight mode","params":[{"name":"lamp","type":"Object","type_expr":"Object"},{"name":"mode","type":"String","description":"mode can be: \"ON\", \"OFF\" or \"AUTO\" (*lamp* is on only during nighttime, default)","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"lamp"},"right":{"text":"mode"}}],"examples":[{"code":["(object 12345) switchLight \"OFF\";"]},{"code":["nearestObject [player, \"Streetlamp\"] switchLight \"OFF\";"]},{"code":["cursorObject switchLight \"ON\";"]}],"see_also":["lightIsOn","BIS_fnc_switchLamp"],"notes":[{"user":"Killzone_Kid","date":"2013-09-16T11:14:00Z","text":"*Before Arma 3 v1.92* use setHit instead:\n\n```sqf\n_lamp = nearestObject [player, \"Lamps_base_F\"];\n_lamp setHit [\"light_1_hitpoint\", 0.97];    // off\n_lamp setHit [\"light_1_hitpoint\", 0];        // on\n```\n\nSwitch all lights off in the 500 radius of player:\n\n```sqf\nprivate _lamps = nearestObjects [player, [\"Lamps_base_F\", \"PowerLines_base_F\", \"PowerLines_Small_base_F\"], 500];\n\n{\n    for \"_i\" from 0 to (count getAllHitPointsDamage _x -1) do\n    {\n        _x setHitIndex [_i, 0.97];\n    };\n} forEach _lamps;\n```"},{"user":"Sa-Matra","date":"2023-03-01T14:12:31Z","text":"How to disable all lamps using the latest Arma 3 commands, a modern method. Disable all lights that are pre-placed on the map, on the entire map:\n\n```sqf\n{\n    _x switchLight \"OFF\";\n} forEach (1 allObjects 0);\n```\n\nDisable all script-spawned and editor-placed lamps:\n\n```sqf\n{\n    _x switchLight \"OFF\";\n} forEach (8 allObjects 0);\n```\n\nThese snippets iterate through all buildings and run switchLight on them. If they're lamps, they'll be turned off."}]}