dayZ House, Building and Custom Object (Streetlamp) Lights.
>>>There is a new version of this script further down<<<
>>>this thread that is currently in testing..Click on: <<<

I found this thread http://dayzmod.com/forum/index.php?/topic/96862-dayz-night-lighting/ when trying to turn on street lights. I really like the idea of having some lighting, personally I think it adds to the 'atmosfear'..
Apparently the actual street lights are banned, but using the code in that thread I decided to go for the next best thing and turn the lights on in buildings and then add an ambient light to light the surrounding area.
This will light up non-enterable houses within a distance of 600m of the player. It creates an ambient light source that lights the surrounding area.
Not all houses are lit each time and there is a random chance that power will fail to each house, the lights will flicker off if this happens.
It is still dark at night and finding the loot spawns is still difficult as they are not lit. I haven't noticed that it makes you more visible to zombies.
Put this in <path to arma2 installation>/MPMissions/<mod folder>/fixes/
change_streetlights.sqf
Code:
while {alive player}
do
{
if(daytime<6||daytime>18)//EDITABLE - Change the stop and start times for the script. No need to create lights in the day. If server set to Static time, local time seems to be 12.5007..
then {
private ["_strMessage","_brightness","_objLightPoint","_awayx","_awayy","_lp","_test","_hcount","_dir","_animlightpoint"];
_objHouse = nearestObjects [player, ["House"], 600]; //EDITABLE - Change distance, (in metres) from the player, at which houses have their lights switched on.
_housecount = count _objHouse;
_hcount=0;
{
//hint format ["(%1) %2 | Script Running..",_hcount, daytime];
_switching = random 100;//Generate random chance for power failures
_switchpercent = 85;//EDITABLE - Percentage for reliability of power supply. eg. 65 will be 65% chance of lights coming on in each house and 35% chance that lights will fail and flicker off.
_lightstate = _x animationPhase "Lights_1";//Window lights on or off
_pos = getPos _x;
_xpos = _pos select 0;
_ypos = _pos select 1;
_dir = getDir _x;
if(_lightstate==0) then
{
if(_switching<_switchpercent)then //Turn on lights in house windows
{
for "_i" from 1 to 5 do {
_x animate [format ["Lights_%1",_i],1];
};
sleep 0.1; // Give time for engine to register light on - I found ambient light wasn't creating without this pause.
};
};
_objLightPoint = nearestObject [_x, "#lightpoint"];
_lightpos = getPos _objLightPoint;
_lightposX = _lightpos select 0;
_lightposY = _lightpos select 1;
_awayx=_xpos-_lightposX;
_awayy=_ypos-_lightposY;// x/y distance of lightpoint from current house
_test = getDir _objLightPoint;
if((_awayx>1 or _awayx<-1)or(_awayy>1 or _awayy<-1))then
{
if(_x animationPhase "Lights_1"==1) then //Only create lightsource for houses with windows lit, stops unlit houses, barns etc having a light source
{
if(_switching<_switchpercent)then //Do lightpoint stuff
{
_lp = "#lightpoint" createVehicle [0,0,0];
_lp setLightColor [1, 1, 1]; // Set its colour
_lp setLightBrightness 0.01; // Set its brightness
_lp setLightAmbient[5, 5, 5]; //Light the surrounding area
_lp setPos [_xpos,_ypos,-3];// Position it underground to reduce glare and spread
_lp setDir _dir;
//hint format["(%5) %4 Houses: Create Lightpoint ! Distance %1:%2. Test:%3",_awayx,_awayy,_test,_housecount,_hcount];
sleep 0.5;
};
};
}
else
{
if(_x animationPhase "Lights_1"==1) then //Only recreate lightsource for houses with windows lit
{
_objLightPoint setLightColor [1, 1, 1]; // Set its colour
_objLightPoint setLightBrightness 0.01; // Set its brightness
_objLightPoint setLightAmbient[5, 5, 5]; //Light the surrounding area
};
//hint format["(%5) %4 Houses: Lightpoint (%6) Found ! Distance %1:%2. Test:%3",_awayx,_awayy,_test,_housecount,_hcount,_objLightPoint];
sleep 0.5;
};
if(_lightstate==1) then //Decide if to turn Light Off with Animation..
{
if(_switching>_switchpercent)then
{
_animlightpoint = nearestObject [_x, "#lightpoint"];
for "_s" from 1 to 5 do {
if(_s%2==0)then
{
_brightness=0;
for "_l" from 1 to 5 do {
_x animate [format ["Lights_%1",_l],0];
};
}
else
{
_brightness=0.01;
for "_l" from 1 to 5 do {
_x animate [format ["Lights_%1",_l],1];
};
};
_animlightpoint setLightBrightness _brightness;
_sleeptime=random 100;
_sleeptime=_sleeptime/500;
sleep _sleeptime;
};
for "_l" from 1 to 5 do {
_x animate [format ["Lights_%1",_l],0];
};
_animlightpoint setLightBrightness 0;
//hint format["(%3) %2 Houses: Switch light off Test:%1",_test,_housecount,_hcount];
sleep 6;
};
};
_hcount=_hcount+1;
} forEach _objHouse;
};
}
Add this to init.sqf
Code:
if (!isDedicated) then {
[] execVM "fixes\change_streetlights.sqf";
};

Flying across a city in a chopper is quite fun, watching the lights catch up with you.
. You can edit 3 parameters (commented with \\EDITABLE):
- The times that the script will start and stop running.
- The distance, from the player, at which the script will work.
- The reliability of the power supply. The chance that a house will light up and the chance that the light will fail and flicker out.
BattlEye: Edit your scripts.txt (<path to arma2 installaion>\<mod folder>\BattlEye\scripts.txt), find the line with createVehiclenear the start, on the end of this line add
to stop BE booting players when using this script.
Code:
!"fixes\change_streetlights.sqf"
Use notepad, I prefer notepad++, to edit the files mentioned here..
This post has been edited a few times since the first version. This is the latest version of the code. This thread covers most issues with getting it running. Please ask if you are having trouble or have any suggestions.
>>>There is a new version of this script further down<<<
>>>this thread that is currently in testing..Click on: <<<