Issue with helicopter crashes - arrays not returning correct changes

Graz

Well-Known Member
I've got a server running 3 crash types. The crashes work fine, apart from the loot. The percentage is completely off and it seems to spawn most of the first 3-4 objects listed and ignores the chance array completely!!!

I've posted the code below for each of them.
(The original code wasn't done by myself)

Yankee Crash
spawn_YankheliCrash = {
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 US Crash 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 6) + 3;
//_itemType = [] + getArray (_config >> "itemType");
//_itemChance = [] + getArray (_config >> "itemChance");
_itemType = [["M240","weapon"], ["M40A3","weapon"], ["G36a_CAMO","weapon"], ["M16A4_ACG_GL","weapon"], ["M4SPR","weapon"], ["M1014","weapon"], ["MP5A5","weapon"], ["M16A4_ACOG","weapon"], ["MP5SD","weapon"], ["M9","weapon"], ["M9SD","weapon"], ["", "trash"], ["WeaponHolder_PartGeneric", "object"], ["WeaponHolder_PartVRotor", "object"], ["ItemGPS","weapon"], ["ItemCompass", "generic"], ["ItemMap","weapon"], ["","military"], ["","medical"], ["MedBox0","object"], ["skin_Soldier1_DZ","magazine"],["Skin_Camo1_DZ","magazine"], ["Skin_Sniper1_DZ","magazine"], ["DZ_CivilBackpack_EP1","object"], ["DZ_Backpack_EP1","object"]];
_itemChance = [0.02, 0.005, 0.01, 0.02, 0.02, 0.03, 0.03, 0.03, 0.01, 0.04, 0.01, 0.15, 0.05, 0.025, 0.01, 0.02, 0.02, 0.10, 0.25, 0.05, 0.03, 0.02, 0.01, 0.04, 0.01];
//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;
};
};
};
};
Ruski Crash
spawn_RuskiheliCrash = {
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 Russian Wreck at " + str(_position));
_veh = createVehicle ["Mi8Wreck",_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 6) + 3;
//_itemType = [] + getArray (_config >> "itemType");
//_itemChance = [] + getArray (_config >> "itemChance");
_itemType = [["RPK_74","weapon"], ["SVD","weapon"], ["AK_107_GL_pso","weapon"], ["AK_107_GL_kobra","weapon"], ["AKS_74_UN_kobra","weapon"],["AK_107_pso","weapon"], ["Saiga12K","weapon"], ["Sa61_EP1","weapon"], ["G36_c_SD_eotech","weapon"], ["Makarov","weapon"], ["MakarovSD","weapon"], ["", "trash"], ["WeaponHolder_PartGeneric", "object"], ["WeaponHolder_PartVRotor", "object"], ["ItemGPS","weapon"], ["ItemCompass", "generic"], ["ItemMap","weapon"], ["","military"], ["","medical"], ["MedBox0","object"], ["skin_Soldier1_DZ","magazine"],["Skin_Camo1_DZ","magazine"], ["Skin_Sniper1_DZ","magazine"], ["DZ_CivilBackpack_EP1","object"], ["DZ_Backpack_EP1","object"]];
_itemChance = [0.02, 0.005, 0.01, 0.02, 0.02, 0.03, 0.03, 0.03, 0.01, 0.04, 0.01, 0.15, 0.05, 0.025, 0.01, 0.02, 0.02, 0.10, 0.25, 0.05, 0.03, 0.02, 0.01, 0.04, 0.01];
//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;
};
};
};
};
Pomme Crash
spawn_PomheliCrash = {
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 British Crash at " + str(_position));
_veh = createVehicle ["UralWreck",_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 6) + 3;
//_itemType = [] + getArray (_config >> "itemType");
//_itemChance = [] + getArray (_config >> "itemChance");
_itemType = [["MG36","weapon"], ["BAF_LRR_scoped","weapon"], ["BAF_L86A2_ACOG","weapon"], ["BAF_L85A2_UGL_SUSAT","weapon"], ["BAF_L85A2_UGL_Holo","weapon"],["M1014","weapon"], ["FN_FAL","weapon"], ["G36K","weapon"], ["bizon_silenced","weapon"], ["UZI_EP1","weapon"], ["UZI_SD_EP1","weapon"], ["", "trash"], ["WeaponHolder_PartGeneric", "object"], ["WeaponHolder_PartVRotor", "object"], ["ItemGPS","weapon"], ["ItemCompass", "generic"], ["ItemMap","weapon"], ["","military"], ["","medical"], ["MedBox0","object"], ["skin_Soldier1_DZ","magazine"],["Skin_Camo1_DZ","magazine"], ["Skin_Sniper1_DZ","magazine"], ["DZ_CivilBackpack_EP1","object"], ["DZ_Backpack_EP1","object"]];
_itemChance = [0.02, 0.005, 0.01, 0.02, 0.02, 0.03, 0.03, 0.03, 0.01, 0.04, 0.01, 0.15, 0.05, 0.025, 0.01, 0.02, 0.02, 0.10, 0.25, 0.05, 0.03, 0.02, 0.01, 0.04, 0.01];
//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;
};
};
};
};
[\Spoiler]

What am I missing? it feels like the chance isn't being considered when spawning the items >_<
 
Because the loot system is broken in dayz.
It doesn't select the 0.01 for nvg's or the 0.03 for the fal etc etc.

it just grabs them all and spawns anything you list, the way i suggest you do it is just add more loot or less.
Either way, the current loot spawns are not what people think they are.

You've also got people on the offical dayz code who think adding these percentages work, so it will only get worse i am afraid.
 
it just grabs them all and spawns anything you list, the way i suggest you do it is just add more loot or less.

I orginally thought this too, but it seems far more likely to spawn the first item then the last, so there is some kind of randomization at play.

For instance M240 is spawning far more then the 'trash'.

Does anyone know how dayz does it?
 
My friend killzone kid explains it here.

First of all dayz_code/compiles/fn_buildWeightedArray.sqf is the function that creates weighted array supposedly based on chances for loot items. This is how it works. If you have an array [[item1,item2,item3][0.1,0.02,0.3]] this is output from this function:
[0,0,0,0,0,0,0,0,0,0,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
Then this array is passed to pick random function and then you have your weighted loot item index.

Problem? First of all to generate this array the function iterates trough every element of the supplied array and then does another loop for each element depending on the chance. 1 means 100 iterations, 0.5 means 50 iterations etc. so it you have long array with high chances you have massive iteration going on and this is only to get just 1 loot item!!!
Second problem is the loot item picked up this way does not even adhere to the chance you indicated for this item. For example you have 2 items array [[item1,item2][0.01,0.01]] both supposedly have 1% chance to be picked up.
The output of this function in this case [0,1] means both items have 50% chance not 1%!!!

So as you can see, currently the people working on the dayzmod community side, are using this so it's broken and it needs to be changed...

More info here: https://github.com/R4Z0R49/DayZMod/issues/79
 
Awesome, I'll run try change it up now and run it for a few days.

I'm taking it's not as simple as switching fn_buildWeightedArray.sqf with fn_arrayItemsByChance.sqf in the chopper functions right?
 
Thanks for posting those, been looking for something as an example!

Has anyone managed to have zombies or smoke on these wrecks like at the Huey crashes?

Thanks.
 
Back
Top