Jump to content
Donnovan

Lootos - My Personal Loot System

Recommended Posts

This is my personal Loot System i share with you now.

Hope you enjoy.

You must allow this public variable in your BE filters: mtdr_lootActiveAdd.

Installation: Run it at the end of your init.sqf with: execVM "script_path/script_name.sqf";

Buildings in _mtdr_loot_buildings_class are from DayZ Mod.

I have a tool to help you to fill the _mtdr_loot_buildings_spawnPos array. To share with you later if needed.

private ["_mtdr_loot_buildings_class","_mtdr_loot_buildings_spawnPos","_mtdr_loot_items","_renewTime","_spawnAgain"];
//MTDR LOOT SYSTEM
_map_size = 15360;
_map_center = [_map_size/2,_map_size/2,0];
_map_rad = (_map_size * sqrt(2))/2;

//Time after a spawned loot will try to be removed and
//triggered to spawn again accordingly to _spawnAgain
_renewTime = 1800;
_spawnAgain = true;

//Buildings that i want to have Loot Piles
_mtdr_loot_buildings_class = [
	"Land_A_Hospital",
	"Land_Mil_Barracks_i",
	"Land_a_stationhouse",
	"Land_A_GeneralStore_01",
	"Land_A_GeneralStore_01a",
	"Land_A_Pub_01",
	"Land_HouseV_1I4",
	"Land_Church_03",
	"Land_Church_01",
	"Land_HouseV2_02_Interier"
];

//Loot Pile Positions of Buildings in _mtdr_loot_buildings_class
//[[Pile Pos in building Coords,Loot lie on ground?],[Another pos,Another f/t],...]
_mtdr_loot_buildings_spawnPos = [
	[[[-07.00,-04.00,-07.33],false]],
	[[[ 05.00, 02.00,-01.10],false]],
	[[[-01.20,-07.90,-09.47],false]],
	[[[-01.14, 01.37,-01.20],false]],
	[[[ 00.50, 05.00,-01.20],false]],
	[[[ 06.16, 05.46,-01.43],false]],
	[[[ 00.00, 03.70,-02.72],false]],
	[[[ 04.70,-00.10,-14.29],false],[[-17.50, 00.00,-14.29],true]],
	[[[-06.90, 00.29,-04.21],false]],
	[[[-00.14,-02.45,-05.53],false]]
];

//Items To place on the buildings. Array:
//Items,
//quantity*,
//buildings in _mtdr_loot_buildings_class,
//building preference. The higher the relative value the greater is the preference
//true for quantity* overall / false for quantity* per building
_mtdr_loot_items = [
	[["ItemBandage"],1,[0,1,2,3,4,5,6,7,8,9],[10,10,10,10,10,10,10,10,10,10],false],
	[["ItemWatch"],12,[7,8],[10,10],true],
	[["DMR"],1,[2,5],[2,10],true],
	[["Makarov"],0.50,[5],[10],false]
];

