Update remove/deconstruct, add helpers

Removing and Deconstructing Objects

- Now adds colored helpers to modular objects.
- Green: Refund one kit.
- Blue:  Refund entire recipe of parts (multiple items).
- Red:	 No refund will be given. Either because the object is too damaged, or the refund feature is disabled.
- If the object has a door open while selected, no helper will display/float in the open door space.
- The gear panel will only open if a refund is available.
- If a lit fire barrel is removed, the flame will now be extinguished.
- If a plot pole is removed, plot boundary helpers will now be deleted.
- Refunds for non-modular objects are handled by their respective config settings.
- Removed non-lockable storage objects will now refund their contents.
- The corresponding storage kit will be refunded.
- If there is room outdoors, backpacks will be arranged in a neat circle close to the refund point.
- If the spawn point is too close to a building, backpacks will spawn at the player's location.
- Helpers will now appear on wrecked/ruined modular objects.
- Helper color arrays were changed to helper transparency values only, to make it easier (and safer) for server owners.

Upgrading, Downgrading, Maintaining and Packing Objects

- Now includes colored helper spheres for improved player experience.
- Reapply damage to upgraded/downgraded object if necessary.

Changes made by @Victor-the-Cleaner
This commit is contained in:
A Man
2021-09-19 18:50:14 +02:00
parent bb968698e6
commit 58c4a4d1f7
13 changed files with 2016 additions and 420 deletions

View File

@@ -1,111 +1,164 @@
/*
DayZ Base Building Upgrades
Made for DayZ Epoch please ask permission to use/edit/distribute email vbawol@veteranbastards.com.
*/
if (dayz_actionInProgress) exitWith {localize "str_epoch_player_48" call dayz_rollingMessages;};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// DayZ Base Building Downgrades
// Made for DayZ Epoch please ask permission to use/edit/distribute email vbawol@veteranbastards.com.
//
// Updated by: Victor the Cleaner
// Date: August 2021
//
// - Now includes helper spheres for improved player experience.
// - Reapply damage to upgraded object if necessary.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (dayz_actionInProgress) exitWith {localize "str_epoch_player_48" call dayz_rollingMessages;}; // Downgrade is already in progress.
dayz_actionInProgress = true;
private ["_location","_dir","_classname","_text","_object","_objectID","_objectUID","_newclassname","_refund","_obj","_upgrade","_objectCharacterID","_ownerID","_i","_invResult","_itemOut","_countOut","_abortInvAdd","_addedItems","_finished","_playerNear"];
player removeAction s_player_downgrade_build;
s_player_downgrade_build = 1;
_obj = _this select 3;
local _obj = _this select 3;
_objectCharacterID = _obj getVariable ["CharacterID","0"];
local _objectCharacterID = _obj getVariable ["CharacterID","0"];
if (DZE_Lock_Door != _objectCharacterID) exitWith {dayz_actionInProgress = false; s_player_downgrade_build = -1; localize "str_epoch_player_49" call dayz_rollingMessages;};
if (DZE_Lock_Door != _objectCharacterID) exitWith { // Unable to downgrade, you do not know the combination.
dayz_actionInProgress = false;
s_player_downgrade_build = -1;
localize "str_epoch_player_49" call dayz_rollingMessages;
};
_playerNear = {isPlayer _x} count (([_obj] call FNC_GetPos) nearEntities ["CAManBase", 12]) > 1;
if (_playerNear) exitWith {dayz_actionInProgress = false; s_player_downgrade_build = -1; localize "str_pickup_limit_5" call dayz_rollingMessages;};
local _playerNear = {isPlayer _x} count (([_obj] call FNC_GetPos) nearEntities ["CAManBase", 12]) > 1;
_objectID = _obj getVariable ["ObjectID","0"];
_objectUID = _obj getVariable ["ObjectUID","0"];
if (_playerNear) exitWith { // Another player is nearby. Only one player can be near to perform this action.
dayz_actionInProgress = false;
s_player_downgrade_build = -1;
localize "str_pickup_limit_5" call dayz_rollingMessages;
};
if (_objectID == "0" && _objectUID == "0") exitWith {dayz_actionInProgress = false; s_player_downgrade_build = -1; localize "str_epoch_player_50" call dayz_rollingMessages;};
local _objectID = _obj getVariable ["ObjectID","0"];
local _objectUID = _obj getVariable ["ObjectUID","0"];
_classname = typeOf _obj;
if (_objectID == "0" && _objectUID == "0") exitWith { // Not setup yet.
dayz_actionInProgress = false;
s_player_downgrade_build = -1;
localize "str_epoch_player_50" call dayz_rollingMessages;
};
_text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
_upgrade = getArray (configFile >> "CfgVehicles" >> _classname >> "downgradeBuilding");
///////////////////////////////////////////////////////////////////////////////////////////////////
if ((count _upgrade) > 0) then {
_newclassname = _upgrade select 0;
_refund = _upgrade select 1;
local _classname = typeOf _obj;
local _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
local _upgrade = getArray (configFile >> "CfgVehicles" >> _classname >> "downgradeBuilding");
[player,(getPosATL player),40,"repair"] spawn fnc_alertZombies;
if (count _upgrade > 0) then {
local _newclassname = _upgrade select 0;
local _refund = _upgrade select 1;
[_obj] call fn_displayHelpers; // create helpers
[player, (getPosATL player), 40, "repair"] spawn fnc_alertZombies; // make noise
local _finished = ["Medic",1] call fn_loopAction; // animation
[] call fn_displayHelpers; // delete helpers
_finished = ["Medic",1] call fn_loopAction;
if (!_finished) exitWith {};
["Working",0,[3,2,4,0]] call dayz_NutritionSystem;
_invResult = false;
_abortInvAdd = false;
_i = 0;
_addedItems = [];
false call dz_fn_meleeMagazines; // Remove melee magazines (BIS_fnc_invAdd fix)
local _invResult = false;
local _i = 0;
local _addedItems = [];
local _itemOut = ""; // item class
false call dz_fn_meleeMagazines; // Remove melee magazines (BIS_fnc_invAdd fix)
{
_itemOut = _x select 0;
_countOut = _x select 1;
local _countOut = _x select 1;
for "_x" from 1 to _countOut do {
_invResult = [player,_itemOut] call BIS_fnc_invAdd;
if(!_invResult) exitWith {
_abortInvAdd = true;
};
if(_invResult) then {
_i = _i + 1;
_addedItems set [(count _addedItems),[_itemOut,1]];
};
};
if (_abortInvAdd) exitWith {};
_invResult = [player, _itemOut] call BIS_fnc_invAdd;
if (!_invResult) exitWith {};
_i = _i + 1;
_addedItems set [(count _addedItems), [_itemOut, 1]];
};
if (!_invResult) exitWith {};
} count _refund;
true call dz_fn_meleeMagazines;
if (_i != 0) then {
_location = _obj getVariable["OEMPos",getPosATL _obj];
if (_i > 0) then {
_dir = getDir _obj;
_vector = [(vectorDir _obj),(vectorUp _obj)];
local _position = _obj getVariable["OEMPos", getPosATL _obj];
local _dir = getDir _obj;
local _vector = [(vectorDir _obj), (vectorUp _obj)];
if (_classname in DZE_DoorsLocked) then {
_obj setVariable ["CharacterID",dayz_characterID,true];
_obj setVariable ["CharacterID", dayz_characterID, true];
_objectCharacterID = dayz_characterID;
};
_classname = _newclassname;
_object = createVehicle [_classname, [0,0,0], [], 0, "CAN_COLLIDE"];
local _object = createVehicle [_classname, [0,0,0], [], 0, "CAN_COLLIDE"];
//_object setDir _dir; // setdir is incompatible with setVectorDirAndUp and should not be used together on the same object https://community.bistudio.com/wiki/setVectorDirAndUp
_object setVariable["memDir",_dir,true];
_object setVariable["memDir", _dir, true];
_object setVectorDirAndUp _vector;
_object setPosATL _location;
_object setPosATL _position;
format[localize "str_epoch_player_142",_text] call dayz_rollingMessages;
format[localize "str_epoch_player_142", _text] call dayz_rollingMessages; // You have downgraded %1.
if (DZE_GodModeBase && {!(_classname in DZE_GodModeBaseExclude)}) then {_object addEventHandler ["HandleDamage",{false}];};
if (DZE_GodModeBase && {!(_classname in DZE_GodModeBaseExclude)}) then {
_object addEventHandler ["HandleDamage", {false}];
} else {
//
// reapply damage based on armor values
//
local _armorOld = getNumber (configFile >> "CfgVehicles" >> (typeOf _obj) >> "armor");
local _damageOld = damage _obj;
local _armorNew = getNumber (configFile >> "CfgVehicles" >> _classname >> "armor");
local _damageNew = _damageOld;
// check for divide by 0
if (_armorNew > 0) then {
_damageNew = (_damageOld * _armorOld) / _armorNew;
};
_object setDamage _damageNew;
};
if (DZE_permanentPlot) then {
_ownerID = _obj getVariable["ownerPUID","0"];
_object setVariable ["ownerPUID",_ownerID,true];
PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location,dayz_playerUID,_vector],_classname,_obj,player,[],dayz_authKey];
} else {
PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location, _vector],_classname,_obj,player,[],dayz_authKey];
};
publicVariableServer "PVDZE_obj_Swap";
local _ownerID = _obj getVariable["ownerPUID", "0"];
_object setVariable ["ownerPUID", _ownerID, true];
PVDZE_obj_Swap = [_objectCharacterID, _object, [_dir, _position, dayz_playerUID, _vector], _classname, _obj, player, [], dayz_authKey];
} else {
PVDZE_obj_Swap = [_objectCharacterID, _object, [_dir, _position, _vector], _classname, _obj, player, [], dayz_authKey];
};
publicVariableServer "PVDZE_obj_Swap";
player reveal _object;
} else {
format[localize "str_epoch_player_143",_i,getText(configFile >> "CfgMagazines" >> _itemOut >> "displayName")] call dayz_rollingMessages;
_text = getText(configFile >> "CfgMagazines" >> _itemOut >> "displayName");
format[localize "str_epoch_player_143", _i, _text] call dayz_rollingMessages; // %1 of %2 could not be added to your inventory. (not enough room?) // poorly worded
{
[player,(_x select 0),(_x select 1)] call BIS_fnc_invRemove;
[player, (_x select 0), (_x select 1)] call BIS_fnc_invRemove;
} count _addedItems;
};
} else {
localize "str_epoch_player_51" call dayz_rollingMessages;
localize "str_epoch_player_51" call dayz_rollingMessages; // No downgrades are available
};
dayz_actionInProgress = false;

