Deconstructing spawn_Helicrash

Forgotten

Well-Known Member
I'd like to see the more experienced scripters take apart the spawn_Helicrash, if anyone has the time or inclination. I've read the FAQ Scripting Guide, and been at this stuff for the last six months, but it's all trial and error for me, mostly error.

I'm mostly looking for what specific numbers actually mean, and what we can change them to.

Here's the code inside dayz_server>init>server_functions.sqf

Code:
spawn_heliCrash = {
    private["_position","_veh","_num","_config","_itemType","_itemChance","_weights","_index","_iArray"];
   
    waitUntil{!isNil "BIS_fnc_selectRandom"};
    if (isDedicated) then {
    _position = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
    diag_log("DEBUG: Spawning a HeliCrash At " + str(_position));
    _veh = createVehicle ["UH1Wreck_DZ",_position, [], 0, "CAN_COLLIDE"];
    dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_veh];
    _veh setVariable ["ObjectID",1,true];
    dayzFire = [_veh,2,time,false,false];
    publicVariable "dayzFire";
    if (isServer) then {
        nul=dayzFire spawn BIS_Effects_Burn;
    };
    _num = round(random 2) + 3;
    _config =        configFile >> "CfgBuildingLoot" >> "HeliCrash";
    _itemType =        [] + getArray (_config >> "itemType");
    //diag_log ("DW_DEBUG: _itemType: " + str(_itemType));   
    _itemChance =    [] + getArray (_config >> "itemChance");
    //diag_log ("DW_DEBUG: _itemChance: " + str(_itemChance));   
    //diag_log ("DW_DEBUG: (isnil fnc_buildWeightedArray): " + str(isnil "fnc_buildWeightedArray"));   
   
    waituntil {!isnil "fnc_buildWeightedArray"};
   
    _weights = [];
    _weights =        [_itemType,_itemChance] call fnc_buildWeightedArray;
    //diag_log ("DW_DEBUG: _weights: " + str(_weights));   
    for "_x" from 1 to _num do {
        //create loot
        _index = _weights call BIS_fnc_selectRandom;
        sleep 1;
        if (count _itemType > _index) then {
            //diag_log ("DW_DEBUG: " + str(count (_itemType)) + " select " + str(_index));
            _iArray = _itemType select _index;
            _iArray set [2,_position];
            _iArray set [3,5];
            _iArray call spawn_loot;
            diag_log("LOOTSPAWN: " + str(_iArray) + " Spawned At A UH-1Y CrashSite");
            _nearby = _position nearObjects ["WeaponHolder",20];
            {
                _x setVariable ["permaLoot",true];
            } forEach _nearBy;
        };
    };
    };
};


I'll throw in my two cents about what I know.

First, I know that:

Code:
spawn_heliCrash

Defines the entire code afterwards, and is referenced in other dayz files, mainly in server_monitor.sqf. You can change it to reference new spawn types that you specify in the code.

Code:
//Spawn crashed helos
for "_x" from 1 to 4 do {
    _id = [] spawn spawn_heliCrash;
    //waitUntil{scriptDone _id};
};
 
//Spawn crashed Ural
for "_x" from 1 to 4 do {
    _id = [] spawn spawn_UralCrash;
    //waitUntil{scriptDone _id};
};

Anything with diag_log will write the information following it into your arma2oaserver.RPT so you can reference it.

Example:

Code:
diag_log("DEBUG: Spawning a HeliCrash At " + str(_position));

Using that line will give you a reference with a position for all of your chopper crashes.

The line below gives you a random amount plus another numeric for loot at the spawnsite.

Code:
_num = round(random 2) + 3;

This line below sets the type of loot table the spawn site will use.

Code:
 _config =        configFile >> "CfgBuildingLoot" >> "HeliCrash";

HeliCrash can be changed to "Military", "Residential", "Industrial", "MilitarySpecial", or any other type you specify or create inside the config.cpp inside dayz_code.

Below is another diag_log you can use to see what items spawn at a particular spawn site.

Code:
 diag_log("LOOTSPAWN: " + str(_iArray) + " Spawned At A UH-1Y CrashSite");


Here's an example of using different items other than wrecks, and with different loot tables.

