Working House Lighting

axeman

OpenDayZ Rockstar!
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: <<<
lights_stary.jpg

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";
};
lights_cherno.jpg
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
Code:
!"fixes\change_streetlights.sqf"
to stop BE booting players when using this script.​
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: <<<
 
''Script fixes\ change_streetlights.sqf Not found'' or something like that.
after deleting fixes\ i got kicked by BE script restriction 20, any suggestions?
 
something to del in BE script.txt ?

On my test serveur i have del all battle eye txt ^^
 
i commented this
in script.txt (Open with Notepad++)
Line 22 : //5 createVehicle !"\"createVehicle\","..........
 
Thanks Nox, you can call the 'fixes' folder anything you want, I call mine axeman. So long as you reference the correct path from the init.sqf.

To stop BE kicking you it is probably better to add, in scripts.txt:
Code:
!"fixes\change_streetlights.sqf"
to the end of the line / function (createVehicle) that is booting you, rather than comment / delete the whole line.

This will filter out the process from BE and keep all of the other stuff in that line. That way hackers won't be able to use createVehicle.
 
One thing I have noticed is that the ambient lights, as they are vehicles. vanish eventually. I think this is as the player, that triggered them, leaves the server.

The house windows stay lit up but without the additional light source the surrounding area is no longer lit. And, as the windows are still lit, a new ambient light source is not triggered / created.

I will be tweaking this code soon, ideally I want to create the vehicles on the server. This means either triggering all of the lights as the server starts or calling a server script from the player trigger.

Both of which I am going to have to experiment with. I am a little concerned with creating a new vehicle for every house in Chernarus in case it puts an unnecessary load on the server.. Anyone with more experience please feel free to chip in :)
 
Unsure why I can't get this running. Pretty straightforward. I've got my streetlights file in my Fixes folder, and added the line into my init file. I first tried adding it to the existing isdedicated line, but no dice there, so I tried this:

Code:
if (!isDedicated) then {
 
    if (!isNil{uiNameSpace getVariable 'DB2DZ_IDD_Debug2_DZ'}) then {
    uiNameSpace setVariable ['DB2DZ_IDD_Debug2_DZ', nil];
    };
 
    //Conduct map operations
    0 fadeSound 0;
    0 cutText [(localize "STR_AUTHENTICATING"), "BLACK FADED",60];
   
    //Run the player monitor
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
    _playerMonitor =    [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";   
};
 
if (!isDedicated) then {
[] execVM "fixes\change_streetlights.sqf";
};

Seperately, also doesn't work for me. I'm spawning myself in the center of cherno in the dead of night.

I'm running Pwnozor's server pack.
 
So I had this running, but my server began going so slow it was unplayable, not sure if it was this or something else but for now I have removed it
 
So I had this running, but my server began going so slow it was unplayable, not sure if it was this or something else but for now I have removed it

For a busy server it could have consequences as a vehicle (the ambient light source) will be created for every player on every house they pass within 2000m. It could get quite bright also :)

Like I said, my server is quite quiet. Is really a proof of concept at the moment. I want to run this at the server and be able to check for an existing light source etc. The original code just kept looping and re-creating the light sources endlessly.. It hung my test server with just me on it..

Am busy writing an .exe scheduler to automate server restarts (using task scheduler) and handle other stuff (vehicle restocking and repositioning, db cleansing etc.).

I will be picking this back up after I finish my scheduler..
 
Unsure why I can't get this running. Pretty straightforward. I've got my streetlights file in my Fixes folder, and added the line into my init file. I first tried adding it to the existing isdedicated line, but no dice there, so I tried this:

Code:
if (!isDedicated) then {
 
    if (!isNil{uiNameSpace getVariable 'DB2DZ_IDD_Debug2_DZ'}) then {
    uiNameSpace setVariable ['DB2DZ_IDD_Debug2_DZ', nil];
    };
 
    //Conduct map operations
    0 fadeSound 0;
    0 cutText [(localize "STR_AUTHENTICATING"), "BLACK FADED",60];
 
    //Run the player monitor
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
    _playerMonitor =    [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";
};
 
if (!isDedicated) then {
[] execVM "fixes\change_streetlights.sqf";
};

Seperately, also doesn't work for me. I'm spawning myself in the center of cherno in the dead of night.

I'm running Pwnozor's server pack.


I have tested it on a Bliss server, can't see that it would make any difference (don't quote me) Make sure it is in MPMissions and packed into dayz_1.chernarus.pbo (or <mod_name>.pbo). Or extract the files from your .pbo, add this in and then delete the .pbo. The .pbo is a 'zipped' up version of the folder/file structure and will work just as well unpacked..
 
