Files
DayZ-Epoch/SQF/dayz_code/actions/object_disassembly.sqf
ebayShopper 42e00475d6 Add sender verification to publish and swap object
Continuation of 8035df0

This is important to have on publish to identify cheaters who spam
create objects in the database or create objects with bad inventory.

- Renamed variables to backport to vanilla
- Removed % and & due to code filtering in publicvariableval.txt

Changes in modular_build.sqf were the same as player_build.sqf.

Tested with building, upgrading buildable/vehicle/tent, downgrading,
buying a vehicle, destroying tent and removing an object.
2017-11-03 16:09:14 -04:00

166 lines
7.0 KiB
Plaintext

private ["_cursorTarget","_onLadder","_isWater","_alreadyRemoving","_characterID","_objectID","_objectUID","_ownerArray","_dir",
"_realObjectStillThere","_upgrade","_entry","_parent","_requiredParts","_requiredTools","_model","_toolsOK","_displayname",
"_whpos","_wh","_object","_vector","_dis","_puid","_variables"];
_cursorTarget = _this;
// ArmaA2 bug workaround: sometimes the object is null
if ((isNil "_cursorTarget") or {(isNull _cursorTarget)}) then {
_cursorTarget = nearestObjects [ player modelToWorld [0,1.5,0] , ["DZ_buildables","BuiltItems"], 1.5];
_cursorTarget = if (count _cursorTarget == 0) then { objNull } else { _cursorTarget select 0 };
};
if(isNull _cursorTarget) exitWith { localize "str_disassembleNoOption" call dayz_rollingMessages; };
//Normal blocked stuff
_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
_isWater = (surfaceIsWater (getPosATL player)) or dayz_isSwimming;
if(_isWater or _onLadder) exitWith { localize "str_water_ladder_cant_do" call dayz_rollingMessages; };
_alreadyRemoving = _cursorTarget getVariable["ObjectLocked",0];
if (_alreadyRemoving == 1) exitWith { localize "str_disassembleInProgress" call dayz_rollingMessages; };
if (dayz_actionInProgress) exitWith {localize "str_player_actionslimit" call dayz_rollingMessages;};
dayz_actionInProgress = true;
_cursorTarget setVariable["ObjectLocked",1,true];
_characterID = _cursorTarget getVariable ["characterID","0"];
_objectID = _cursorTarget getVariable ["ObjectID","0"];
_objectUID = _cursorTarget getVariable ["ObjectUID","0"];
_ownerArray = _cursorTarget getVariable ["ownerArray",[]];
_dir = round getDir _cursorTarget;
_vector = [vectorDir _cursorTarget,vectorUp _cursorTarget];
_pos = getposATL _cursorTarget;
if (((_vector select 1) select 2) - 1 > 0.001) then { _pos set [2,0]; };
_realObjectStillThere = true;
_upgrade = typeOf _cursorTarget;
_entry = configFile >> "CfgVehicles" >> _upgrade;
r_interrupt = false;
_disassemblyParts = [] + (getArray (_entry >> "Disassembly" >> "removedParts"));
_disassemblyReturnChance = getNumber (_entry >> "Disassembly" >> "removedChance");
for "_i" from 1 to 20 do {
_parent = inheritsFrom _entry;
_requiredParts = [] + (getArray (_parent >> "Upgrade" >> "requiredParts"));
_requiredTools = [] + (getArray (_parent >> "Upgrade" >> "requiredTools"));
_model = getText (_parent >> "model"); // model of parent
_displayname = getText (_entry >> "displayName"); // name of current
diag_log format["%1 - %2 - %3 - %4 - %5",_parent,_requiredParts,_requiredTools,_model,_displayname];
// check the tools needed
_toolsOK = true;
{
if (!(_x IN items player)) exitWith { _toolsOK = false; };
} count _requiredTools;
if (!_toolsOK) exitWith { format [localize "str_disassembleMissingTool",getText (configFile >> "CfgWeapons" >> _x >> "displayName"),_displayname] call dayz_rollingMessages; };
if (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "disableWeapons") == 0) then {
player playActionNow "Medic";
_dis=20;
[player,"tentpack",0,false,20] call dayz_zombieSpeak;
[player,_dis,true,(getPosATL player)] call player_alertZombies;
//wait animation starts and block
waitUntil {getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "disableWeapons") == 1};
};
if (_realObjectStillThere) then { // send to server the destroy request
_realObjectStillThere = false;
PVDZ_obj_Destroy = [_objectID,_objectUID,player,_cursorTarget,dayz_authKey];
publicVariableServer "PVDZ_obj_Destroy";
diag_log [diag_ticktime, __FILE__, "Networked object, request to destroy", PVDZ_obj_Destroy];
} else {
// remove object
deleteVehicle _cursorTarget;
};
_cursorTarget = objNull;
["Working",0,[20,40,15,0]] call dayz_NutritionSystem;
// check whether we reached the base class, for which no P3D is defined
if (count _requiredParts == 0) exitwith {
diag_log [diag_ticktime, __FILE__, "Dismantle terminated, last building deleted is:", _upgrade];
};
// create a weaponholder with dismissed parts
_whpos=player modelToWorld [2 * sin(30*_i), 2 * cos(30*_i), 0];
_whpos set [2,0];
_wh = createVehicle ["WeaponHolder", _whpos, [], 0, "CAN_COLLIDE"];
_wh setDir (30*_i);
_wh setPosATL _whpos;
{
//Never return _disassemblyParts_.
if (!(_x in _disassemblyParts)) then {
//Random other returned items.
if ([_disassemblyReturnChance] call fn_chance) then {
if (isClass (configFile >> "CfgMagazines" >> _x))
then { _wh addMagazineCargoGlobal [_x, 1]; }
else { _wh addWeaponCargoGlobal [_x, 1]; };
};
};
} forEach _requiredParts;
diag_log [diag_ticktime, __FILE__, "Pile created with:", _requiredParts];
// create the parent object locally
_upgrade = configName _parent;
if (getNumber(_parent >> "scope")==2) then {
_cursorTarget = _upgrade createVehicleLocal getMarkerpos "respawn_west";
_cursorTarget setVectorDirAndUp _vector;
_cursorTarget setPosATL _pos;
};
uiSleep 1.5;
if (r_interrupt) exitwith {
diag_log [diag_ticktime, __FILE__, "Operation interrupted, last building deleted is:", _upgrade];
};
_entry = _parent;
};
// wait animation ends
waitUntil {r_interrupt or (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "disableWeapons") == 0)};
if (r_interrupt and vehicle player == player) then {
[objNull, player, rSwitchMove,""] call RE;
player playActionNow "stop";
r_interrupt = false;
};
if (!_realObjectStillThere) then {
// current object is a local one, replace it by a networked one, with all attributes
// and request a HIVE save
if (!isNull _cursorTarget) then {
_upgrade = typeOf _cursorTarget;
deleteVehicle _cursorTarget;
if (getNumber(_parent >> "scope")==2) then {
_object = createVehicle [_upgrade, getMarkerpos "respawn_west", [], 0, "CAN_COLLIDE"];
//if (_object isKindOf "DZ_buildables") then { _object allowDamage false; };
_object setVectorDirAndUp _vector;
_object setPosATL _pos;
_puid = getPlayerUID player;
if (!(_puid in _ownerArray)) then {
_ownerArray set [ count _ownerArray, _puid ];
};
_object setVariable ["ownerArray",_ownerArray,true];
_variables = [[ "ownerArray", _ownerArray]];
_object setVariable ["characterID",_characterID,true];
PVDZ_obj_Publish = [dayz_characterID,_object,[_dir, _pos],_variables,player,dayz_authKey];
publicVariableServer "PVDZ_obj_Publish";
diag_log [diag_ticktime, __FILE__, "New Networked object, request to save to hive. PVDZ_obj_Publish:", PVDZ_obj_Publish];
/*
//Send maintenance info
PVDZ_veh_Save = [_object,"maintenance"];
publicVariableServer "PVDZ_veh_Save";*/
player reveal _object;
};
};
};
localize "str_disassembleDone" call dayz_rollingMessages;
_cursorTarget setVariable["ObjectLocked",0,true];
dayz_actionInProgress = false;