Home   Help Search Login Register  

Author Topic: How to switch off all the lights in Chernarus?  (Read 2782 times)

0 Members and 1 Guest are viewing this topic.

Offline mathias_eichinger

  • Missions Depot
  • Administrator
  • *****
  • I'm a llama!
How to switch off all the lights in Chernarus?
« on: 26 Apr 2010, 19:09:42 »
Hey lads,

do you know if there is a way to switch off all the lights in Chernarus, e.g. simulate a nation-wide electricity blackout?


Offline Loyalguard

  • Former Staff
  • ****
Re: How to switch off all the lights in Chernarus?
« Reply #1 on: 26 Apr 2010, 20:49:22 »
I am nearing alpha on my Chernarus Electrical Grid script pack, which is the sequel to Sahrani Electrical Grids for A1 which simulates an entire Island Electrical Grid to include switching lights on and off.  There are over 1000 street lamps on Chernarus and some of them arre off by themseleves near nothing else so it takes a bit to find them all.  I have an algorithim that finds them all using nearObjects in a series of small radii (500m or less) and and switches them off systematically using switchLight.  I do it like this because if you try to switch them all off in one big radius (like 11000m outward from Novy Sobor) it causes a LOT of lag (several seconds).  

The algorithim is lengthy and is meant to be executed in stages, but I am happy to post it when I get home tonight (I don't have it with me at work).  

And just to note, switchLight is a local command, so it has to be run on all machines to have full effect or some players will have lights on and some off if MP and you only run it local.

Update:

Ok, here you go.  It's not really an algorithm, it is more of a brute force method ;).  This is not totally pretty and clean as I ripped it from my larger script pack to make it more universal, but the below script will switch off every street lamp in Chernarus.  The caveats being:

1) The switching code is laggy (5-10 secs) unless you use the include startLoadingScreen/endLoadingScreen commands.
2) It will only turn off street lamps.  Tower lights, traffic signals, and ALICE houselights are not affected (there is away to turn off ALICE lights but we can cover that later if necessary).

Here is how it works.  The script creates an array of circle positions and radii that I have pre-compiled to cover every street lamp on the island and tailored the radii to only cover the lamps.  It then iterates through each one of these search radii finding it street lamp with nearObjects and uses switchLight to turn each light off.  I have included some additional code (and script) that if used will verify that every light is off and if not will put a yellow dot marker at its location.  Just comment/remove it if you don't want to use it.

Regarding startLoadingScreen/endLoadingScreen, if you are unfamiliar with them, they are a fantastic combo that halts the game simulation and scene drawing so that scripts run at full speed.  Without them, it would take about 10 secs (on my slow machine) to iterate though all of the lights.  With them at mission start (i.e. script launched from init.sqf or unit init line), it only adds a few seconds to the "Receiving..." screen (you never see "initializing..." unless you run the script AFTER mission start).  I am working on further optimizing the searches to avoid lag all together that will take me some more time (days to weeks) and is part of my bigger overall project.  So, enough intro, here is the code (warning: long):


LGD_allCherLightsOff.sqf:
Code: [Select]
/*
File: LGD_allCherLightsOff.sqf
Version: 0.5
Author: Loyalguard

Description:
A script to turn off all the lights on Chernarus

Parameters:
None.
 
Execution:
Executed from any other executing instance.
*/

// Scope //

private ["_zones"];

// Halt simulation and scene drawing so script runs at full speed.  Comment or remove this if you do not want to pause the simulation and screen drawing but may cause lag otherwise.  If at mission start you will never see the below text.  Mission start is the recommended time to run this script.

startLoadingScreen ["Initializing..."];

// Create an array of circles that should encompass all street lamps on the island.  Store the position of the center of the circle, its radius, and the name of the geographical area.  Suffix meanings are ..._c (center), ..._n (north), ..._e (east), ..._s (south_, and ..._w (west).  Even though a name is included (third element in each sub-array), it is not used by the script, it is only for reference.

