dayZ Street Lights

axeman

OpenDayZ Rockstar!
dayZ Street Lights for Taviana.



Here it is. Server Admins, please read through the info. as I have optimised the code a bit due to the massive amount of lights on Tavi and added options to allow a bit of tweaking. I have set everything default to a setting that I am happy with on my test server. Code is commented and I have gone into detail below.

init.sqf
Code:
if (isServer) then {
axe_server_lampObjs =    compile preprocessFileLineNumbers "lights\fnc_returnLampWS.sqf";
"axeLampObjects" addPublicVariableEventHandler {_id = (_this select 1) spawn axe_server_lampObjs};
};
 
if (!isDedicated) then {
//StreetLights
[] execVM "lights\street_lights.sqf";
};
Create a folder called lights. In it put:

fnc_returnLampWS.sqf: Download and UnRar from HERE.

In the same lights folder put:

street_lights.sqf
Code:
//dayZ Street Lights for Taviana | All Rights Reserved Andrew Gregory aka axeman | axeman@thefreezer.co.uk
waitUntil {!isNull player};
//waitUntil {time > 30};
private ["_nrDist","_finishHour","_startHour","_LocalLight","_doLight","_safeCount","_saferMode","_flickering","_plCellsLitVar","_objLightPoint","_awayx","_awayy","_location","_plCurrX","_plCurrY"];
//
//CAN EDIT
//
_startHour = 17; //Hour to start switching lights on
_finishHour = 6; //Hour to stop switching lights on
_saferMode = true;//Safe(r) Mode - If True (default) Lights every other light (Looks better, more random). False - Lights all streetlights (Sometimes creates a radius around the player, can see lights coming on).
_LocalLight = false;//Local Light - True creates light on each client PC only. False (default) - creates light and shares across network with other clients (Code optimised for the default).
_nrDist = 8; //Default=8. When checking each location if an existing light is already within _nrDist number of metres (8) a new light will NOT be created. To prevent bunching (for fluorescent fights) and reduce the overall number (Street lights are usually at least 28m apart).
//
//NO NEED TO EDIT FURTHER
//
_plCellsLitVar = [];
//axeFlickerLight = compile preprocessfile "lights\flicker_lights.sqf";
private["_mtrxNum","_mapSW","_mapNE","_widthX","_widthY","_cellWidth","_cellHeight","_lp"];
while {alive player}do{
     
    if(daytime<_finishHour||daytime>_startHour)then {
        _safeCount = 0;
        axeLampReturn=[];
        _plCellsLitVar = player getVariable ["axeCellsLit",[]];
        //hint format ["CELLSLIT:%1",_plCellsLitVar];
        sleep 0.5;
        _plCurrX = getPos vehicle player select 0;
        _plCurrY = getPos vehicle player select 1;
        _mtrxNum = 6;
        _mapSW = [0,0,0];
        _mapNE = [20000,23600,0];
        _widthX = (_mapNE select 0) - (_mapSW select 0);
        _widthY = (_mapNE select 1) - (_mapSW select 1);
        _cellWidth = _widthX / _mtrxNum;
        _cellHeight = _widthY / _mtrxNum;
 
        //GET CELL PLAYER IS IN - CHECK IF LIT ALREADY
        for "_x" from 0 to (_mtrxNum - 1) do {
            if(_plCurrX > (_mapSW select 0) + (_cellWidth * _x) && _plCurrX < (_mapSW select 0) + (_cellWidth * (_x+1)))then{
                for "_y" from 0 to (_mtrxNum - 1) do {
                    if(_plCurrY > (_mapSW select 1) + (_cellHeight * _y) && _plCurrY < (_mapSW select 1) + (_cellHeight * (_y+1)))then{
                        if(call Compile format ["%1%2",_x,_y] in _plCellsLitVar)then{
                        axeLampReturn=[];
                        //hint format ["IN CELL:%1%2 | ALREADY LIT:%3",_x,_y,_plCellsLitVar];
                        }else{
                        //Call Compile format ["_plCell = _cell%1%2",_x,_y];
                        axeLampObjects = [_x,_y,player];
                        publicVariable "axeLampObjects";
                        waitUntil {count axeLampReturn > 0};
                        Call Compile format ["_plCellsLitVar = _plCellsLitVar + [%1%2]",_x,_y];
                        //hint format ["IN CELL:%1%2 | NOT LIT :%3",_x,_y,_plCellsLitVar];
                        };
                    };
                };
            };
        };
 
        if(count axeLampReturn >0)then{
            //Illuminate
            {
            _doLight = true;
                if(_saferMode&&_safeCount%2==0)then{
                    _doLight = false;
                };
                _safeCount = _safeCount + 1;
                if(_doLight)then{
                _location = [_x select 0,_x select 1,_x select 2];
                _objLightPoint = nearestObject [_location, "#lightpoint"];
                _awayx=(_location select 0)-(getPos _objLightPoint select 0);
                _awayy=(_location select 1)-(getPos _objLightPoint select 1);
         
                    if((_awayx>_nrDist or _awayx<-_nrDist)or(_awayy>_nrDist or _awayy<-_nrDist))then{
                    _location set [1, (_x select 1) + ((0.6)*sin(_x select 3))];
                    _location set [2,_location select 2 - 0.2];
                    _location=[_location select 0, _location select 1, _location select 2];
                        if(_LocalLight)then{
                        _lp = "#lightpoint" createVehicleLocal _location;
                        }else{
                        _lp = "#lightpoint" createVehicle _location;
                        };
                    _lp setLightColor [1, 0.88, 0.73];
                    _lp setLightBrightness 0.04;
                    _lp setLightAmbient [1, 0.88, 0.73];
                    _lp setVectorUp [0,0,-1];
                    _lp setVariable ["axeLit",1];
                    //player reveal _lp;
                    //hint format ["LAMP NOT FOUND:%1 | %2 | DOLIGHT:%3 | COUNT:%4",_x,time,_doLight,_safeCount];
 
                    }else{
                        if(_objLightPoint getVariable ["axeLit",0]<1)then{
                       //sleep 0.2;
                        _objLightPoint setLightColor [1, 0.88, 0.73];
                        _objLightPoint setLightBrightness 0.04;
                        _objLightPoint setLightAmbient [1, 0.88, 0.73];
                        _objLightPoint setVectorUp [0,0,-1];
                        _objLightPoint setVariable ["axeLit",1];
                        //hint format["LAMP ALREADY FOUND | Var:%1 | DOLIGHT:%3 | COUNT:%4",_objLightPoint getVariable "axeLit",_doLight,_safeCount];
                        };
                    };
                };
     
            }forEach axeLampReturn;
        player setVariable ["axeCellsLit",_plCellsLitVar];
        };
 
    sleep 3;
    };
};
I would highly recommend packaging fnc_returnLampWS.sqf into your server files, due to the enormous amount of lights the file is going to add 209k to your mission download without. You will need to unpack days_server.pbo, copy the file into the folder structure and then repackage. I use Bin Pbo to do my packaging, Be sure to check the options and add z\addons\dayz_server to the Addon Prefix setting when packaging.