For a busy server it could have consequences as a vehicle (the ambient light source) will be created for every player on every house they pass within 2000m. It could get quite bright also :)

Like I said, my server is quite quiet. Is really a proof of concept at the moment. I want to run this at the server and be able to check for an existing light source etc. The original code just kept looping and re-creating the light sources endlessly.. It hung my test server with just me on it..

Am busy writing an .exe scheduler to automate server restarts (using task scheduler) and handle other stuff (vehicle restocking and repositioning, db cleansing etc.).

I will be picking this back up after I finish my scheduler..
Well I am defiantly following this project!
KEEPITALIVEEE :p
 
I'm quite familiar with the Dayz server file structure, been running a server for near 8 months now. :)

change_streetlights.sqf is inside my Fixes folder. I haven't pbo-ed my MPMissions folder in close to half a year.

Where exactly in your init are you placing your exec example? It could help me, as I have a number of things also in there starting under isdedicated.

I tried both:

Code:
if (!isDedicated) then {
 
    if (!isNil{uiNameSpace getVariable 'DB2DZ_IDD_Debug2_DZ'}) then {
    uiNameSpace setVariable ['DB2DZ_IDD_Debug2_DZ', nil];
    };
 
    //Conduct map operations
    0 fadeSound 0;
    0 cutText [(localize "STR_AUTHENTICATING"), "BLACK FADED",60];
   
    //Run the player monitor
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
    _playerMonitor =    [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";   
};
 
if (!isDedicated) then {
[] execVM "Fixes\change_streetlights.sqf";
};

And also:

Code:
if (!isDedicated) then {
 
[] execVM "Fixes\change_streetlights.sqf";
 
    if (!isNil{uiNameSpace getVariable 'DB2DZ_IDD_Debug2_DZ'}) then {
    uiNameSpace setVariable ['DB2DZ_IDD_Debug2_DZ', nil];
    };
 
    //Conduct map operations
    0 fadeSound 0;
    0 cutText [(localize "STR_AUTHENTICATING"), "BLACK FADED",60];
   
    //Run the player monitor
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
    _playerMonitor =    [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";   
};
 
This is my init.sqf:
Code:
startLoadingScreen ["","DayZ_loadingScreen"];
enableSaving [false, false];
 
dayZ_instance = 1;    //The instance
hiveInUse    =    true;
initialized = false;
dayz_previousID = 0;
 
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\variables.sqf"; //Initilize the Variables (IMPORTANT: Must happen very early)
progressLoadingScreen 0.1;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\publicEH.sqf";    //Initilize the publicVariable event handlers
progressLoadingScreen 0.2;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\medical\setup_functions_med.sqf"; //Functions used by CLIENT for medical
progressLoadingScreen 0.6;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\compiles.sqf"; //Compile regular functions
progressLoadingScreen 0.7;
 
player setVariable ["BIS_noCoreConversations", true];
enableRadio false;
 
"filmic" setToneMappingParams [0.153, 0.357, 0.231, 0.1573, 0.011, 3.750, 6, 4]; setToneMapping "Filmic";
 
if (isServer) then {
    hiveInUse = true;
    _serverMonitor = [] execVM "\z\addons\dayz_server\system\server_monitor.sqf";
};
 
if (!isDedicated) then {
    0 fadeSound 0;
    0 cutText [(localize "STR_AUTHENTICATING"), "BLACK FADED",60];
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
    _playerMonitor =    [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";
 
};
 
// SnowStorm:
//if (!isDedicated) then {
    //[] execVM "fixes\effects.sqf";
//};
//progressLoadingScreen 0.6;
if ([FONT=Consolas]!isDedicated[/FONT]) then {
    if (daytime>20 && daytime<4) then {
    [] execVM "fixes\change_streetlights.sqf";
    progressLoadingScreen 0.8;
    };
};
diag_log format["DateTime: %1",daytime];
 
//REPLACE WIRE WITH MOUNTAIN DEW AT ALL SPAWN POINTS
spawn_loot = compile preprocessFileLineNumbers "fixes\spawn_loot.sqf";
progressLoadingScreen 1.0;

I have been messing with only setting it off at certain hours, seems to work ok..

I would think that the new fixes would need to be in the .pbo to work, does the game look for the folders also if the .pbo is present ? I didn't think so, but I may be wrong.

I can't test at the moment as I have broken my local install again trying to move files from dayz code into the bliss code :)
 
Back
Top