dayZ Street Lights

axeman

OpenDayZ Rockstar!
dayz_street_lights_axeman.jpg


>> FOLLOW THIS POST FOR CHERNARUS <<​
>> FOR CELLE EDITS: HERE <<​
>> TAVIANA STREET LIGHTS HERE<<​

Here it is, working street lights for Chernarus:

init.sqf (add these lines):
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 new folder called lights and add the following two files. This is all basic mission editing and there are plenty of threads covering this area, please go and try the dayZ House Lights or one of the other great addons here or in dayZ Scripting Discussions or search / browse before asking basic mission editing questions here. Will answer any queries but trying to keep the thread as clean as possible, ta :cool:

lights\fnc_returnLampWS.sqf: Download Rar File (Too big for posting)

lights\street_lights.sqf
Code:
//dayZ Street Lights from axeman - [email protected]
waitUntil {!isNull player};
//waitUntil {time > 30};
private ["_plCellsLitVar","_1stPos""_cellGen","_objLightPoint","_lightposX","_lightposY","_xpos","_ypos","_awayx","_awayy","_location","_plCurrX","_plCurrY","_nLampObject"];
_plCellsLitVar=[];
 
private["_mtrxNum","_mapSW","_mapNE","_widthX","_widthY","_cellWidth","_cellHeight"];
while {alive player}do{
axeLampReturn=[];
    if(daytime<6||daytime>17)then {
        _plCellsLitVar = player getVariable ["axeCellsLit",[]];
        //hint format ["CELLSLIT:%1",_plCellsLitVar];
        sleep 0.2;
        _plCurrX = getPos vehicle player select 0;
        _plCurrY = getPos vehicle player select 1;
        _mtrxNum = 6;
        _mapSW = [484,1546,0];
        _mapNE = [14323,13556,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];
                        };
                    sleep 1;
                    };
                };
            };
        };
 
        if(count axeLampReturn >0)then{
            //Illuminate
            {
            _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>1 or _awayx<-1)or(_awayy>1 or _awayy<-1))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];
                _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];
                player reveal _lp;
                //hint format ["LAMP NOT FOUND:%1 | %2",_x,time];
                sleep 0.2;
                }else{
                //hint format["LAMP ALREADY FOUND | Var:%1",_objLightPoint getVariable "axeLit"];
                    if(_objLightPoint getVariable ["axeLit",0]<1)then{
                    _objLightPoint setLightColor [1, 0.88, 0.73];
                    _objLightPoint setLightBrightness 0.04;
                    _objLightPoint setLightAmbient [1, 0.88, 0.73];
                    _objLightPoint setVectorUp [0,0,-1];
                    };
                sleep 0.2;
                };
 
            }forEach axeLampReturn;
        player setVariable ["axeCellsLit",_plCellsLitVar];
        };
 
    sleep 3;
    };
};