View File

@@ -1,197 +1,267 @@
/*
DayZ Base Building Upgrades
Made for DayZ Epoch please ask permission to use/edit/distrubute email vbawol@veteranbastards.com.
*/
if (dayz_actionInProgress) exitWith {localize "str_epoch_player_52" call dayz_rollingMessages;};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// DayZ Base Building Upgrades
// Made for DayZ Epoch please ask permission to use/edit/distribute email vbawol@veteranbastards.com.
//
// Updated by: Victor the Cleaner
// Date: August 2021
//
// - Now includes helper spheres for improved player experience.
// - Reapply damage to upgraded object if necessary.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (dayz_actionInProgress) exitWith {localize "str_epoch_player_52" call dayz_rollingMessages;}; // Upgrade is already in progress.
dayz_actionInProgress = true;
private ["_location","_dir","_classname","_hasAccess","_missing","_text","_proceed","_num_removed","_object","_missingQty","_itemIn","_countIn","_qty","_removed","_removed_total","_tobe_removed_total","_objectID","_objectUID","_temp_removed_array","_textMissing","_newclassname","_requirements","_obj","_upgrade","_lockable","_combination_1","_combination_2","_combination_3","_combination","_objectCharacterID","_ownerID","_qtyBP","_bpMags","_countNew","_bp2Remove","_count","_friendsArr","_vector","_temp_BP_removed_array","_finished","_neededTools"];
player removeAction s_player_upgrade_build;
s_player_upgrade_build = 1;
_obj = _this select 3;
_objectID = _obj getVariable ["ObjectID","0"];
_objectUID = _obj getVariable ["ObjectUID","0"];
_classname = typeOf _obj;
local _obj = _this select 3;
local _objectID = _obj getVariable ["ObjectID","0"];
local _objectUID = _obj getVariable ["ObjectUID","0"];
local _classname = typeOf _obj;
if ((_objectID == "0" && {_objectUID == "0"}) || _classname in DZE_DisableUpgrade) exitWith {dayz_actionInProgress = false; s_player_upgrade_build = -1; localize "str_epoch_player_50" call dayz_rollingMessages;};
if ((_objectID == "0" && _objectUID == "0") || {_classname in DZE_DisableUpgrade}) exitWith {
dayz_actionInProgress = false;
s_player_upgrade_build = -1;
localize "str_epoch_player_50" call dayz_rollingMessages; // Not setup yet.
};
_hasAccess = [player, _obj] call FNC_check_access;
if (_classname in DZE_LockedStorage && !(_hasAccess select 0)) exitWith {dayz_actionInProgress = false;localize "STR_CL_EC_NOT_OWNER" call dayz_rollingMessages;};
local _hasAccess = [player, _obj] call FNC_check_access;
_text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
_upgrade = getArray (configFile >> "CfgVehicles" >> _classname >> "upgradeBuilding");
if (!(_hasAccess select 0) && {_classname in DZE_LockedStorage}) exitWith {
dayz_actionInProgress = false;
localize "STR_CL_EC_NOT_OWNER" call dayz_rollingMessages; // You are not the owner.
};
local _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
local _upgrade = getArray (configFile >> "CfgVehicles" >> _classname >> "upgradeBuilding");
if ((count _upgrade) > 0) then {
_neededTools = _upgrade select 1;
if (["",_neededTools,"none"] call dze_requiredItemsCheck) then {
_newclassname = _upgrade select 0;
_lockable = 0;
if(isNumber (configFile >> "CfgVehicles" >> _newclassname >> "lockable")) then {
_lockable = getNumber(configFile >> "CfgVehicles" >> _newclassname >> "lockable");
};
_requirements = _upgrade select 2;
_missingQty = 0;
_missing = "";
_bpMags = [];
_bp2Remove = [];
_qtyBP = 0;
_proceed = true;
local _neededTools = _upgrade select 1;
if (["", _neededTools, "none"] call dze_requiredItemsCheck) then {
local _newclassname = _upgrade select 0;
local _lockable = getNumber(configFile >> "CfgVehicles" >> _newclassname >> "lockable");
local _requirements = _upgrade select 2;
local _missingQty = 0;
local _missing = "";
local _bpMags = [];
local _bp2Remove = [];
local _qtyBP = 0;
local _proceed = true;
{
_itemIn = _x select 0;
_countIn = _x select 1;
_qty = { (_x == _itemIn) || {configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn} } count magazines player;
local _itemIn = _x select 0;
local _countIn = _x select 1;
local _qty = {(_x == _itemIn) || {configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn}} count magazines player;
if (!isNull (UnitBackpack Player) && {_qty < _countIn}) then {
_bpMags = (getMagazineCargo (unitbackpack player));
if (!isNull (UnitBackpack Player) && (_qty < _countIn)) then {
_bpMags = getMagazineCargo (unitBackpack player);
{
if ((_x == _itemIn) || {configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn}) exitWith {
_qtyBP = ((_bpMags select 1) select _forEachIndex);
_bp2Remove set [(count _bp2Remove), _x];
if ((_x == _itemIn) || (configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn)) exitWith {
_qtyBP = (_bpMags select 1) select _forEachIndex;
_bp2Remove set [count _bp2Remove, _x];
};
} forEach (_bpMags select 0);
};
if ((_qty < _countIn) && {_qtyBP < (_countIn - _qty)}) exitWith { _missing = _itemIn; _missingQty = (_countIn - (_qty + _qtyBP)); _proceed = false; };
if (_qty < _countIn && (_qtyBP < (_countIn - _qty))) exitWith {
_missing = _itemIn;
_missingQty = _countIn - (_qty + _qtyBP);
_proceed = false;
};
} forEach _requirements;
if (_proceed) then {
[player,(getPosATL player),25,"repair"] spawn fnc_alertZombies;
_finished = ["Medic",1] call fn_loopAction;
[_obj] call fn_displayHelpers; // create helpers
[player, (getPosATL player), 25, "repair"] spawn fnc_alertZombies; // make noise
local _finished = ["Medic",1] call fn_loopAction; // animation
[] call fn_displayHelpers; // delete helpers
if (!_finished) exitWith {};
["Working",0,[3,2,4,0]] call dayz_NutritionSystem;
_temp_removed_array = [];
_temp_BP_removed_array = [];
_removed_total = 0;
_tobe_removed_total = 0;
local _temp_removed_array = [];
local _temp_BP_removed_array = [];
local _removed_total = 0;
local _tobe_removed_total = 0;
{
_removed = 0;
_itemIn = _x select 0;
_countIn = _x select 1;
local _removed = 0;
local _itemIn = _x select 0;
local _countIn = _x select 1;
_tobe_removed_total = _tobe_removed_total + _countIn;
{
if( (_removed < _countIn) && {(_x == _itemIn) || {configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn}}) then {
_num_removed = ([player,_x] call BIS_fnc_invRemove);
_removed = _removed + _num_removed;
_removed_total = _removed_total + _num_removed;
local _num_removed = ([player, _x] call BIS_fnc_invRemove);
_removed = _removed + _num_removed;
_removed_total = _removed_total + _num_removed;
if(_num_removed >= 1) then {
_temp_removed_array set [count _temp_removed_array,_x];
_temp_removed_array set [count _temp_removed_array, _x];
};
};
} forEach magazines player;
if (!isNull (UnitBackpack Player) && {_removed < _countIn}) then {
_bpMags = (getMagazineCargo (unitbackpack player));
clearMagazineCargoGlobal (unitbackpack player);
if (!isNull (UnitBackpack Player) && (_removed < _countIn)) then {
_bpMags = getMagazineCargo (unitBackpack player);
clearMagazineCargoGlobal (unitBackpack player);
{
_count = ((_bpMags select 1) select _forEachIndex);
_countNew = _count;
local _count = (_bpMags select 1) select _forEachIndex;
local _countNew = _count;
if (_x in _bp2Remove && {(_x == _itemIn) || {configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn}}) then {
_countNew = (_count - (_countIn - _removed));
_bp2Remove = _bp2Remove - [_x];
_countNew = _count - (_countIn - _removed);
_bp2Remove = _bp2Remove - [_x];
};
if (_countNew > 0) then {
(unitbackpack player) addMagazineCargoGlobal [_x, _countNew];
(unitBackpack player) addMagazineCargoGlobal [_x, _countNew];
};
_num_removed = (_count - _countNew);
_temp_BP_removed_array set [(count _temp_BP_removed_array), [_x, _num_removed]];
local _num_removed = _count - _countNew;
_temp_BP_removed_array set [count _temp_BP_removed_array, [_x, _num_removed]];
_removed_total = _removed_total + _num_removed;
} forEach (_bpMags select 0);
};
} forEach _requirements;
if (_tobe_removed_total == _removed_total) then {
call player_forceSave;
_location = _obj getVariable["OEMPos",(getposATL _obj)];
_dir = getDir _obj;
_vector = [(vectorDir _obj),(vectorUp _obj)];
_objectCharacterID = _obj getVariable ["CharacterID","0"];
_classname = _newclassname;
_object = createVehicle [_classname, [0,0,0], [], 0, "CAN_COLLIDE"];
local _location = _obj getVariable["OEMPos", (getPosATL _obj)];
local _dir = getDir _obj;
local _vector = [vectorDir _obj, vectorUp _obj];
local _objectCharacterID = _obj getVariable ["CharacterID","0"];
_classname = _newclassname;
local _object = createVehicle [_classname, [0,0,0], [], 0, "CAN_COLLIDE"];
//_object setDir _dir; // setdir is incompatible with setVectorDirAndUp and should not be used together on the same object https://community.bistudio.com/wiki/setVectorDirAndUp
_object setVariable["memDir",_dir,true];
_object setVariable["memDir", _dir, true];
_object setVectorDirAndUp _vector;
_object setPosATL _location;
if (_lockable == 3 && {!(_classname in ["WoodenGate_2_DZ","WoodenGate_3_DZ","WoodenGate_4_DZ"])}) then {
DZE_topCombo = 0;
DZE_midCombo = 0;
DZE_botCombo = 0;
DZE_Lock_Door = "";
dayz_selectedDoor = objNull;
DZE_topCombo = 0;
DZE_midCombo = 0;
DZE_botCombo = 0;
DZE_Lock_Door = "";
dayz_selectedDoor = objNull;
local _combination = 0;
createDialog "ComboLockUI";
waitUntil {!dialog};
if (keypadCancel || {parseNumber DZE_Lock_Door == 0}) then {
_combination_1 = floor(random 10);
_combination_2 = floor(random 10);
_combination_3 = floor(random 10);
_combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
DZE_Lock_Door = _combination;
if (keypadCancel || (parseNumber DZE_Lock_Door == 0)) then {
local _combination_1 = floor(random 10);
local _combination_2 = floor(random 10);
local _combination_3 = floor(random 10);
_combination = format["%1%2%3", _combination_1, _combination_2, _combination_3];
DZE_Lock_Door = _combination;
} else {
_combination = DZE_Lock_Door;
};
_objectCharacterID = _combination;
format[localize "str_epoch_player_158",_combination,_text] call dayz_rollingMessages;
systemChat format[localize "str_epoch_player_158",_combination,_text];
local _message = format[localize "str_epoch_player_158", _combination, _text];
_message call dayz_rollingMessages;
systemChat _message; // You have upgraded %2. The combination is: %1
} else {
format[localize "str_epoch_player_159",_text] call dayz_rollingMessages;
format[localize "str_epoch_player_159", _text] call dayz_rollingMessages; // You have upgraded %1.
};
if (DZE_GodModeBase && {!(_classname in DZE_GodModeBaseExclude)}) then {
_object addEventHandler ["HandleDamage",{false}];
} else {
//
// reapply damage based on armor values
//
local _armorOld = getNumber (configFile >> "CfgVehicles" >> (typeOf _obj) >> "armor");
local _damageOld = damage _obj;
local _armorNew = getNumber (configFile >> "CfgVehicles" >> _classname >> "armor");
local _damageNew = _damageOld;
// check for divide by 0
if (_armorNew > 0) then {
_damageNew = (_damageOld * _armorOld) / _armorNew;
};
_object setDamage _damageNew;
};
if (DZE_permanentPlot) then {
_ownerID = _obj getVariable["ownerPUID","0"];
if (_ownerID == "0") then { _ownerID = dayz_playerUID; }; //APFL is on but UID is 0 so we will claim it to record the ownership.
_object setVariable ["ownerPUID",_ownerID,true];
local _ownerID = _obj getVariable["ownerPUID","0"];
if (_ownerID == "0") then {
_ownerID = dayz_playerUID; // APFL is on but UID is 0 so we will claim it to record the ownership.
};
_object setVariable ["ownerPUID", _ownerID, true];
if (_lockable == 3) then {
_friendsArr = [[dayz_playerUID,toArray (name player)]];
local _friendsArr = [[dayz_playerUID, toArray (name player)]];
_object setVariable ["doorfriends", _friendsArr, true];
PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location,_ownerID,_vector],_classname,_obj,player,_friendsArr,dayz_authKey];
PVDZE_obj_Swap = [_objectCharacterID, _object, [_dir, _location, _ownerID, _vector], _classname, _obj, player, _friendsArr, dayz_authKey];
} else {
PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location,_ownerID,_vector],_classname,_obj,player,[],dayz_authKey];
PVDZE_obj_Swap = [_objectCharacterID, _object, [_dir, _location, _ownerID, _vector], _classname, _obj, player, [], dayz_authKey];
};
} else {
PVDZE_obj_Swap = [_objectCharacterID,_object,[_dir,_location,_vector],_classname,_obj,player,[],dayz_authKey];
PVDZE_obj_Swap = [_objectCharacterID, _object, [_dir, _location, _vector], _classname, _obj, player, [], dayz_authKey];
};
publicVariableServer "PVDZE_obj_Swap";
player reveal _object;
} else {
{player addMagazine _x;} count _temp_removed_array;
if (count _temp_BP_removed_array > 0) then {
{(unitbackpack player) addMagazineCargoGlobal _x} count _temp_BP_removed_array;
};
format[localize "str_epoch_player_145",_removed_total,_tobe_removed_total] call dayz_rollingMessages;
{player addMagazine _x;} count _temp_removed_array;
if (count _temp_BP_removed_array > 0) then {
{(unitBackpack player) addMagazineCargoGlobal _x} count _temp_BP_removed_array;
};
format[localize "str_epoch_player_145", _removed_total, _tobe_removed_total] call dayz_rollingMessages; // Missing Parts after first check Item: %1 / %2
};
} else {
_textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName");
format[localize "STR_EPOCH_ACTIONS_6",_missingQty, _textMissing] call dayz_rollingMessages;
systemchat localize "STR_CRAFTING_NEEDED_ITEMS";
local _textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName");
format[localize "STR_EPOCH_ACTIONS_6", _missingQty, _textMissing] call dayz_rollingMessages; // Missing %1 more of %2
systemChat localize "STR_CRAFTING_NEEDED_ITEMS"; // Needed items:
if (count _requirements > 0) then {
{
_text = getText(configFile >> "CfgMagazines" >> (_x select 0) >> "displayName");
systemchat format ["%2x %1",_text,(_x select 1)];
local _text = getText(configFile >> "CfgMagazines" >> (_x select 0) >> "displayName");
systemChat format ["%2x %1", _text, (_x select 1)];
} count _requirements;
};
};
};
} else {
localize "str_epoch_player_82" call dayz_rollingMessages;
localize "str_epoch_player_82" call dayz_rollingMessages; // No upgrades are available
};
dayz_actionInProgress = false;

View File

@@ -1,52 +1,104 @@
/*
delete object from db with extra waiting by [VB]AWOL
parameters: _obj
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// delete object from db with extra waiting by [VB]AWOL
//
// Modified by: Victor the Cleaner
// Date: August 2021
//
// - Will now accept array parameter: [_obj, _actionContext, _isModular]
//
// * _obj is the object to be removed
// * _actionContext is a unique ID referencing either remove or deconstruct actions
// * _isModular is for handling refunds of modular objects only
//
// - Script now adds colored helpers to modular objects when removing or deconstructing.
//
// * Green: Refund one kit
// * Blue: Refund entire recipe of parts (multiple items)
// * Red: No refund will be given. Either because the object is too damaged, or the refund feature is disabled
//
// - Refunds for non-modular objects are handled by their respective config settings.
//
// - Removed non-lockable storage objects will now refund their contents.
//
// * The corresponding storage kit will be refunded.
// * If there is room outdoors, backpacks will be arranged in a neat circle close to the refund point.
// * If the spawn point is too close to a building, backpacks will spawn at the player's location.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (dayz_actionInProgress) exitWith {localize "str_player_actionslimit" call dayz_rollingMessages;};
dayz_actionInProgress = true;
private ["_type","_plotcheck","_PlayerNear","_isMine","_obj","_objectID","_objectUID","_finished","_isOk","_proceed","_counter","_limit","_objType","_itemOut","_countOut","_selectedRemoveOutput","_nearestPole","_refundpart","_isWreck","_IsNearPlot","_brokenTool","_removeTool","_isDestructable","_isRemovable","_objOwnerID","_isOwnerOfObj","_preventRefund","_ipos","_item","_isWreckBuilding","_nameVehicle","_isModular","_success","_lootGroupIndex","_output"];
local _p = _this select 3; // get addAction parameter
local _obj = _p; // object
local _actionContext = 2; // default to remove action
local _isModular = false; // for removal of non-modular objects
player removeAction s_player_deleteBuild;
s_player_deleteBuild = 1;
_obj = _this select 3;
if (isNull _obj) exitWith {dayz_actionInProgress = false; systemChat localize "str_cursorTargetNotFound";};
_objOwnerID = "0";
_isOwnerOfObj = false;
if (DZE_permanentPlot) then {
_objOwnerID = _obj getVariable["ownerPUID","0"];
_isOwnerOfObj = (_objOwnerID == dayz_playerUID);
} else {
_objOwnerID = _obj getVariable["CharacterID","0"];
_isOwnerOfObj = (_objOwnerID == dayz_characterID);
if (typeName _p == "ARRAY") then { // allow for remove/deconstruct array to be passed
_obj = _p select 0; // object
_actionContext = _p select 1; // remove or deconstruct
_isModular = _p select 2; // isModular or isModularDoor
};
if (isNull _obj) exitWith {
dayz_actionInProgress = false;
systemChat localize "str_cursorTargetNotFound"; // You must be looking at the item to interact with it.
};
if (_obj getVariable ["GeneratorRunning", false]) exitWith {
dayz_actionInProgress = false;
localize "str_epoch_player_89" call dayz_rollingMessages; // Cannot remove a running generator.
};
if (_obj getVariable ["GeneratorRunning", false]) exitWith {dayz_actionInProgress = false; localize "str_epoch_player_89" call dayz_rollingMessages;};
local _objType = typeOf _obj; // object's classname
local _bbObject = boundingBox _obj select 1; // positive x,y dimensions
_objectID = _obj getVariable ["ObjectID","0"];
_objectUID = _obj getVariable ["ObjectUID","0"];
if (_objType in DZE_DoorsLocked && !(_objType in ["WoodenGate_1_DZ","WoodenGate_2_DZ","WoodenGate_3_DZ","WoodenGate_4_DZ"])) exitWith {
dayz_actionInProgress = false;
localize "STR_EPOCH_ACTIONS_20" call dayz_rollingMessages; // You must remove the lock to delete this item!
};
_isOk = true;
_proceed = false;
_objType = typeOf _obj;
if (_objType in DZE_DoorsLocked && !(_objType in ["WoodenGate_1_DZ","WoodenGate_2_DZ","WoodenGate_3_DZ","WoodenGate_4_DZ"])) exitWith {dayz_actionInProgress = false; localize "STR_EPOCH_ACTIONS_20" call dayz_rollingMessages;};
///////////////////////////////////////////////////////////////////////////////////////////////////
// Chance to break tools
_isDestructable = _obj isKindOf "BuiltItems";
_isWreck = _objType in DZE_isWreck;
_isRemovable = _objType in DZE_isRemovable;
_isWreckBuilding = _objType in DZE_isWreckBuilding;
_isMine = _objType in ["Land_iron_vein_wreck","Land_silver_vein_wreck","Land_gold_vein_wreck"];
_isModular = _obj isKindOf "ModularItems";
// prevent player actions appearing during animation cycle
player removeAction s_player_deleteBuild;
player removeAction s_player_deconstruct;
player removeAction s_player_upgrade_build;
player removeAction s_player_maint_build;
s_player_deleteBuild = 1;
s_player_deconstruct = 1;
s_player_upgrade_build = 1;
s_player_maint_build = 1;
_PlayerNear = {isPlayer _x} count (([_obj] call FNC_GetPos) nearEntities ["CAManBase", 12]) > 1;
if (_PlayerNear && (_isMine or _objType == "Land_ammo_supply_wreck")) exitWith {dayz_actionInProgress = false; localize "str_pickup_limit_5" call dayz_rollingMessages;};
local _objOwnerID = _obj getVariable["ownerPUID","0"];
local _isOwnerOfObj = (_objOwnerID == dayz_playerUID);
_limit = 3;
if (!DZE_permanentPlot) then {
_objOwnerID = _obj getVariable["CharacterID","0"];
_isOwnerOfObj = (_objOwnerID == dayz_characterID);
};
local _objectID = _obj getVariable ["ObjectID","0"];
local _objectUID = _obj getVariable ["ObjectUID","0"];
local _hasNoID = (_objectID == "0" && _objectUID == "0");
local _isDestructable = _obj isKindOf "BuiltItems";
local _isWreck = _objType in DZE_isWreck;
local _isRemovable = _objType in DZE_isRemovable;
local _isWreckBuilding = _objType in DZE_isWreckBuilding;
local _isMine = _objType in ["Land_iron_vein_wreck","Land_silver_vein_wreck","Land_gold_vein_wreck"];
local _isAmmoSupplyWreck= _objType == "Land_ammo_supply_wreck";
local _isPlotPole = _objType == "Plastic_Pole_EP1_DZ";
local _isFireBarrel = _objType == "FireBarrel_DZ";
local _isStorageItem = _objType in DZE_refundStorageItemContents; // non-lockable storage (sheds, crates etc.)
local _playerNear = {isPlayer _x} count (([_obj] call FNC_GetPos) nearEntities ["CAManBase", 12]) > 1;
if (_playerNear && (_isMine or _isAmmoSupplyWreck)) exitWith {
dayz_actionInProgress = false;
localize "str_pickup_limit_5" call dayz_rollingMessages; // Another player is nearby. Only one player can be near to perform this action.
};
///////////////////////////////////////////////////////////////////////////////////////////////////
local _limit = 3;
if (DZE_StaticConstructionCount > 0) then {
_limit = DZE_StaticConstructionCount;
@@ -56,225 +108,461 @@ if (DZE_StaticConstructionCount > 0) then {
};
};
_plotcheck = [player, false] call FNC_find_plots;
_IsNearPlot = _plotcheck select 1;
_nearestPole = _plotcheck select 2;
local _plotCheck = [player, false] call FNC_find_plots;
local _isNearPlot = _plotCheck select 1;
local _nearestPole = _plotCheck select 2;
if(_IsNearPlot >= 1) then {
private ["_buildcheck","_isowner","_isfriendly"];
if (_isNearPlot > 0) then {
// Since there are plot poles nearby we need to check ownership && friend status
_buildcheck = [player, _nearestPole] call FNC_check_access;
_isowner = _buildcheck select 0;
_isfriendly = ((_buildcheck select 1) or (_buildcheck select 3));
local _accessCheck = [player, _nearestPole] call FNC_check_access;
local _isowner = _accessCheck select 0;
local _isfriendly = ((_accessCheck select 1) or (_accessCheck select 3));
if (!_isowner && !_isfriendly) then {
_limit = round(_limit*2);
_limit = round(_limit * 2);
};
};
_nameVehicle = getText(configFile >> "CfgVehicles" >> _objType >> "displayName");
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Added functionality to display helpers on modular objects
//
///////////////////////////////////////////////////////////////////////////////////////////////////
local _modularRefund = false;
local _isEnabled = false;
local _refund = []; // can be either STRING or ARRAY
local _helperTexture = DZE_removeTexture; // default helper color: green
format[localize "str_epoch_player_162",_nameVehicle] call dayz_rollingMessages;
if (_isModular) then {
{
if (_objType == _x select 1) exitWith { // find matching class
_isEnabled = _x select 0; // is refund enabled?
_refund = _x select _actionContext; // get refund array
};
} count DZE_modularConfig;
if (_isModular && {_objType in _x} count DZE_modularConfig == 0) then {
localize "STR_EPOCH_ACTIONS_21" call dayz_rollingMessages;
if (_actionContext == 2) then { // if singular kit
_refund = [[_refund, 1]]; // reformat array
};
_modularRefund = (DZE_refundModular && _isEnabled && !((DZE_RefundDamageLimit > 0) && (damage _obj > DZE_RefundDamageLimit)));
if (_actionContext == 3) then { // if deconstruct
_helperTexture = DZE_deconstructTexture; // blue helpers
};
if (!_modularRefund) then { // if no refunds are to be given
localize "STR_EPOCH_ACTIONS_21" call dayz_rollingMessages; // notify player - Deconstructing modular buildables will not refund any components.
_helperTexture = DZE_NoRefundTexture; // red helpers
};
};
// Alert zombies once.
[player,50,true,(getPosATL player)] spawn player_alertZombies;
[_obj, _helperTexture] call fn_displayHelpers; // create helpers
_brokenTool = false;
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Begin Removal
//
///////////////////////////////////////////////////////////////////////////////////////////////////
local _nameVehicle = getText(configFile >> "CfgVehicles" >> _objType >> "displayName");
//format[localize "str_epoch_player_162", _nameVehicle] call dayz_rollingMessages; // Starting de-construction of %1.
local _brokenTool = false;
local _counter = 0;
local _isOk = true;
local _proceed = false;
[player, 50, true, (getPosATL player)] spawn player_alertZombies; // Alert zombies once
// Start de-construction loop
_counter = 0;
while {_isOk} do {
// if object no longer exits this should return true.
if(isNull(_obj)) exitWith {
// if object no longer exists this should return true
if (isNull _obj) exitWith {
_isOk = false;
_proceed = false;
};
format[localize "str_epoch_player_163",_nameVehicle,(_counter + 1),_limit] call dayz_rollingMessages;
format[localize "str_epoch_player_163", _nameVehicle, (_counter + 1), _limit] call dayz_rollingMessages; // De-constructing %1, stage %2 of %3 walk away at anytime to cancel.
[player,(getPosATL player),25,"repair"] spawn fnc_alertZombies;
[player, (getPosATL player), 25, "repair"] spawn fnc_alertZombies;
_finished = ["Medic",1] call fn_loopAction;
local _finished = ["Medic", 1] call fn_loopAction;
if(!_finished) exitWith {
if (!_finished) exitWith {
_isOk = false;
_proceed = false;
};
if(_finished) then {
if (_finished) then {
_counter = _counter + 1;
// 4% chance to break a required tool each pass
if ((_isDestructable || _isRemovable) && {!_isOwnerOfObj} && {dayz_toolBreaking && {[0.04] call fn_chance}}) then {
_brokenTool = true;
if (dayz_toolBreaking) then {
if ((_isDestructable || _isRemovable) && !_isOwnerOfObj) then {
if ([0.04] call fn_chance) then { // 4% chance to break a required tool each pass
_brokenTool = true;
};
};
};
};
if(_brokenTool) exitWith {
if (_brokenTool) exitWith {
_isOk = false;
_proceed = false;
};
if(_counter == _limit) exitWith {
if (_counter == _limit) exitWith {
_isOk = false;
_proceed = true;
};
};
_success = true;
[] call fn_displayHelpers; // delete helpers
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// tool breakage
//
///////////////////////////////////////////////////////////////////////////////////////////////////
local _success = true;
if (_brokenTool) then {
_success = false;
_removeTool = if (_isWreck) then {"ItemToolbox"} else {["ItemCrowbar","ItemToolbox"] call BIS_fnc_selectRandom};
local _removeTool = if (_isWreck) then {"ItemToolbox"} else {["ItemCrowbar","ItemToolbox"] call BIS_fnc_selectRandom};
if (_removeTool == "ItemCrowbar" && !("ItemCrowbar" in items player)) then {
if ("MeleeCrowbar" in weapons player) then {
player removeWeapon "MeleeCrowbar";
_success = true;
} else {
if (dayz_onBack == "MeleeCrowbar") then {
dayz_onBack = ""; // Remove
player setVariable ["dayz_onBack",dayz_onBack,true];
dayz_onBack = ""; // Remove item
player setVariable ["dayz_onBack", dayz_onBack, true];
_success = true;
if (!isNull (findDisplay 106)) then {((findDisplay 106) displayCtrl 1209) ctrlSetText "";};
};
};
} else {
if (([player,_removeTool,1] call BIS_fnc_invRemove) > 0) then {_success = true;};
if (([player, _removeTool, 1] call BIS_fnc_invRemove) > 0) then {_success = true;};
};
if (_success) then {
format[localize "str_epoch_player_164",getText(configFile >> "CfgWeapons" >> _removeTool >> "displayName"),_nameVehicle] call dayz_rollingMessages;
format[localize "str_epoch_player_164", getText(configFile >> "CfgWeapons" >> _removeTool >> "displayName"), _nameVehicle] call dayz_rollingMessages; // %1 broke, cannot remove %2.
};
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// find refund depending on object category
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// Remove only if player waited AND tool was successfully removed if broken
if (_proceed && _success) then {
// Double check that object is not null
if(!isNull(_obj)) then {
_ipos = getPosATL _obj;
if !(isNull _obj) then {
if(!_isWreck && !_isWreckBuilding) then {
//Server performs deleteVehicle
PVDZ_obj_Destroy = [_objectID,_objectUID,player,_obj,dayz_authKey];
local _objectPos = getPosATL _obj; // copy now before object deleted
local _iPos = _objectPos; // default refund position
local _iDir = getDir _obj; // default refund direction
local _selectedRemoveOutput = []; // initialize refund array
local _preventRefund = false; // in case object has no id
local _bpTotal = 0; // total number of backpacks to refund
call {
///////////////////////////////////////////////////////////////////////////
//
// dynamic debris wreckage
//
///////////////////////////////////////////////////////////////////////////
if (_isWreck) exitWith {
// Find one random part to refund
local _refundpart = ["PartEngine","PartGeneric","PartFueltank","PartWheel","PartGlass","ItemJerrycan"] call BIS_fnc_selectRandom;
_selectedRemoveOutput = [[_refundpart, 1]];
};
local _lootGroupIndex = dz_loot_groups find _objType;
local _output = [];
///////////////////////////////////////////////////////////////////////////
//
// metal vein wreck
//
///////////////////////////////////////////////////////////////////////////
if (_isMine) exitWith {
_output = [_lootGroupIndex, 3] call dz_fn_loot_select;
{_selectedRemoveOutput set [count _selectedRemoveOutput, [_x select 1, [_x select 2, _x select 3]]]} forEach _output;
// chance of gem occurrence
if ([0.4] call fn_chance) then {
local _gems = [];
local _weights = [];
{
_gems set [count _gems, _x select 0];
_weights set [count _weights, _x select 1];
} count DZE_GemOccurance;
local _gemSelected = [_gems, _weights] call BIS_fnc_selectRandomWeighted;
_selectedRemoveOutput set [count _selectedRemoveOutput, [_gemSelected, 1]];
};
};
///////////////////////////////////////////////////////////////////////////
//
// roadside ammo crate
//
///////////////////////////////////////////////////////////////////////////
if (_isAmmoSupplyWreck) exitWith {
_output = [_lootGroupIndex, 5] call dz_fn_loot_select;
{_selectedRemoveOutput set [count _selectedRemoveOutput, [_x select 1, 1, _x select 0]]} forEach _output;
};
///////////////////////////////////////////////////////////////////////////
//
// wrecked modular object
//
///////////////////////////////////////////////////////////////////////////
if (_isWreckBuilding) exitWith {
_selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
};
///////////////////////////////////////////////////////////////////////////
//
// modular object
//
///////////////////////////////////////////////////////////////////////////
if (_modularRefund) exitWith {
{_selectedRemoveOutput set [count _selectedRemoveOutput, _x]} forEach _refund;
_preventRefund = _hasNoID;
};
///////////////////////////////////////////////////////////////////////////
//
// non-lockable storage item
//
///////////////////////////////////////////////////////////////////////////
if (_isStorageItem) exitWith {
if (!_hasNoID) then {
_selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput"); // refund config array
};
local _weapons = getWeaponCargo _obj;
local _magazines = getMagazineCargo _obj;
local _backpacks = getBackpackCargo _obj;
if ((count _weapons > 0 || {count _magazines > 0 || {count _backpacks > 0}})) then { // has storage items
// reformat cargo arrays into [class, count, type] and append to _selectedRemoveOutput
local _format = [[_weapons,2],[_magazines,3],[_backpacks,5]];
{
local _class = _x select 0 select 0; // weapon, magazine, or backpack
local _total = _x select 0 select 1; // count array
local _type = _x select 1; // item type
local _array = [];
{
_count = _total select _forEachIndex;
_array = [_x, _count, _type]; // format array
_selectedRemoveOutput set [count _selectedRemoveOutput, _array]; // append to output
if (_type == 5) then {_bpTotal = _bpTotal + _count}; // update backpack count
} forEach _class;
} count _format;
};
};
///////////////////////////////////////////////////////////////////////////
//
// All other removable objects
//
///////////////////////////////////////////////////////////////////////////
_selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput"); // refund config array
_preventRefund = _hasNoID;
};
call {
///////////////////////////////////////////////////////////////////////////
//
// check if plot pole helpers remain
//
///////////////////////////////////////////////////////////////////////////
if (_isPlotPole) exitWith {
if (!isNil "PP_Marks") then {
{deleteVehicle _x;} count PP_Marks;
PP_Marks = nil;
};
};
///////////////////////////////////////////////////////////////////////////
//
// check if fire barrel was left burning
//
///////////////////////////////////////////////////////////////////////////
if (_isFireBarrel) exitWith {
local _flame = nearestObjects [_obj, ["flamable_DZ"], 1]; // check for inflamed objects
if (count _flame > 0) then { // if any
_flame = (_flame select 0); // get nearest (typeName changes from "ARRAY" to "OBJECT")
_flame inflame false; // extinguish flame
deleteVehicle _flame; // delete proxy object
};
};
};
///////////////////////////////////////////////////////////////////////////////////
//
// delete object from database
//
///////////////////////////////////////////////////////////////////////////////////
if (!_isWreck && !_isWreckBuilding) then {
// Server performs deleteVehicle
PVDZ_obj_Destroy = [_objectID, _objectUID, player, _obj, dayz_authKey];
publicVariableServer "PVDZ_obj_Destroy";
} else {
deleteVehicle _obj;
};
if (_isWreckBuilding) then {
PVDZ_send = [player,"RemoveObject",_ipos,[_ipos,dayz_authKey,player]];
PVDZ_send = [player, "RemoveObject", _objectPos, [_objectPos, dayz_authKey, player]];
publicVariableServer "PVDZ_send";
};
format[localize "str_epoch_player_165",_nameVehicle] call dayz_rollingMessages;
//format[localize "str_epoch_player_165", _nameVehicle] call dayz_rollingMessages; // De-constructing %1.
["Working",0,[3,2,4,0]] call dayz_NutritionSystem;
_preventRefund = false;
_selectedRemoveOutput = [];
if(_isWreck) then {
// Find one random part to give back
_refundpart = ["PartEngine","PartGeneric","PartFueltank","PartWheel","PartGlass","ItemJerrycan"] call BIS_fnc_selectRandom;
_selectedRemoveOutput set [count _selectedRemoveOutput,[_refundpart,1]];
} else {
if(_isWreckBuilding) then {
call {
if (_isMine) exitwith {
_lootGroupIndex = dz_loot_groups find _objType;
_output = [_lootGroupIndex,3] call dz_fn_loot_select;
///////////////////////////////////////////////////////////////////////////////////
//
// prepare refund and backpack array
//
///////////////////////////////////////////////////////////////////////////////////
{_selectedRemoveOutput set [count _selectedRemoveOutput, [_x select 1,[_x select 2,_x select 3]]]} forEach _output;
};
if (_objType == "Land_ammo_supply_wreck") exitwith {
_lootGroupIndex = dz_loot_groups find _objType;
_output = [_lootGroupIndex,5] call dz_fn_loot_select;
if (!_preventRefund && {count _selectedRemoveOutput > 0}) then {
{_selectedRemoveOutput set [count _selectedRemoveOutput, [_x select 1,1,_x select 0]]} forEach _output;
};
_selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
};
} else {
if ({_objType in _x} count DZE_modularConfig > 0) then {
{
private ["_class", "_refund"];
local _item = "WeaponHolder" createVehicle [0,0,0];
_item setDir _iDir;
_class = _x select 0;
_refund = _x select 1;
if (_objType == _class) then {
{_selectedRemoveOutput set [count _selectedRemoveOutput,_x];} forEach _refund;
};
} count DZE_modularConfig;
} else {
_selectedRemoveOutput = getArray (configFile >> "CfgVehicles" >> _objType >> "removeoutput");
};
_preventRefund = (_objectID == "0" && _objectUID == "0");
if ((player distance _objectPos) > 1.5) then { // if player was not close to the object
_iDir = [player, _objectPos] call BIS_fnc_dirTo; // update direction
_iPos = [player, 1.5, _iDir] call BIS_fnc_relPos; // update position
};
};
_iPos set [2, ((getPosATL player) select 2) max 0]; // Match refund height to player height, or place on ground
if ((count _selectedRemoveOutput) <= 0) then {
[localize "str_epoch_player_90",1] call dayz_rollingMessages;
};
local _bpDir = floor(random 360); // backpack rotation angle around refund point
local _bpArc = 360 / (_bpTotal max 1); // angle between each backpack (prevents divide by zero)
local _bbMin = ((_bbObject select 0) min (_bbObject select 1)) * 0.5; // 50% of storage object's smallest x,y dimension
local _bpDist = (_bbMin max 0.3) min 0.75; // clamp min/max radial distance from WeaponHolder to backpack pivot point
local _playerPos= getPosATL player;
if (_isMine) then {
if((random 10) <= 4) then {
private ["_gems","_weights","_gemSelected"];
_gems = [];
_weights = [];
local _isInside = { // procedure to check whether the supplied position is inside a building's bounding box
local _pos = _this;
local _inside = false;
{
_gems set [(count _gems), (_x select 0)];
_weights set [(count _weights), (_x select 1)];
} count DZE_GemOccurance;
_gemSelected = [_gems, _weights] call BIS_fnc_selectRandomWeighted;
_selectedRemoveOutput set [(count _selectedRemoveOutput),[_gemSelected,1]];
};
};
local _building = _x;
// give refund items
if((count _selectedRemoveOutput) > 0 && !_preventRefund) then {
private "_posPlayer";
if (_building != _item) then { // exclude WeaponHolder when placing backpacks
local _relPos = _building worldToModel _pos;
_posPlayer = getPosATL player;
_iPos set [2,_posPlayer select 2];
local _max = (boundingBox _building) select 1;
local _px = _max select 0;
local _py = _max select 1;
local _pz = _max select 2;
local _myX = abs (_relPos select 0);
local _myY = abs (_relPos select 1);
local _myZ = abs (_relPos select 2);
if (_iPos select 2 < 0) then {
_iPos set [2,0];
if ((_myX < _px) && {(_myY < _py) && {(_myZ < _pz)}}) then {
_inside = true;
};
};
if (_inside) exitWith {};
} forEach (nearestObjects [_pos, ["Building"], 50]); // scan every "Building" class within 50m
_inside;
};
_item = "WeaponHolder" createVehicle [0,0,0];
if (_isStorageItem && (_iPos call _isInside)) then {
_iPos = _playerPos;
_bpDist = 0.1;
};
///////////////////////////////////////////////////////////////////////////
//
// refund items
//
///////////////////////////////////////////////////////////////////////////
local _totalCount = 0; // total number of refunded items
{
_itemOut = _x select 0;
_countOut = _x select 1;
if (typeName _countOut == "ARRAY") then {
_countOut = round((random (_countOut select 1)) max (_countOut select 0));
local _itemOut = _x select 0; // item to refund
local _countOut = _x select 1; // how many
if (typeName _countOut == "ARRAY") then { // check for random refund range
local _min = _countOut select 0;
local _max = _countOut select 1;
local _range = (abs (_max - _min)) + 1; // add 1 because range is numerically inclusive
_countOut = (floor (random _range)) + _min; // randomize
};
if (count _x > 2) then {
_type = _x select 2;
_totalCount = _totalCount + _countOut; // running total of items
if (count _x > 2) then { // if array item has 3 elements
local _type = _x select 2; // get corresponding cargo type
call {
if (_type == 2) exitwith {_item addWeaponCargoGlobal [_itemOut,_countOut]};
if (_type == 3) exitwith {_item addMagazineCargoGlobal [_itemOut,_countOut]};
if (_type == 5) exitwith {_item addBackpackCargoGlobal [_itemOut,_countOut]}; // Needs to make sure object can handle Backpacks or will dump on the ground.
if (_type == 2) exitWith {_item addWeaponCargoGlobal [_itemOut, _countOut]};
if (_type == 3) exitWith {_item addMagazineCargoGlobal [_itemOut, _countOut]};
if (_type == 5) exitWith { //_item addBackpackCargoGlobal [_itemOut, _countOut]; // Needs to make sure object can handle Backpacks or will dump on the ground.
for "_i" from 1 to _countOut do {
local _bpObj = _itemOut createVehicle [0,0,0]; // create backpack
local _bpPos = [_iPos, _bpDist, _bpDir] call BIS_fnc_relPos; // position it a short distance away from the spawn point
_bpObj setVectorDirAndUp [
[0, 0, -1], // lay it flat
[[0, 1, 0], -_bpDir] call BIS_fnc_rotateVector2D // align to holder
];
_bpPos set [2, ((_bpPos select 2) max 0) - 0.15]; // match holder height or place on ground (lowered slightly)
if (_bpPos call _isInside) then {
_bpObj setPosATL _playerPos; // prevent backpack from spawning inside an unenterable building
} else {
_bpObj setPosATL _bpPos; // location is good
};
_bpDir = (_bpDir + _bpArc) % 360; // arrange backpacks evenly
};
};
};
} else {
_item addMagazineCargoGlobal [_itemOut,_countOut];
_item addMagazineCargoGlobal [_itemOut, _countOut]; // default magazine cargo
};
} count _selectedRemoveOutput;
_item setposATL _iPos;
player reveal _item;
DZE_GearCheckBypass = true; //Bypass gear menu checks since dialog will always open on item
player action ["Gear", _item];
if (_totalCount > 0) then { // Only reveal refund if there is something there. Random ranges can produce zero results.
_item setPosATL _iPos;
player reveal _item;
DZE_GearCheckBypass = true; // Bypass gear menu checks since dialogue will always open on item
player action ["Gear", _item];
};
} else {
[localize "str_epoch_player_90", 1] call dayz_rollingMessages; // No parts were found.
};
} else {
localize "str_epoch_player_91" call dayz_rollingMessages;
localize "str_epoch_player_91" call dayz_rollingMessages; // Failed, object no longer exists.
};
};
dayz_actionInProgress = false;
s_player_deleteBuild = -1;
dayz_actionInProgress = false;
s_player_deleteBuild = -1;
s_player_deconstruct = -1;
s_player_upgrade_build = -1;
s_player_maint_build = -1;