-Working- Loot Spawning While in Vehicle, and adjust loot spawning distances!

spaces.are.evil

New Member
Ok folks, I have been meaning to get this out to the world for a while, but now just found time. If you haven't discovered this already, it is a very easy modification. However, this will cause a greater amount of stress(lag) on the server with how fast some vehicles can travel.

Some assumptions:
  • You have a dayz_code folder in your mission pbo
  • You have a copy of compiles.sqf inside your dayz_code folder (most likely in the init folder)
  • You know where the dayz_code.pbo file is located on your personal machine, and can open said file to access a file within.
Open your dayz_code.pbo, open the compile folder, and take a copy of player_spawnCheck.sqf.
Inside of your mission file's dayz_code folder, create a folder called compile. Place player_spawnCheck.sqf inside compile folder.
Alternative: Create a file called player_spawnCheck.sqf inside your dayz_code folder, in a folder called compile: https://github.com/UnclearWall/DayZ...@dayz/dayz_code/compile/player_spawnCheck.sqf
(note: i am unsure if this file changes across different maps/mods)
The pathway of this file should be: dayz_code\compile\player_spawnCheck.sqf
Open your compiles.sqf (dayz_code\init\compiles.sqf in your mission pbo)
Around line 23 should be this line:
Code:
player_spawnCheck =        compile preprocessFileLineNumbers "z\addons\dayz_code\compile\player_spawnCheck.sqf";

Replace that line with this code:

Code:
    //player_spawnCheck =        compile preprocessFileLineNumbers "z\addons\dayz_code\compile\player_spawnCheck.sqf";
    player_spawnCheck =        compile preprocessFileLineNumbers "dayz_code\compile\player_spawnCheck.sqf";

Now, open your player_spawnCheck.sqf file (dayz_code\compile\player_spawnCheck.sqf)

Around line 120, you will see this code:

Code:
    //Loot
    if ((_dis < 120) and (_dis > 30) and _canLoot and !_inVehicle) then {
        _looted = (_x getVariable ["looted",-0.1]);
        _cleared = (_x getVariable ["cleared",true]);
        _dateNow = (DateToNumber date);
        _age = (_dateNow - _looted) * 525948;
        //diag_log ("SPAWN LOOT: " + _type + " Building is " + str(_age) + " old" );
        if ((_age > 10) and (!_cleared)) then {
            _nearByObj = nearestObjects [(getPosATL _x), ["WeaponHolder","WeaponHolderBase"],((sizeOf _type)+5)];
            {deleteVehicle _x} forEach _nearByObj;
            _x setVariable ["cleared",true,true];
            _x setVariable ["looted",_dateNow,true];
        };
        if ((_age > 10) and (_cleared)) then {
            //Register
            _x setVariable ["looted",_dateNow,true];
            //cleanup
            _handle = [_x] spawn building_spawnLoot;
            waitUntil{scriptDone _handle};
        };
    };

On the if statement line, remove !_inVehicle. The line should now read as so

Code:
    if ((_dis < 120) and (_dis > 30) and _canLoot) then {

That has allowed for loot to spawn while players are still in vehicles.

Loot Spawning Distances

Now, notice the (_dis < 120) and (_dis > 30) .

(_dis < 120) = Distance to start spawning loot (within 120 meters)
(_dis > 30) = Distance to stop spawning loot (within 30 meters)

You can change this as you want, but a few warnings:

  • Making the distance to start spawning larger will increase lag
  • If the distance between the start and stop point is too narrow, loot might not have enough of a chance to spawn in (currently the distance between start and stop is 90 meters).

Save, repack, enjoy! Let me know of any issues with this and I will try my best to help.
One last thought:
On the line of the if statement where you remove !_inVehicle. I wonder if you could check to see if those vehicles are helicopters or other faster moving vehicles to cut down on the amount of lag generated by this change.
 
For 1.7.7.1 Chernarus users : The line looks like this
Code:
    //Loot
    if (_currentWeaponHolders < _maxWeaponHolders) then {
        if ((_dis < 120) and (_dis > dayz_safeDistPlr) and _canLoot and !_inVehicle and _checkLoot) then {
            _looted = (_x getVariable ["looted",-0.1]);
            _dateNow = (DateToNumber date);
            _age = (_dateNow - _looted) * 525948;
            //diag_log ("SPAWN LOOT: " + _type + " Building is " + str(_age) + " old" );
            if (_age < -0.1) then {
                    _x setVariable ["looted",(DateToNumber date),!_islocal];
            } else {
                if (_age > dayz_tagDelayWeaponHolders) then {
                    _x setVariable ["looted",_dateNow,!_islocal];
                    _qty = _x call building_spawnLoot;
                    _currentWeaponHolders = _currentWeaponHolders + _qty;
                };
            };
        };
    };

and you MUST grab it from the dayz_code.pbo
 
Back
Top