Once done you can then reference that file, from the init.sqf, using the 'serverside' path. So if you saved that file in the compile folder then you need to reference it with
Code:
axe_server_lampObjs =    compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_returnLampWS.sqf";
instead of
Code:
axe_server_lampObjs =    compile preprocessFileLineNumbers "lights\fnc_returnLampWS.sqf";
 

axeman

OpenDayZ Rockstar!
Cont...


I am going to outline some of the changes for Taviana, first the stats. There are 6570 light positions from 1,820,917 map items. Chernarus uses 1321 lights, so a big jump, which is the reason I wanted to tweak this version a bit.

The optimisation, I have set these to, what I consider, a safe level. I would rather start at something safe and then wind it up a bit if needed. To be honest the settings now give quite a nice random feel to the lights as every other position is lit. You can see this on some of the longer roads but the mapping software didn't follow roads so the lights get mixed up nicely.


Editable Setting in street_lights.sqf

_startHour / _finishHour | Pretty self explanatory, the start and finish times that you want the script to run inbetween (24hour format) Just enter the hour.

_saferMode | This forces the script to only light every other location from the array of the cell the player is in. Setting to false will light every single light point. When False I have found that it seems to create a radius, around the player, where lights are not lit outside of, at about 285m. You can see the lights coming on ! I don't know if this is something specific to the earlier version of dayZ or not. To be investigated further.

_LocalLight | Setting to true will create the light points on the players PC only, as False it sends the info., across the network, to other players. The code will check for existing lights so is designed to account for the default setting. Definitely worth a try if you think that network traffic is being effected. This is really just a precautionary measure and something to offer some more meaningful feedback if network issues do arise, which they haven't as yet.

