Turning off streetlamps in an area

So you want to turn off all Streetlamps in an area?  You can do that pretty easily.  First place a Gamelogic in the middle of your town.  Then put the following code in it’s Init field.

{_x switchLight "OFF"} forEach ((getPos this) nearObjects ["StreetLamp",200]);

That will turn off all StreetLamps within 200m of the Gamelogic.

Here’s code I used in a mission on Chernarus to turn out all the lights in a city when I blew up two Power Generators:

_types = ["Land_PowLines_WoodL", "Land_PowLines_ConcL", "Land_lampa_ind_zebr", "Land_lampa_sidl_3", "Land_lampa_vysoka", "Land_lampa_ind", "Land_lampa_ind_b", "Land_lampa_sidl"];

while {true} do
        // power1 and power2 were two objects I placed.
	waituntil{!alive power1 and !alive power2};

	// delete the light over the generators.
	deletevehicle obsLight;

	for [{_i=0},{_i < (count _types)},{_i=_i+1}] do
                // powercoverage is a marker I placed.
		_lamps = getmarkerpos "powercoverage" nearObjects [_types select _i, 1200];
		sleep 1;
		{_x switchLight "OFF";} forEach _lamps;

Here are two demo missions which show this effect at work. The first method includes pre-placed items which can be deactivated via addAction in order to cut the power. Destroying them also works. The second example shows how destroying items on the map (the power transformers) can be used for the same effect. Hint, you'll need 3 satchels each!

  1. #1 by Sigint on August 23, 2010 - 8:36 PM

    Hey! I was wondering, how would I go about using this script (Or something similar) with a generator in a way of ‘Destroy the generator and the power goes out in X town’ as a sort of side task that can aid in a mission?

    Thanks man! ^_^

    • #2 by kylania on August 23, 2010 - 8:58 PM

      Added an example for you. 🙂

  2. #3 by Sigint on August 23, 2010 - 9:25 PM

    Ah, thanks! You’re ninja quick with this ^_^ Thanks!

  3. #4 by Sigint on August 23, 2010 - 9:33 PM

    Ack! I am such a noob to coding! I don’t know how I would go about that, usint a init.sqf or just putting it in a trigger! D: I’m not good at all at reverse-engineering a script T_T Uhg I hate being a script-noob ha

    • #5 by kylania on August 23, 2010 - 10:09 PM

      Either or. In my mission I actually called it from the init of a wall lamp I’d placed nearby. 🙂

      nul = [] execVM “power.sqf”;

      • #6 by Sigint on August 24, 2010 - 7:18 PM

        Err… >_< Right. I tried to use the 'nul = [] execVM “power.sqf”;' code on an object nearby but it says invalid #. ~_~ So hopefully you can shed more like with an example if possible… like I resquested earlier. I thought I could get it without one but I can't T_T

  4. #7 by Sigint on August 23, 2010 - 10:53 PM

    Oh? Would it be too much of me to ask for the mission so I can cut the script up and look how it works in actual action or maybe just an example mission? >_< I know it's asking much but it's easier for me to twist the scripts around from a pre-existing mission like from your example missions instead of the code you placed ^_^; Haha sorry. If not it's okay, I'm still trying to figure it out XD

    • #8 by kylania on August 24, 2010 - 8:58 PM

      Added two demo missions to the post so you can see the effect in action. Let me know if you have questions about them!

  5. #9 by Sigint on August 25, 2010 - 4:08 AM

    Ah yes! Thank you! Thank you thank you thank you! I can easily figure it out now! ^_^ Thaaaank you! Makes it so much easier. T_T I ever get this campaign released (Let alone finished T_T) I will def be putting you in the thanks for all the help! T_T

  6. #10 by gobbo on August 25, 2010 - 1:02 PM

    I really like that, used it in a EMP script to switch whole areas off.
    But the red flashing lights on tall buildings still stay switched on. Do you know the classnames/types of those?

  7. #11 by Lucky on November 24, 2010 - 12:51 PM

    You can find Arma2 classnames at the armatechsquad library:

Comments are closed.