Battleye: (script restriction #20 )
Add
Code:
!"#lightpoint createVehicle _location;" !"#lightpoint createVehicleLocal _location;"
to the line starting with
Code:
5 createVehicle
Should be line number 22.


That's It ! (Go load it up) The rest is info.

Essentially the server holds a 6x6 grid array, of Chernarus, including all the locations of streetlamps on the server (there are some not included i.e. the telegraph poles with the lamp on top - these can be added).

Once the survivor enters the cell the script calls the server for the cell worldspaces and the client lights them up for just that cell.. New clients do not need to recreate the 'vehicle', that the #lightpoint' is made with, but do light up an existing one.. Was working on reducing this as other clients will see existing lights but will still set the brightness etc. (you may see a light blink)..

Changes: I have had previous issues which, I think, have been resolved with this newer version. My test code was recently deliberately used (and sold) without my permission so I feel I should just get this out there.. Just goes to show, not everyone is good to their word.

Additions: I really wanted to incorporate Personal Generators into this and merge it with my dayZ House Lights script amongst other ideas I have been toying with on my servers. Such as light failures, only working in some areas randomly, thunder storms knocking out lights, flickering lighting to add to the atmosfear etc.

dayz_street_lights_the_freezer.jpg


There is a separate piece of code (Not Included) that runs once on the server to create the 'map' of all the streetlights. Basically, the streetlamps are, what I call, map items. They can only be seen by the server and even then can not be accessed using the normal nearestObjects until they have been parsed from all the other stuff on the map..

I did try sending the surrounding worldspaces, to the survivor, in real time from the server. Over a 50m radius was causing yellow chains (due to the amount of items) with me on my localhost server / gaming pc (is quite powerful). Which is why I went down the 'mapping / grid' route..

It took the program around 6 hours to parse 1321 'lampa' items from 3,031,789 chernarus 'map items', on my local test server, to build the streetlight position array (in the downloadable sqf). I can run this against other maps and easily apply the coords to them.

I have been playing with this concept and picking it up every other weekend and tweaking and changing, trying different methods, determined to beat it. I would have preferred to have released this when I was ready ! Am happy this will work ok, just not got the chance to test it on a big LAN server.

:D

The fnc_returnLampWS.sqf can be packaged into the server files as the communication between that and the main street_lights.sqf is done with public variables, more importantly public server variables and public client variables (to reduce network traffic). This also has the advantage of reducing the download size of your mission file.. (This is how I have tested it)

Here it is, hope you get it going and am quietly confident that it will run sweet :D

Gameplay: From a gameplay point of view, it really adds to the playability at night. I have changed my server times so is 6 hours over dusk. Industrial areas and train stations are now easy to navigate in the dark, there are pointers when starting on the coast (the motorways / highways being lit). Yet you still get plenty of dark and scary moments, the lit areas add to the suspense as, when un-tooled up, you end up running back into the dark being chased by zombies.. There is no reason to not add a bit of lighting, with full moon nights (Set your date to static in the hiveext.ini) it is a winning combination..

Zombies in the day is fun, at night it is scary again...

dayZ Street Lights

 
It took the program around 6 hours to parse 1321 'lampa' items from 3,031,789 chernarus 'map items', on my local test server, to build the streetlight position array (in the downloadable sqf). I can run this against other maps and easily apply the coords to them.

WRfAdNp.gif





Simply epic...
 
AXEMAN, you win many internet points.

What would I be be able to do to help make this available for a map like Celle?

I understand that you had to run something for 6 hours - I'd be willing to do that myself if necessary but have no idea how.

Also - Where do we put the returnLamp in the server file?
 
AXEMAN, you win many internet points.

What would I be be able to do to help make this available for a map like Celle?

I understand that you had to run something for 6 hours - I'd be willing to do that myself if necessary but have no idea how.

Also - Where do we put the returnLamp in the server file?
Both files go in a new lights directory in your MPMissions folder (mission pbo), as is referenced from the init.sqf.

As mentioned at the end, the downloaded file, which is called from the isServer section (in init.sqf), can be placed in the dayz_Server.pbo. If you know how to do this then great, if not, just stick it in the mission folder and use the paths provided..

I would need to install Celle to be able to run the code..
 
Ideally I'd like to insert it in the server.pbo, my mission pbo is already extremely huge. Whatever it is that you are running in order to get the requirement information for the various maps, would it be possible for me to run said thing, I've got all the maps, i'd be willing to just let it run all day doing them for you and everyone else.
 
Ideally I'd like to insert it in the server.pbo, my mission pbo is already extremely huge. Whatever it is that you are running in order to get the requirement information for the various maps, would it be possible for me to run said thing, I've got all the maps, i'd be willing to just let it run all day doing them for you and everyone else.
I run it once to create the array that is in the current downloadable file, look at it, it is a list of worldspace arrays. Once that is done, lightpoints, for that map, are recorded. Technically this could be run against other map items, but that is another story. Though, I would like to add the lights at the top of the telegraph poles, so long as I can easily parse them from the 'map'..

I definitely would not recommend using some of my earlier code where the client was asking the server for updates based on the client position and on a schedule of every few seconds, there are A LOT of objects / items that need to be parsed, with just me on my local gaming PC, I was getting lag, on 127.0.0.1 the server was lagging. Albeit in Chernogorsk with a 500m scan radius, still too much, times that by 50, goodbye server. Is an early version of the code that the 'mapping code' came from ultimately..
 
gz for release, pity you were kindof forced into an early release.

interesting design you use there with the server holding the lightsarray, i like the approach and the thoughts about bandwidth/performance.

cheers

Sarge
 
Simply amazing! Please keep us posted if you run this against the other maps. My vote is for Panthera next!!

Axeman for president. :D
 
Top work Axeman... nice to see it released by someone that actually knows how it works and not thieves that just release working alpha copies and "at a price"... obvious here that you actually know what your doing:)
Having tested a lot of Axemans scripts I can highly recommend him to others that may have projects in mind...
See you at the LAN in Bedford this weekend!
 
gz for release, pity you were kindof forced into an early release.

interesting design you use there with the server holding the lightsarray, i like the approach and the thoughts about bandwidth/performance.

cheers

Sarge
I tried all ways to get the streetlight objects, they just aren't available, as CfgNonAIVehicles, from the client. Even at server level is not straight forward grabbing the object to get a worldspace.

Is not the most elegant way of doing things but it works. Without changing the classes, which requires a mod from what I understand, I really can't see another way of doing it..

Spent ages trying different methods and tracking down the streetlamp objects, was very much 1 step forward created 3 steps back. I do like how well the cells work though, by the time you are near a streetlight they are lit for the whole area. There are a couple of sleeps that could probably be removed to speed it up. Took this from the test server and commented out my hints..
 
I don't want to sound demanding, this is more of a casual request - when will you be doing the other maps?

Street lights in combination with high density fog and some colour correction.... especially with the other ideas you had in mind like flickering and such... oh god the eerie effect, time to find out how to have it 24/7 night for the future releases of this.
 
I don't want to sound demanding, this is more of a casual request - when will you be doing the other maps?

Street lights in combination with high density fog and some colour correction.... especially with the other ideas you had in mind like flickering and such... oh god the eerie effect, time to find out how to have it 24/7 night for the future releases of this.
The permanent nights can be done by setting Time to Type=Static and the hour to something like 19 in hiveext.ini (No Offset).

I have also set my date to static as this is supposed to create permanent moonlight, it does seem like there is a lot more at least, I haven't been on all night to check.. So long as the server is set to restart every so many hours time will get reset each restart.

I like having a bit of light and dusk so there is a bit of both, as people seem to prefer being able to see. Have gone as far as to edit the config file at restart, using my scheduler, so that GMT+x is correct, that way the time is always about right in dayZ Commander..
 
I cannot edit the hiveext.ini unfortunately, i'm with DayZ.st

I like dusk and dawn personally with bright moonlight and clear skies, it looks really nice, middle of the night, not so much and day 24/7 is really boring
 
Great work axeman, i appreciate the work you have put in here and with the house lighting too, very good of you to share your hard work with us all :)
 
script restriction #20 ??

I had to add this to the scripts.txt line starting with 5 createVehicle
!"#lightpoint" createVehicle _location;"
 
script restriction #20 ??

I had to add this to the scripts.txt line starting with 5 createVehicle
!"#lightpoint" createVehicle _location;"

Thanks, will add to the top, is the same scripts restrictions as the house lights..
 
Back
Top