Code:
spawn_Outpost3 = {
private["_position","_veh","_num","_config","_itemType","_itemChance","_weights","_index","_iArray"];
 
waitUntil{!isNil "BIS_fnc_selectRandom"};
if (isDedicated) then {
_position = [getMarkerPos "center",0,4000,10,0,4000,0] call BIS_fnc_findSafePos;
diag_log("DEBUG: Spawning a Outpost3 at " + str(_position));
_veh = createVehicle ["Land_fortified_nest_small",_position, [], 0, "CAN_COLLIDE"];
dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_veh];
_veh setVariable ["ObjectID",1,true];
_num = round(random 5) + 3;
_config = configFile >> "CfgBuildingLoot" >> "Military";
_itemType = [] + getArray (_config >> "itemType");
//diag_log ("DW_DEBUG: _itemType: " + str(_itemType));
_itemChance = [] + getArray (_config >> "itemChance");//diag_log ("DW_DEBUG: _itemType: " + str(_itemType));
//_itemChance = [] + getArray (_config >> "itemChance");
//diag_log ("DW_DEBUG: _itemChance: " + str(_itemChance));
//diag_log ("DW_DEBUG: (isnil fnc_buildWeightedArray): " + str(isnil "fnc_buildWeightedArray"));
 
waituntil {!isnil "fnc_buildWeightedArray"};
 
_weights = [];
_weights = [_itemType,_itemChance] call fnc_buildWeightedArray;
//diag_log ("DW_DEBUG: _weights: " + str(_weights));
for "_x" from 1 to _num do {
//create loot
_index = _weights call BIS_fnc_selectRandom;
sleep 1;
if (count _itemType > _index) then {
//diag_log ("DW_DEBUG: " + str(count (_itemType)) + " select " + str(_index));
_iArray = _itemType select _index;
_iArray set [2,_position];
_iArray set [3,5];
_iArray call spawn_loot;
_nearby = _position nearObjects ["WeaponHolder",20];
{
_x setVariable ["permaLoot",true];
} forEach _nearBy;
};
};
};
};


And that's about all I know. I want to be clear, I've used many examples from other people to set up my crashes and loot spawns, and I don't know all of who I used. I do know I followed Stapo's diag_log examples to add those so I could see where my sites were spawning.


I have some specific questions about code, and if anyone knows what any of the rest of the code is referencing or telling the server to do, I know I, personally, would love directions and examples about how to further edit.

My specific questions are as follows:


Code:
_position = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;

In this line, I am assuming it is telling it a center reference from where to randomly find a spot for the site. I have successfully changed the 2000 number to 4000 to cause further afield spawns than are normal, but any above 4k in both fields causes sites to spawn off the map. I'm interested to know exactly what the numbers are for.

I'm also looking for some way to force loot to spawn further away from the center of the loot site, so that it won't spawn underneath any models I use.

I thought maybe the following code had something to do with it:

Code:
_nearby = _position nearObjects ["WeaponHolder",20];

But after repeatedly changing it and checking sites, I've found no discernible change in the loot spawning.

Anywho, I figured this would be an interesting study in examples and expert scripter input.

Thanks for any replies!
 
Was poking around in dayz_code>config.cpp and found:

Code:
class UH1Wreck_DZ: Military {
        zombieClass[] = {"z_soldier_pilot","z_soldier_heavy"};
        zombieChance = 0;
        lootChance = 0;
        minRoaming = 4;
        maxRoaming = 8;
        lootPos[] = {};
    };

I was most interested in lootPos. This seems to indicate where loot should spawn?

Here's the entry for a deerstand:

Code:
class Land_Misc_deerstand: Military {
        zombieChance = 0;
        lootChance = 0.5;
        maxRoaming = 3;
        lootPos[] = {{-0.923828,-0.808594,1.08539},{0.419922,-0.237305,1.08539}};
    }; // Qty: 56

Will try some editing of the lootPos and see what comes of it.
 
I found out that :

Code:
lootPos[] = {{-0.923828,-0.808594,1.08539},{0.419922,-0.237305,1.08539}};

Is spots where loot will spawn in relation to the center of the model? I assume this may be usable as part of the helicrash script. Will try that too.
 
Hello, thanks for your help :)

Have a question:
What represente "2" in
Code:
dayzFire = [_veh,2,time,false,false];

then i wanted to creat a Plane Crash.

If i change : _veh = createVehicle ["UH1Wreck_DZ",_position, [], 0, "CAN_COLLIDE"];
by ! _veh = createVehicle ["C130Wreck",_position, [], 0, "CAN_COLLIDE"];

and in class UH1Wreck_DZ: Military
by class c130wreck: Military

it's worked ?

I'm on Work for now, i'll try this tonight, if you have some recommandation it will be great

Thanks
 
Creating a plane crash is actually as simple as changing the model that spawns, renaming your spawn_***Crash name to something more appropriate, and adding the new spawn line into your server_monitor file, and that's it!

Refer to my Outpost example above.
 
Just a note, the C130 is a terrible crash site, as the model, when placed on an incline, will launch players into the air. This kills or severely injures them. Near the back of the plane, players will get trapped in what almost seems to be a gravity field, with some players being unable to escape.

I believe there's some sort of flat land script floating around I saw. I have not tested that in conjunction with the C130 to see if it remedies the problem.
 
Back
Top