2016-04-08 20:21:46 +00:00
/*
Author: Aaron Clark - EpochMod.com
2015-09-17 16:31:04 +00:00
2016-04-08 20:21:46 +00:00
Contributors:
2015-09-17 16:31:04 +00:00
2016-04-08 20:21:46 +00:00
Description:
Uses Epoch server extension to perform various functions like: kick, ban, shutdown, message, unlock/lock
2015-09-17 16:31:04 +00:00
2016-04-08 20:21:46 +00:00
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
2015-09-17 16:31:04 +00:00
2016-04-08 20:21:46 +00:00
Github:
2016-06-13 16:54:19 +00:00
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_server/EPOCH_serverLootObject.sqf
2016-04-08 20:21:46 +00:00
*/
2017-05-01 14:07:41 +00:00
//[[[cog import generate_private_arrays ]]]
private ["_config","_debug","_exit","_loop","_lootItemArray","_lootItemWeightedArray","_lootTable","_lootTableClass","_lootTableIndex","_loots","_magazineSize","_mags","_maxLoot","_maxPayout","_minLoot","_pricingConfig","_quan","_randomItem","_randomItemArray","_randomizeMagazineAmmoCount","_weightedItemArray"];
//[[[end]]]
params ["_object","_type",["_forceSpawn",false],["_pos",[]] ];
2016-04-08 20:21:46 +00:00
_debug = true;
_pricingConfig = 'CfgPricing' call EPOCH_returnConfig;
2017-04-02 04:17:46 +00:00
_lootTableIndex = if (EPOCH_modCUPVehiclesEnabled) then {if (EPOCH_mod_madArma_Enabled) then {3} else {1}} else {if (EPOCH_mod_madArma_Enabled) then {2} else {0}};
_lootTableClass = ["CfgLootTable","CfgLootTable_CUP","CfgLootTable_MAD","CfgLootTable_MADCUP"] select _lootTableIndex;
2017-04-05 16:10:28 +00:00
if !(EPOCH_forcedLootSpawnTable isEqualTo "") then {
_lootTableClass = EPOCH_forcedLootSpawnTable;
};
2016-04-08 20:21:46 +00:00
_randomizeMagazineAmmoCount = ["CfgEpochClient", "randomizeMagazineAmmoCount", true] call EPOCH_fnc_returnConfigEntryV2;
2017-04-23 16:52:36 +00:00
if (isnull _object && !(_pos isequalto [])) then {
_object = createVehicle ["groundWeaponHolder",_pos,[],0,"CAN_COLLIDE"];
};
2016-04-08 20:21:46 +00:00
if !(isNull _object) then{
2017-08-30 22:00:06 +00:00
_lootTable = ["CfgMainTable", _type, "tables"] call EPOCH_fnc_weightedArray;
2017-10-10 15:49:00 +00:00
if !(_lootTable isEqualTo []) then {
2015-09-17 16:31:04 +00:00
_loots = [];
_config = configFile >> "CfgMainTable" >> _type;
_minLoot = getNumber(_config >> "lootMin");
_maxLoot = getNumber(_config >> "lootMax");
_maxPayout = ((random(_maxLoot) * EPOCH_lootMultiplier) min _maxLoot) max _minLoot;
for "_k" from 1 to _maxPayout do {
2017-10-10 15:49:00 +00:00
_loots pushBack (selectRandomWeighted _lootTable);
2015-09-17 16:31:04 +00:00
};
{
2017-08-30 22:00:06 +00:00
_lootItemWeightedArray = [_lootTableClass, _x, "items"] call EPOCH_fnc_weightedArray;
2017-10-10 15:49:00 +00:00
if !(_lootItemWeightedArray isEqualTo[]) then {
_randomItemArray = selectRandomWeighted _lootItemWeightedArray;
2015-09-17 16:31:04 +00:00
_randomItem = _randomItemArray select 0;
_type = _randomItemArray select 1;
_quan = 1;
_loop = true;
_exit = false;
while {_loop} do {
switch _type do {
case "item": {
2016-05-01 19:22:31 +00:00
if (isClass (_pricingConfig >> _randomItem) || _forceSpawn) then {
2016-04-08 20:21:46 +00:00
_object additemCargoGlobal [_randomItem, _quan];
} else {
if (_debug) then {diag_log format["DEBUG: suppress spawn of %1 does not have price.",_randomItem]};
};
2015-09-17 16:31:04 +00:00
_loop = false;
};
case "magazine": {
2016-05-01 19:22:31 +00:00
if (isClass (_pricingConfig >> _randomItem) || _forceSpawn) then {
2016-04-08 20:21:46 +00:00
if (_randomizeMagazineAmmoCount) then {
// spawn a single Magazine with a random ammo count
_magazineSize = getNumber (configFile >> "CfgMagazines" >> _randomItem >> "count");
_object addMagazineAmmoCargo[_randomItem, _quan, ceil(random(_magazineSize))];
} else {
// spawn a single full Magazine
_object addMagazineCargoGlobal [_randomItem, _quan];
};
2015-12-31 19:29:16 +00:00
} else {
2016-04-08 20:21:46 +00:00
if (_debug) then {diag_log format["DEBUG: suppress spawn of %1 does not have price.",_randomItem]};
2015-12-31 19:29:16 +00:00
};
2015-09-17 16:31:04 +00:00
_loop = false;
};
case "backpack": {
2016-05-01 19:22:31 +00:00
if (isClass (_pricingConfig >> _randomItem) || _forceSpawn) then {
2016-04-08 20:21:46 +00:00
_object addBackpackCargoGlobal [_randomItem, _quan];
} else {
if (_debug) then {diag_log format["DEBUG: suppress spawn of %1 does not have price.",_randomItem]};
};
2015-09-17 16:31:04 +00:00
_loop = false;
};
case "weapon": {
2016-05-01 19:22:31 +00:00
if (isClass (_pricingConfig >> _randomItem) || _forceSpawn) then {
2016-04-08 20:21:46 +00:00
_object addWeaponCargoGlobal [_randomItem, _quan];
// only spawn mags that have prices
_mags = getArray (configFile >> "CfgWeapons" >> _randomItem >> "magazines") select {isClass (_pricingConfig >> _x)};
if !(_mags isEqualTo []) then {
if (_randomizeMagazineAmmoCount) then {
// spawn a single Magazine with a random ammo count
_magazineSize = getNumber (configFile >> "CfgMagazines" >> (_mags select 0) >> "count");
_object addMagazineAmmoCargo[_mags select 0, 1, ceil(random(_magazineSize))];
} else {
// spawn a single full Magazine with weapon
_object addMagazineCargoGlobal [_mags select 0, 1];
};
2015-12-31 19:29:16 +00:00
};
2016-04-08 20:21:46 +00:00
} else {
if (_debug) then {diag_log format["DEBUG: suppress spawn of %1 does not have price.",_randomItem]};
2015-09-17 16:31:04 +00:00
};
_loop = false;
};
case "CfgLootTable": {
2015-12-08 17:07:43 +00:00
// go down the rabit hole
2017-08-30 22:00:06 +00:00
_lootItemWeightedArray = [_lootTableClass, _randomItem, "items"] call EPOCH_fnc_weightedArray;
2017-10-10 15:49:00 +00:00
if !(_lootItemWeightedArray isEqualTo[]) then {
_randomItemArray = selectRandomWeighted _lootItemWeightedArray;
2015-09-17 16:31:04 +00:00
_randomItem = _randomItemArray select 0;
_type = _randomItemArray select 1;
} else {
_exit = true;
};
};
default {
_exit = true;
};
};
2016-04-08 20:21:46 +00:00
if (_exit) exitWith{if (_debug) then {diag_log "DEBUG: exit from spawn with default state."}};
2015-09-17 16:31:04 +00:00
};
};
} forEach _loots;
};
2015-12-08 17:07:43 +00:00
};