Want to make all loot spawn like heli crash sites--once and permanent

Are any of the log entries for the object spawns showing up? After the heli wrecks you should be seeing "Create Objects: bin\config.bin/CfgTownGenerator/(CityName)" for each city in your RPT. If those are showing up, uncomment "//diag_log ("LOOTSPAWN");" in server_spawnLoot.sqf and you should be seeing a bunch of entries after the towns' objects are spawned that say "LOOTSPAWN".
Maybe this way we can trace the issue to its source.

The default loot spawning code should be removed so that shouldn't be an issue (should have probably mentioned that one, too).
 
No. I did see those yesterday (one for each city--no loot, though), but not today with the new instructions.
 
I'm not sure if it's what's wrong with loot spawning, but the only differences between my files and what I posted are:
In server_PermaLootInit change [_x] call server_spawnLoot; to _x call server_spawnLoot; and
In server_spawnLoot change _obj = _this select 0; to _obj = _this;

I haven't changed anything about the fillLocs script since I posted it, so I'm not sure what's stopping it from executing.
 
Well, I tried changing those two, but had no success. What about where the instructions say "If you want to only spawn specific objects or stop some from spawning, take a look at the commented if statement"? Does something have to be changed by me? I haven't touched anything on server_fillLocs.sqf--just left it stock (same with everything).
 
I don't think that would have anything to do with it. The commented out part can be used to stop certain objects (like bodies and other smaller stuff) from spawning, it should work without it.

I'm not sure what else to try... Some ideas:

How long are you waiting for things to spawn when you load up? By default (with sleep 0.1 between each object spawn) it can take a while to spawn all the city objects, perhaps try it without that sleep command and the other sleep command uncommented (the 0.5 second one between cities).
Is there anything in your rpt about any of the scripts failing to execute? It could be a simple typo on my part.
Try adding a diag_log to the beginning of server_fillLocs and server_permaLootInit to see if they're being called at all.
If all else fails (and you're willing to spend more time on it), try placing diag_logs all over to establish the breaking point.
 
Thanks for the suggestions. I will definitely keep trying until I get it! Without this, my vision is ruined!
 
I finally found success! I couldn't get it to work using isathar's exact method, so I simply used two of his files, and emulated how heli crash loot is spawned. When I went into the game, it paused on the loading screen for around 10 seconds, and that was it! I'm not sure if it was so quick because my server is on a RAMdisk or what, but it was barely noticeable.

Directions to spawn all non-crash site (regular) loot once upon server start, and not respawn again until the next server start (most of this is thanks to isathar's effort):

1. Add at very bottom of dayz_server\system\server_monitor.sqf
Code:
_id = [] spawn server_permaLootInit;




2. Add in dayz_server\init\server_functions.sqf in between "spawn_heliCrash = {" and "server_getDiff ="
Code:
server_permaLootInit = {
    private["_center","_allBldngs","_type","_config","_canLoot","_cleared"];
 
    if (isServer) then {
        _center = getMarkerPos "center";
        _allBldngs = _center nearObjects ["building",8500]; // (root(225000) / 2) + 1000 should get everything in Chernarus
 
        {
            _type = typeOf _x;
            _config = configFile >> "CfgBuildingLoot" >> _type;
            _canLoot = isClass (_config);
            _cleared = (_x getVariable ["cleared",true]);
     
            if (_canLoot) then {
                if (isNil("_cleared")) then {
                    _x setVariable ["cleared",true,true];
                    _cleared = true
                };
                 
                if (_cleared) then {
                    _x call server_spawnPermaLoot;
                    _x setVariable ["cleared",false,true];
                };
            };
        } forEach _allBldngs;
    };
};




3. Add in dayz_code\init\compiles.sqf under "spawn_loot =" (line 398)
Code:
    server_spawnPermaLoot =    compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\server_spawnPermaLoot.sqf";




4. Add as a new file called "server_spawnPermaLoot.sqf" in dayz_code\compile
Code:
private["_positions","_iArray","_iPos","_item","_obj","_type","_nearBy","_itemType","_itemChance","_lootChance","_weights","_index"];
_obj =            _this;
 
_type =        typeOf _obj;
_config =        configFile >> "CfgBuildingLoot" >> _type;
 
_positions =    [] + getArray (_config >> "lootPos");
_lootChance =    getNumber (_config >> "lootChance");
_itemType =        [] + getArray (_config >> "itemType");
_itemChance =    [] + getArray (_config >> "itemChance");
 
{
    _iPos = _obj modelToWorld _x;
    _rnd = random 1;
    //Place something at each position
    if (player distance _iPos > 5) then {
        if (_rnd < _lootChance) then {
            _nearBy = nearestObjects [_iPos, ["WeaponHolder","WeaponHolderBase"],1];
            if (count _nearBy == 0) then {
                _weights = [_itemType,_itemChance] call fnc_buildWeightedArray;
                _index = _weights call BIS_fnc_selectRandom;
                if (_index >= 0) then {
                    _iArray = +(_itemType select _index);
                    _iArray set [2,_iPos];
                    _iArray set [3,0];
                    _iArray call spawn_loot;
                    _iArray = [];
                //diag_log ("LOOTSPAWN");
                };
                _item setVariable ["created",(DateToNumber date),true];
                _item setVariable ["permaloot",true,true];
            };
        };
    };
} forEach _positions;




5. Like isathar said, I don't know if this is necessary, but I commented this out in dayz_code\system\building_monitor.sqf
Code:
//{deleteVehicle _x;} forEach _items;




If you try this, I would like to hear how it works for you.
 
Here's what I'm currently running for this:

server_monitor.sqf:
add "_id = [] spawn server_fillLocs;"

If you want the clutter to spawn at once, you'll have to override either stream_locationCheck to not call stream_locationFill or change stream_locationFill to not spawn objects, both in dayz_code/compile.

If you don't want all the clutter spawned at once (may have a performance impact, but I haven't noticed it), replace the above line with:
"_id = [] call server_permaLootInit;"

server_functions.sqf:
add
PHP:
server_spawnLoot =            compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_spawnLoot.sqf";
server_permaLootInit =        compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_PermaLootInit.sqf";
server_fillLocs =            compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_FillLocs.sqf";

Create the following files and add them to dayz_server\compile:

server_spawnLoot.sqf:
PHP:
private["_obj","_type","_config","_positions","_iArray","_iPos","_item","_nearBy","_itemType","_itemChance","_lootChance","_weights","_index"];
 
_obj =            _this;
_type =        typeOf _obj;
_config =        configFile >> "CfgBuildingLoot" >> _type;
_positions =    [] + getArray (_config >> "lootPos");
_lootChance =    getNumber (_config >> "lootChance");
_itemType =        [] + getArray (_config >> "itemType");
_itemChance =    [] + getArray (_config >> "itemChance");   
 
_obj setVariable ["spawnedZeds", false, true];
//diag_log (format[("Owner of building : %1"), owner _obj]);
{
    _iPos = _obj modelToWorld _x;
    //Place something at each position
    if (player distance _iPos > 5) then {
        if (random 1 < _lootChance) then {
            _nearBy = nearestObjects [_iPos, ["WeaponHolder","WeaponHolderBase"],1];
            if (count _nearBy == 0) then {
                _weights = [_itemType,_itemChance] call fnc_buildWeightedArray;
                _index = _weights call BIS_fnc_selectRandom;
                if (_index >= 0) then {
                    _iArray = +(_itemType select _index);
                    _iArray set [2,_iPos];
                    _iArray set [3,0];
                    _iArray call spawn_loot;
                    _iArray = [];
                //diag_log ("LOOTSPAWN");
                };
               
                //_item setVariable ["created",(DateToNumber date),true];
                //_item setVariable ["permaloot",true,true];
            };
        };
    };
} forEach _positions;

server_PermaLootInit:
PHP:
private["_center","_allBldngs","_type","_config","_canLoot"];
 
if (isServer) then {
    diag_log ("Started Spawning Loot...");
   
    _center = getMarkerPos "center";
    _allBldngs = _center nearObjects ["building",25000];
   
    {
        _type = typeOf _x;
        _config = configFile >> "CfgBuildingLoot" >> _type;
        _canLoot = isClass (_config);
       
        if (_canLoot) then {
            _x call server_spawnLoot;
        };
    } forEach _allBldngs;
   
    diag_log ("Finished Spawning Loot...");
};

server_FillLocs.sqf:
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);
 
        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");
                //filter:
                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;
                   
                    //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;
                };
            };
        };
        sleep 0.2;
        diag_log ("Create Objects: " + str(_configBase));
    };
    _id = [] call server_permaLootInit;
};
 