if (isServer) then {
	private ["_mtdr_loot_buildings_objs","_mtdr_lootTable_bobj","_mtdr_lootTable_item","_mtdr_lootActive","_MTDR_fnc_selectRandom"];
	waitUntil {!isNil "BIS_fnc_selectRandom"};
	
	//Wait do give the chance to all mod and server custom buildings to spawn
	sleep 10;
	
	//Predefine loot locations
	_mtdr_loot_buildings_objs = [];
	_mtdr_loot_buildings_objs_count = [];
	{
		_class = _x;
		_objs = [];
		{if (typeOf _x == _class) then {_objs = _objs + [_x];};} forEach (_map_center nearObjects [_class,_map_rad]);
		_mtdr_loot_buildings_objs = _mtdr_loot_buildings_objs + [_objs];
	} forEach _mtdr_loot_buildings_class;
	{
		_qtt = count _x;
		_mtdr_loot_buildings_objs_count = _mtdr_loot_buildings_objs_count + [_qtt];
	} forEach _mtdr_loot_buildings_objs;
	_mtdr_lootTable_bobj = [];
	_mtdr_lootTable_item = [];
	_MTDR_fnc_selectRandom = {_index = round (random count _this - 0.5);_index};
	{
		_prefArray = _x select 3;
		_perBuild = true;
		_total = 0;
		_totalB = 0;
		_mult = 1;
		if (_perBuild) then {_mult = 0;};
		{
			_total = _total + (_mtdr_loot_buildings_objs_count select _x) * ((_prefArray select _forEachIndex) * _mult + (1 - _mult));
			_totalB = _totalB + (_mtdr_loot_buildings_objs_count select _x);
		} forEach (_x select 2);
		{
			_qttB = (_mtdr_loot_buildings_objs_count select _x) * ((_prefArray select _forEachIndex) * _mult + (1 - _mult));
			_prefArray set [_forEachIndex,(_qttB/_total) * 100];
		} forEach (_x select 2);
		diag_log ("[MTDR LOOT] " + str (_x select 0) + ": _prefArray = " + str _prefArray);
		_qtt = _x select 1;
		if !(_x select 4) then {_qtt = round (_qtt * _totalB);};
		for "_i" from 1 to _qtt do {
			_bTypeIndex = 0;
			while {true} do {
				_idx = (_x select 2) call _MTDR_fnc_selectRandom;
				if (random 100 < _prefArray select _idx) exitWith {
					_bTypeIndex = (_x select 2) select _idx;
				};
			};
			_buildObj = (_mtdr_loot_buildings_objs select _bTypeIndex) call BIS_fnc_selectRandom;
			_buildPos = getPosATL _buildObj;
			_item = (_x select 0) call BIS_fnc_selectRandom;
			_bIndex = _mtdr_lootTable_bobj find _buildObj;
			if (_bIndex == -1) then {
				_mtdr_lootTable_bobj = _mtdr_lootTable_bobj + [_buildObj];
				_mtdr_lootTable_item = _mtdr_lootTable_item + [_item];
			} else {
				_items = _mtdr_lootTable_item select _bIndex;
				if (typeName _items == "Array") then {
					_newPile = _items + [_item];
					_mtdr_lootTable_item set [_bIndex,_newPile];
				} else {
					_newPile = [_items] + [_item];
					_mtdr_lootTable_item set [_bIndex,_newPile];
				};
			};
		};
	} forEach _mtdr_loot_items;
	mtdr_lootSystemMain = [_mtdr_lootTable_bobj,_mtdr_lootTable_item];
	publicVariable "mtdr_lootSystemMain";
	
	//Monitor for Abandoned Loot Deletion
	_mtdr_lootActive = [];
	"mtdr_lootActiveAdd" addPublicVariableEventHandler {_mtdr_lootActive = _mtdr_lootActive + [_this select 1];};
	while {true} do {
		{
			_build = _x;
			_time = _build getVariable ["ml_used",0];
			if (time - _time > _renewTime) then {
				_bPos = getPosATL _build;
				_nearP = false;
				{if (_bPos distance _x < 200) exitWith {_nearP = true;};} forEach playableUnits;
				if (!_nearP) then {
					_idx1 = _mtdr_loot_buildings_class find typeOf _build;
					_spawnPosAll = _mtdr_loot_buildings_spawnPos select _idx1;
					{
						_spawnPos = _build modelToWorld (_x select 0);
						_holders = _spawnPos nearObjects ["WeaponHolder",5];
						_holder = objNull;
						if (count _holders > 0) then {
							{
								if (_x getVariable ["ml_hld",false]) exitWith {_holder = _x;};
							} forEach _holders;
						};
						if (!isNull _holder) then {deleteVehicle _holder;};
					} forEach _spawnPosAll;
					_mtdr_lootActive = _mtdr_lootActive - [_build];
					if (_spawnAgain) then {
						_build setVariable ["ml_used",-1,true];
					};
				};
			};
			uiSleep 0.001;
		} forEach _mtdr_lootActive;
		uiSleep 180;
	};
};