_zones =
[
[[8468.74, 6678.053, 0], 50, "guglovo"],
[[7560.065, 5148.78, 0], 175, "mogilevka"],
[[7219.85, 6969.44, 0], 25, "novysobor_s"],
[[7085.968, 7687.262, 0], 200, "novysobor_c"],
[[6526.572, 6104.209, 0], 100, "vyshnoye"],
[[6149.618, 7768.536, 0], 350, "starysobor"],
[[6011.312, 10335.15, 0], 325, "grishino_c"],
[[5951.45, 11203.6, 0], 25, "grishino_n"],
[[5906.005, 4764.474, 0], 250, "nadezhdino_c"],
[[5820.046, 4040.917, 0], 150, "nadezhdino_s"],
[[5350.612, 8553.725, 0], 250, "kabinino"],
[[5011.151, 12510.67, 0], 100, "petrovka"],
[[4785.475, 9978.161, 0], 500, "airfield_s"],
[[4278.788, 10729.83, 0], 500, "airfield_n"],
[[3793.466, 8861.744, 0], 375, "vybo_c"],
[[3121.17, 9264.231, 0], 25, "vybo_n"],
[[3069.559, 7903.22, 0], 275, "pustoshka_c"],
[[3190.208, 7079.035, 0], 450, "pustoshka_s"],
[[2165.78, 7922.44, 0], 25, "pustoshka_w"],
[[2700.753, 9800.041, 0], 350, "lopatino"],
[[2432.338, 6301.245, 0], 300, "sosnovka"],
[[1989.7784, 7358.7549, 0], 100, "myshkino"],
[[1895.589, 12431.12, 0], 75, "skalka"],
[[5627.59, 2090.783, 0], 200, "mutnaya_c"],
[[5735.11, 2856.721, 0], 150, "mutnaya_n"],
[[5403.767, 3724.283, 0], 100, "hill191"],
[[5182.85, 4188.01, 0], 25, "hill229"],
[[4563.802, 2456.013, 0], 300, "balota_c"],
[[4185.026, 3285.422, 0], 150, "balota_n"],
[[5153.537, 2209.69, 0], 300, "balota_e"],
[[3599.484, 2398.265, 0], 225, "komarov_c"],
[[2796.156, 3021.082, 0], 525, "komarov_n"],
[[6726.109, 2703.005, 0], 525, "chernogorsk_c"],
[[6372.947, 3493.757, 0], 400, "chernogorsk_n"],
[[7095.924, 3206.101, 0], 125, "chernogorsk_e"],
[[7117.689, 2293.069, 0], 250, "chernogorsk_s"],
[[6135.506, 2190.511, 0], 350, "chernogorsk_w"],
[[10440.75, 2197.366, 0], 500, "elektrozavodsk_c"],
[[11007.99, 2827.19, 0], 350, "elektrozavodsk_e"],
[[10274.7, 1642.771, 0], 150, "elektrozavodsk_s"],
[[9697.336, 1809.307, 0], 500, "elektrozavodsk_w"],
[[13423.7, 2810.72, 0], 25, "skalisty"],
[[12086.09, 3590.905, 0], 200, "kamyshov_c"],
[[11576.19, 3365.395, 0], 350, "kamyshov_w"],
[[10278.27, 3736.325, 0], 125, "topolka"],
[[9237.09, 4970.72, 0], 25, "pusta_e"],
[[9147.81, 3944.635, 0], 200, "pusta"],
[[8682.86, 2422.02, 0], 25, "golova"],
[[8422.1, 4930.37, 0], 25, "pusta_w"],
[[7963.439, 3251.734, 0], 375, "prigorodki_c"],
[[7440.511, 3259.888, 0], 150, "prigorodki_w"],
[[2647.963, 5290.248, 0], 500, "zelenogorsk_c"],
[[2703.273, 5973.573, 0], 75, "zelenogorsk_n"],
[[2490.67, 4693.78, 0], 25, "zelenogorsk_s"],
[[1735.945, 5093.433, 0], 75, "zelenogorsk_w"],
[[5063.373, 5568.144, 0], 250, "pulkovo"],
[[4745.113, 6808.018, 0], 125, "rogovo"],
[[4524.533, 6359.096, 0], 200, "pogorevka"],
[[4440.386, 4627.704, 0], 175, "kozlovka_c"],
[[4404.075, 4027.428, 0], 175, "kozlovka_s"],
[[3704.73, 6005.41, 0], 25, "greenmountain"],
[[3414.418, 4925.941, 0], 100, "drozhino"],
[[3395.85, 3901.314, 0], 100, "bor"],
[[1865.689, 2244.12, 0], 175, "kamenka"],
[[1700.09, 3820.13, 0], 225, "pavlovo"],
[[13345.79, 6328.807, 0], 325, "solnichniy_c"],
[[13110.34, 6907.32, 0], 300, "solnichniy_n"],
[[13061.51, 5701.706, 0], 475, "solnichniy_s"],
[[12218.42, 6257.157, 0], 175, "solnichniy_w"],
[[12945.8, 8169.6, 0], 200, "nizhnoye"],
[[12775.8, 4416.77, 0], 150, "tulga"],
[[11285.77, 5439.169, 0], 100, "msta"],
[[11192.93, 6556.056, 0], 50, "dolina_c"],
[[10557.63, 7007.796, 0], 50, "dolina_w"],
[[10643.82, 7993.118, 0], 200, "polana"],
[[10130.87, 5496.505, 0], 250, "staroye"],
[[9629.635, 6556.247, 0], 100, "shakhova"],
[[12109.82, 9428.826, 0], 525, "berezin_c"],
[[12294.22, 8479.613, 0], 25, "berezin_s"],
[[12903.87, 10000.76, 0], 500, "berezine_"],
[[13351.79, 12864.24, 0], 30, "olsha"],
[[12316.49, 10873.38, 0], 125, "khelm"],
[[12133.21, 7279.321, 0], 200, "orlovets"],
[[12015.26, 12492.08, 0], 475, "krasnatov_e"],
[[10905.53, 12373.8, 0], 450, "krasnatov_c"],
[[10735.14, 10794.45, 0], 20, "dubrovka_n"],
[[9846.278, 10370.91, 0], 250, "dubrovka_w"],
[[10452.34, 9715.529, 0], 310, "dubrovka_c"],
[[10448.9, 8883.941, 0], 25, "gorka_e"],
[[9583.34, 8822.237, 0], 325, "gorka"],
[[8493.104, 11670.62, 0], 400, "gvozdno_c"],
[[8061.176, 11422.6, 0], 150, "gvozdno_w"],
[[4393.16,5659.420,0], 100, "unlabeled1"],
[[1362.99,13401.7,0], 200, "unlabeled2"]
];