I can't edit my post to add this, but you will also need to remove this from the server_monitor.fsm:

Code:
{
    if (local _x) then {
        _keep = _x getVariable ["permaLoot",false];
                _nearby = {isPlayer _x} count (_x nearEntities [["CAManBase"], 100]);
        if ( (!_keep) && (_nearby==0) ) then {
            deleteVehicle _x;
            _delQty = _delQty + 1;
        };
    };
} forEach _missionObjs;
 
Sorry to make this a third post, but I forgot to mention the code in the last post is in the Cleanup Objects state.
 
Thanks. Loot is spawning with this code.

What do you mean by clutter at the top of your post?


Also, it seems that if a player is spawning in an area where loot should be (ie ATC tower) No loot spawns. Is this part of the Location check??
 
Nvm. I just commented out

stream_locationCheck.sqf
Code:
//_config call stream_locationFill;

I think that is what you meant above.
 
Is there anyway to make it so all loot spawns in all loot locations? right now some buildings have loot others dont. I want loot in every building in each of the loot spawn locations inside the building.
 
Have you tried editing the .hpp files?

Cuz they lsit things like zombie counts, loot chance (i believe it means a chance for it to spawn something or be empty) and a few other things. Take a look (same file as the loot table)
 
I tried that after this post. It worked. However, loot is not spawning as I want it. The server seems to be handling the loot, however, I want the loot to spawn in every building in chernarus at server start.

As it stands now, loot is still spawning as you enter the towns. Ideas?
 
Ok, so I guess I missed one thing. On page 1, it is mentioned to remove loot spawning from dayz_code. Which files are needed to be bypassed in order to make sure only the server is spawning loot?
 
@TorturedChunk: player_spawnCheck handles regular loot spawning. See my github.

You can just add it as a mission override and comment out the loot spawn stuff
 
Back
Top