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
Ruski Crash
Pomme Crash
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;
};
};
};
};
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;
};
};
};
};
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;
};
};
};
};
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;
};
};
};
};
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 >_<
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 >_<