// Iterate through each element sub-array in the array _zones and switch off any street lamps found in each search area.  Warning...nested forEach loops which can be system resource intensive.

{{_x switchLight "OFF"} forEach ((_x select 0) nearObjects ["StreetLamp", (_x select 1)])} forEach _zones;

//{{_x switchLight "OFF"} forEach ((_x select 0) nearObjects ["StreetLamp", (_x select 1)]); sleep .01;} forEach _zones; // Use this version instead of one above only if NOT using startLoadingScreen (can't use sleep with startLoadingScreen).

// Resume simulation and scene drawing.
endLoadingScreen; // Comment or remove this if not using startLoadingScreen.

// Check to see if there are any lights left on.  Remove or comment this if you do not want to use it.

//_nul = [] execVM "LGD_CheckLightsOn.sqf";

LGD_CheckLightsOn.sqf:
(Uncomment execVM line in above script and include the below .sqf  in the same folder to use)
Code: [Select]
/*
File: LGD_CheckLightsOn.sqf
Version: 0.5
Author: Loyalguard

Description:
A script to check if street lamps are set to "AUTO" and mark their position  with a yellow dot marker if they are.

Parameters:
None.
 
Execution:
Executed from any other executing instance.
*/

// Scope //

private ["_radius", "_i", "_streetLamps", "_marker"];

// Initialize Variables //

_radius = 11000;
_i=1;

// Create an array containing all street lamp objects within the defined radius of the player.  Place player on Novy Sobor for ideal coverage.
_streetLamps = position player nearObjects ["StreetLamp",_radius];

// Start a forEach loop that cycles through each element of _streetLamps and creates a marker at its position if it is not turned off.  If uncommented, name them incrementally and display the name/number for counting purposes.

{
if (((lightIsOn _x) == "AUTO")) then
{
_marker = createMarker [format ["L%1",_i], position _x];
_marker setMarkerShape "ICON";
_marker setMarkerType "DOT";
_marker setMarkerColor "ColorYellow";
//_marker setMarkerText format ["l%1",_i]; // Comment if you do not want to label individual lamp markers.
_i=_i+1;
};
} forEach _streetLamps;



Good luck!
« Last Edit: 27 Apr 2010, 09:25:50 by Loyalguard »

Offline mathias_eichinger

  • Missions Depot
  • Administrator
  • *****
  • I'm a llama!
Re: How to switch off all the lights in Chernarus?
« Reply #2 on: 03 May 2010, 18:09:09 »
Hey Loyalguard, thank you very much for doing this. I will try it out as soon as I find the time.

Cheers

Mathias