How to Make Trash/Junk Spawn Server-Side

Rick167

Member
Hey guys, it's me again with another one of my scripting dilemmas.

I was doing some reading on google when I found a github article that was a little unclear to me.

Here is the link of the article: https://github.com/DayZMod/DayZ/issues/44

Basically, I've had a couple complaints of people crashing into objects that their clients haven't yet rendered. I figured, if I made my server render the objects server-side, this would prevent the problem.

Here are the instructions that were provided in the github link I provided above:

Instead of the client streaming in the roadblocks/wrecks/junk, which sometimes causes a sudden appearance in front of a fast moving vehicle, the server streams it once upon server start, and makes it permanent. I have tested this on my server. It worked great with minimal server performance loss while giving a performance boost to clients. Credit for this goes to isathar at opendayz.net.
  1. Remove the stream code in player_monitor.fsm
  2. Remove stream_locationCheck.sqf, stream_locationFill.sqf, & stream_locationDel.sqf
  3. Create an sqf (we'll call it server_fillLocs.sqf for now) with the following code:
private ["_configBase","_tempList"];
if (isServer) then {
_tempList = ["Chernogorsk","Elektrozavodsk","Balota","Komarovo","Kamenka","Kamyshovo","Prigorodki","Kabanino","Solnichniy","StarySobor","NovySobor","SouthernAirport","NorthernAirport","Berezino","Lopatino","GreenMountain","Zelenogorsk","Nadezhdino","Kozlovka","Mogilevka","Pusta","Bor","Pulkovo","Vyshnoye","Drozhino","Pogorevka","Rogovo","Guglovo","Staroye","Pavlovo","Shakhovka","Sosnovka","Msta","Pustoshka","Dolina","Myshkino","Tulga","Vybor","Polana","Gorka","Orlovets","Grishino","Dubrovka","Nizhnoye","Gvozdno","Petrovka","Khelm","Krasnostav","Olsha"];
for "_j" from 0 to ((count _tempList) - 1) do
{
_configBase = configFile >> "CfgTownGenerator" >> (_tempList select _j);
Code:
 for "_i" from 0 to ((count _configBase) - 1) do { private ["_config","_type","_position","_dir","_onFire","_object"]; _config = (_configBase select _i); if (isClass(_config)) then { //filter: _type = getText (_config >> "type"); //if (((getText (_config >> "type")) != "Body1") and ((getText (_config >> "type")) != "Body2")) then { _position = [] + getArray (_config >> "position"); _dir = getNumber (_config >> "direction"); _onFire = getNumber (_config >> "onFire"); _object = _type createVehicle _position; _object setPos _position; _object setDir _dir; _object allowDamage false; //diag_log format["CreateObj: %1 / %2",_type,_position]; /* if (_onFire > 0) then { nul=[_object,_onFire,time,false,false] spawn BIS_Effects_Burn; }; */ //}; }; //sleep 0.1; // for longer load, but better startup performance }; sleep 0.5; //comment the other sleep and uncomment this for faster load but slower startup performance diag_log ("Creating Objects: " + str(_configBase)); };
};
  1. Add it it to server_functions.sqf
Code:
server_fillLocs = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_fillLocs.sqf";
  1. Add it to server_monitor.sqf
Code:
_id = [] spawn server_fillLocs;

I was able to locate the player_monitor.fsm file, but was unable to figure out exactly what needed to be deleted.

I was able to locate the three "stream" files in DayZCode mentioned above. I can delete those and reupload the DayZCode file no problem.

Finally, I am able to create the new SQF file, and make the changes to server_functions.sqf and server_monitor.sqf.

My two questions are:

1. Wouldn't modifying the DayZ_Code files require my clients to have the same exact version... I.E. requiring them to download something in order to play in our server?

2. What exactly am I supposed to change in the player_monitor? I see a few things referring to streaming, but I can't be sure what to take out.

Also, if someone has another way of doing this, I'm completely open to that, especially if the answer to my first question is yes, and your solution won't require clients having to download our version.

As always, thank you in advance for all helpful and productive comments and any assistance that you may be able to give.

- Rick
 
If you edit anything in the dayz code, anyone playing on your server will have to download that to play there
 
Ouch.. Alright, so let's scratch that idea. Is there any way to force the server to render these objects rather than relying on the client and hoping that their client does it in time?
 
I havent looked through all of the dayz code yet but I think somewhere in there it defines everything as wrecks and their locations because its not random, they are in a set position on every server, now if you found that file and if it exists you can easily copy it over and execute it server side and disable it client side, not sure how to do it otherwise or what you edit etc

Also this method would spawn wrecks in server side with no loading when a player goes near, its there all the time for everyone. If you find that file let me know and Ill help you out, if you cant find it ill look later in the day for it
 
I'm not sure if this can get you in the right direction, but I know the file "stream_locationCheck.sqf" has something to do with the rendering of the items.

I read in another post that if you enter
Code:
stream_locationCheck = {

then all the items won't spawn. The problem here is that it also despawns tents like the ones in Stary, Balota, etc.

Here is my stream_locationCheck.sqf file's contents:

Code:
private ["_location", "_distCfg","_configClass","_distAct","_rubbish","_config","_locHdr","_position","_w8", "_ahead" ];
_w8 = _this select 0;
//diag_log "running location check...";
_rubbish = dayz_Trash == 1;
{
    _location = _x select 0;
    _distCfg = (_x select 2);
    _configClass = _x select 1;
    _distAct = player distance _location;
    _ahead = (speed player) / 3.6 * 6;

    if (!(_forEachIndex in dayz_locationsActive)) then {
        if ((_distAct < _distCfg + dayz_spawnArea + _ahead) and _rubbish) then {
            dayz_locationsActive set [count dayz_locationsActive,_forEachIndex];
            _config = configFile >> "CfgTownGeneratorChernarus" >> _configClass;
            _locHdr = configName _config;
            //if (typeName _locHdr != "STRING") then { _locHdr = str _location; };
            diag_log format ["%1: creating %2 objects at '%3'", __FILE__, count _config, _locHdr];
            [_config, _w8] call stream_locationFill; // create wrecks & rubbish as local objects
        };
    } else {
        if (_distAct > _distCfg + dayz_canDelete + _ahead) then {
            _config = configFile >> "CfgTownGeneratorChernarus" >> _configClass;
            _locHdr = configName _config;
            //if (typeName _locHdr != "STRING") then { _locHdr = str _location; };
            diag_log format ["%1: removing %2 objects from '%3'", __FILE__, count _config, _locHdr];
            [_config, _w8] call stream_locationDel; // delete wrecks & rubbish
            dayz_locationsActive = dayz_locationsActive - [_forEachIndex];
        };
    };
} forEach dayz_Locations;

I hope something in that might set you in the right direction. It's all gobbledegook to me.
 
I'm still no expert, but I'm starting to get down the right track I think...

If I'm understanding what you're saying, then I have to have the CfgTownGeneratorDefault.hpp file in my mission PBO, along with a modified version of dayz_code/config.cpp (the file that calls on CfgTownGeneratorDefault.hpp).

But wait.. I can't have a custom config.cpp, can I? Er.. If that's the case, how will this work? Welp, now I'm rendered useless. lol

Appreciate the help. I am learning, just.. slowly!

EDIT: I think I may have though of a way around the config.cpp thing... I was falling asleep and realized I could call the CfgTownGeneratorDefault.hpp through my description.ext, couldn't I?
 
I used this from the perma loot system that was posted a while back. Here is how you do it.

CREATE:
Place in server\compile folder.

server_fillLocs.sqf
Code:
private ["_configBase","_tempList","_id"];
 
if (isServer) then {
    _tempList = ["Chernogorsk","Elektrozavodsk","Balota","Komarovo","Kamenka","Kamyshovo","Prigorodki","Kabanino","Solnichniy","StarySobor","NovySobor","SouthernAirport","NorthernAirport","Berezino","Lopatino","GreenMountain","Zelenogorsk","Nadezhdino","Kozlovka","Mogilevka","Pusta","Bor","Pulkovo","Vyshnoye","Drozhino","Pogorevka","Rogovo","Guglovo","Staroye","Pavlovo","Shakhovka","Sosnovka","Msta","Pustoshka","Dolina","Myshkino","Tulga","Vybor","Polana","Gorka","Orlovets","Grishino","Dubrovka","Nizhnoye","Gvozdno","Petrovka","Khelm","Krasnostav","Olsha"];
    for "_j" from 0 to ((count _tempList) - 1) do
    {
        _configBase = configFile >> "CfgTownGenerator" >> (_tempList select _j);
 
        for "_i" from 0 to ((count _configBase) - 1) do
        {
            private ["_config","_type","_position","_dir","_onFire","_object"];
       
            _config =    (_configBase select _i);
            if (isClass(_config)) then {
                _type =    getText    (_config >> "type");
                if (((getText (_config >> "type")) != "Body1") and ((getText (_config >> "type")) != "Body2") and ((getText (_config >> "type")) != "Mass_grave")) then {
                    _position = [] + getArray    (_config >> "position");
                    _dir =        getNumber    (_config >> "direction");
                    _onFire =    getNumber    (_config >> "onFire");
               
                    _object = _type createVehicle _position;
                    _object setPos _position;
                    _object setDir _dir;
                    _object allowDamage true;
                };
            };
        };
        sleep 0.2;
        diag_log ("Create Objects: " + str(_configBase));
    };
};



server_functions.sqf
ADD:
To the list of compile preprocess.
Code:
server_fillLocs            = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_fillLocs.sqf";


server_monitor.sqf
FIND:
Code:
allowConnection = true;

ADD UNDERNEATH:
Code:
// Server Fill All Locations
if (isServer) then {
_fillLocs = [] spawn server_fillLocs;
};


Now this spawns them in, however, after some time the server will delete the objects. Places like balota med tents disappear. There is a work around to this problem but I will have to look at it when I get home from work.

Hope this helps.
 
Back
Top