_nrDist | Or Near Distance, as each light position is checked the script looks for a nearby light. This is to check if the new position has been lit already. I have used this to reduce bunching of lights. Taviana has a new lamp object, fluor_lamp.p3d, this is for the fluorescent lamps inside the schools and hospitals.

Without increasing this distance there is a light point for every ceiling light in the building, not good.. This could be increased much further to reduce the number of lights that are lit. If this was increased to 80 - 120 (metres) it would surely randomise the street lights more and reduce the number that are lit, another way to optimise (the fear).



That's it, I look forward to your feedback. Let me know if you are having problems getting this working or have any questions..
 
Looks great Axeman, just got it working on my server. I didn't have a lot of time to do testing but some lights didn't light up, and some of the towns didn't have lights at all. I am not sure if this was intended or not/desync. Anyway looks amazing great job!

Sorry if this is frowned upon but if anyone wants to check out lights on Taviana come check it out! 67.228.177.46:3170

**edit**
Possibly add lights to the small ground lights running down the airfields airstrips?
 

axeman

OpenDayZ Rockstar!
Some of the lights do not light up. They are in the list and can be lit. Is the 'safer mode' that forces every other light to be lit. This is due to the large amount of lights in Taviana.

I haven't noticed any of the towns not lighting up, I suspect that they will. Again, due to the large number some areas can take longer to catch up initially, I have just edited a sleep out (on line 91) is not required.
 
sorry if this is a dumb question but, if i want to pack it to my server.pbo
i would just have to place the "lights" folder in to the "compile" folder in the server.pbo and then go to my init.sqf in the mission.pbo and add in this at the buttom
if (isServer) then {
axe_server_lampObjs = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_returnLampWS.sqf";
"axeLampObjects" addPublicVariableEventHandler {_id = (_this select 1) spawn axe_server_lampObjs};
};

if (!isDedicated) then {
//StreetLights
[] execVM "lights\street_lights.sqf";
};
or did i miss something ?
 

Nonov Urbizniz

OpenDayZ Rockstar!
Staff member
I know AEG treats the runway/airfield lights totally separately, they (runway/airfield lights) are assumed to be always working. Although I believe that is more of a philosophy of the author than due to the way the game handles them.

Great work Axeman!
 
sorry if this is a dumb question but, if i want to pack it to my server.pbo
i would just have to place the "lights" folder in to the "compile" folder in the server.pbo and then go to my init.sqf in the mission.pbo and add in this at the buttom


or did i miss something ?

i think i figured out

the fnc_returnlampWS in the compile folder in the server.pbo
Streetlights in the mission.pno ? and then edit the init.sqf like this ?

if (isServer) then {
axe_server_lampObjs = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fnc_returnLampWS.sqf";
"axeLampObjects" addPublicVariableEventHandler {_id = (_this select 1) spawn axe_server_lampObjs};
};

if (!isDedicated) then {
//StreetLights
[] execVM "lights\street_lights.sqf";
};
 

axeman

OpenDayZ Rockstar!
Richardfromlost, that looks good. If the dayz_server.pbo has any issues with packaging you will see file not found etc. in your server .rpt log..
 
If you could get the little lights that actually line the airstrip to light up that would be amazing! theres bigger lights at the end that already work.
 

axeman

OpenDayZ Rockstar!
If you could get the little lights that actually line the airstrip to light up that would be amazing! theres bigger lights at the end that already work.
I was also tempted to add small lights for the reflectors on the side of the road. Already far too many lights though :) The lights, as they are, are about as dim as they go, I don't think they are really designed for subtle lighting.
 
Looks and works great on Taviana I was driving down the road and even lights along the roadside work, now if i can just get the fog working. Thanks Axe great addition here, also I put it in my server.pbo as reccomended.
 
after 2 nights of street light im a fan :D

but there is 2 minor bugs
1. if u take NVG on and then off, the street light wont appear
2. it see like that the light wont show on the west island for some players but for others it will

is there a away to fix this ?
 
I love this script but I have a few problems..

when its time for the lights to come on they didn't seam to work until I relogged
I have found that if you drive across the bridge from north to south the lights don't come on the south island? (maybe the otherway too)
it seams very hit and miss I was on the ground with lights working all around, someone landed a heli next to me but it was dark for them, until they reclogged from lobby?
 

axeman

OpenDayZ Rockstar!
How long did the second player wait until deciding that the light weren't coming on ? On the larger cells it can take a bit of time to light them all up, especially when flying in as the player is lighting cells up more quickly..
 
Top