if (hasInterface) then {
	private ["_mtdr_lootTable_bobj","_mtdr_lootTable_item","_mtdr_pPosMain","_mtdr_calc_newBuilds","_mtdr_spawnLoot","_mtdr_lootTable_bobj_local","_mtdr_lootTable_item_local"];
	waitUntil {!isNil "mtdr_lootSystemMain"};
	_mtdr_lootTable_bobj = mtdr_lootSystemMain select 0;
	_mtdr_lootTable_item = mtdr_lootSystemMain select 1;
	_mtdr_pPosMain = getPosATL player;
	
	//Function to Find Loot buildings near the player
	//They are the ones that will be monitored in the loop
	_mtdr_calc_newBuilds = {
		_mtdr_lootTable_bobj_local = [];
		_mtdr_lootTable_item_local = [];
		{
			_bSize = (sizeOf typeOf _x) * 2;
			_dist = ((_mtdr_pPosMain distance _x) - _bSize) max 0;
			_items = _mtdr_lootTable_item select _forEachIndex;
			if (_dist < 300) then {
				_mtdr_lootTable_bobj_local = _mtdr_lootTable_bobj_local + [_x];
				_mtdr_lootTable_item_local = _mtdr_lootTable_item_local + [_items];
			};
		} forEach _mtdr_lootTable_bobj;
	};
	
	//Function to Spawn Loot
	_mtdr_spawnLoot = {
		_obj = _this select 0;
		_items = _this select 1;
		if (typeName _items != "Array") then {_items = [_items];};
		_idx1 = _mtdr_loot_buildings_class find typeOf _obj;
		_spawnPosAll = _mtdr_loot_buildings_spawnPos select _idx1;
		{
			_spawnPosArray = _spawnPosAll call BIS_fnc_selectRandom;
			_spawnPos = _obj modelToWorld (_spawnPosArray select 0);
			_onGround = _spawnPosArray select 1;
			if (_onGround) then {_spawnPos = [_spawnPos select 0,_spawnPos select 1,0];};
			_holders = _spawnPos nearObjects ["WeaponHolder",5];
			_holder = objNull;
			if (count _holders > 0 && {_x getVariable ["ml_hld",false]} count _holders > 0) then {
				{
					if (_x getVariable ["ml_hld",false]) exitWith {
						_holder = _x;
					};
				} forEach _holders;
			} else {
				_holder = createVehicle ["WeaponHolder",_spawnPos,[],0,"CAN_COLLIDE"];
				_holder setPosATL _spawnPos;
				_holder setVariable ["ml_hld",true,true];
			};
			_isM = isClass (configFile >> "CfgMagazines" >> _x);
			if (_isM) then {
				_holder addMagazineCargoGlobal [_x,1];
			} else {
				_isW = isClass (configFile >> "CfgWeapons" >> _x);
				if (_isW) then {
					_holder addWeaponCargoGlobal [_x,1];
				} else {
					_isV = isClass (configFile >> "CfgVehicles" >> _x);
					if (_isV) then {
						_holder addBackpackCargoGlobal [_x,1];
					} else {
						diag_log "[MTDR LOOT] TIPO DE LOOT NAO IDENTIFICADO!";
					};
				};
			};
		} forEach _items;
		mtdr_lootActiveAdd = _obj;
		publicVariableServer "mtdr_lootActiveAdd";
	};
	call _mtdr_calc_newBuilds;

	//Monitore for Loot Buildings to activate for player
	while {true} do {
		_pOnFoot = vehicle player == player;
		if (_pOnFoot) then {
			_pPos = getPosATL player;
			_walked = _mtdr_pPosMain distance _pPos;
			if (_walked > 280) then {
				_mtdr_pPosMain = _pPos;
				call _mtdr_calc_newBuilds;
				_walked = 0;
			};
			{
				_bSize = sizeOf typeOf _x;
				_dist = ((_pPos distance _x) - _bSize) max 0;
				if (_dist == 0) then {
					_bUsed = _x getVariable ["ml_used",-1];
					if (_bUsed == -1) then {
						_x setVariable ["ml_used",time,true];
						_items = _mtdr_lootTable_item_local select _forEachIndex;
						[_x,_items] call _mtdr_spawnLoot;
						//systemChat "Loot Especial Matadouro...!";
					};
				};
			} forEach _mtdr_lootTable_bobj_local;
		};
		uiSleep 2;
	};
};
Edited by Donnovan

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Advertisement
  • Supporters
  • Discord

×
×
  • Create New...