From 03353b94831ce1acdeea60392a8d8d27d38be04c Mon Sep 17 00:00:00 2001 From: ebaydayz Date: Wed, 24 Feb 2016 20:56:13 -0500 Subject: [PATCH] Add lock and unlock vehicle from inside See: #1103 Made vehicle gear always accessible from inside. Also added optional variable to prevent stealing from backpacks by non-friendlies at traders. Thanks to @maca134 for the method. --- CHANGE LOG 1.0.6.txt | 2 + SQF/dayz_code/actions/hotwire_veh.sqf | 3 + SQF/dayz_code/actions/lock_veh.sqf | 3 + SQF/dayz_code/actions/unlock_veh.sqf | 3 + SQF/dayz_code/compile/fn_gearMenuChecks.sqf | 39 +++++++------ SQF/dayz_code/compile/fn_selfActions.sqf | 62 +++++++++++++++------ SQF/dayz_code/init/compiles.sqf | 17 ++++++ SQF/dayz_code/init/variables.sqf | 5 ++ SQF/dayz_epoch_b/stringtable.xml | 10 ++++ 9 files changed, 109 insertions(+), 35 deletions(-) diff --git a/CHANGE LOG 1.0.6.txt b/CHANGE LOG 1.0.6.txt index 87903b884..16cc8b317 100644 --- a/CHANGE LOG 1.0.6.txt +++ b/CHANGE LOG 1.0.6.txt @@ -12,6 +12,8 @@ [NEW] Weapon switch hotkeys (1 = primary, 2 = pistol, 3 = melee) from DayZ Mod #1673 @ebaydayz [NEW] Added waves effect during stormy weather #974 @FramedYannick @ebaydayz [NEW] Optional variable to restrict wearable clothes. Add DZE_RestrictSkins to init.sqf #1560 @BetterDeadThanZed @ebaydayz +[NEW] Optional variable to prevent stealing from backpacks by non-friendlies at traders. Add DZE_BackpackAntiTheft to init.sqf @ebaydayz +[NEW] Added action to lock and unlock vehicles from inside #1103 @pj999 @ebaydayz [CHANGED] An infection chance of -1 disables self-transfusion infection. 0 is always infected. (DZE_selfTransfuse_Values) @icomrade [CHANGED] Removed weapons from Traders hands and made them stand with arms by their side. @SilvDev diff --git a/SQF/dayz_code/actions/hotwire_veh.sqf b/SQF/dayz_code/actions/hotwire_veh.sqf index 3f555697e..0ccbc6c1e 100644 --- a/SQF/dayz_code/actions/hotwire_veh.sqf +++ b/SQF/dayz_code/actions/hotwire_veh.sqf @@ -6,6 +6,8 @@ DZE_ActionInProgress = true; {player removeAction _x} count s_player_lockunlock;s_player_lockunlock = []; s_player_lockUnlock_crtl = 1; +{DZE_myVehicle removeAction _x} count s_player_lockUnlockInside;s_player_lockUnlockInside = []; +s_player_lockUnlockInside_ctrl = -1; _removed = ([player,"ItemHotwireKit",1] call BIS_fnc_invRemove); @@ -28,4 +30,5 @@ if (_removed == 1) then { }; s_player_lockUnlock_crtl = -1; +s_player_lockUnlockInside_ctrl = -1; DZE_ActionInProgress = false; \ No newline at end of file diff --git a/SQF/dayz_code/actions/lock_veh.sqf b/SQF/dayz_code/actions/lock_veh.sqf index 895af6398..5a597fb52 100644 --- a/SQF/dayz_code/actions/lock_veh.sqf +++ b/SQF/dayz_code/actions/lock_veh.sqf @@ -6,6 +6,8 @@ DZE_ActionInProgress = true; {player removeAction _x} count s_player_lockunlock;s_player_lockunlock = []; s_player_lockUnlock_crtl = 1; +{DZE_myVehicle removeAction _x} count s_player_lockUnlockInside;s_player_lockUnlockInside = []; +s_player_lockUnlockInside_ctrl = -1; PVDZE_veh_Lock = [_vehicle,true]; if(player distance _vehicle < 10) then { @@ -17,4 +19,5 @@ if(player distance _vehicle < 10) then { }; s_player_lockUnlock_crtl = -1; +s_player_lockUnlockInside_ctrl = -1; DZE_ActionInProgress = false; \ No newline at end of file diff --git a/SQF/dayz_code/actions/unlock_veh.sqf b/SQF/dayz_code/actions/unlock_veh.sqf index 6fd5ac3ac..84eb31717 100644 --- a/SQF/dayz_code/actions/unlock_veh.sqf +++ b/SQF/dayz_code/actions/unlock_veh.sqf @@ -7,6 +7,8 @@ DZE_ActionInProgress = true; {player removeAction _x} count s_player_lockunlock;s_player_lockunlock = []; s_player_lockUnlock_crtl = 1; +{DZE_myVehicle removeAction _x} count s_player_lockUnlockInside;s_player_lockUnlockInside = []; +s_player_lockUnlockInside_ctrl = -1; PVDZE_veh_Lock = [_vehicle,false]; if(player distance _vehicle < 10) then { @@ -20,4 +22,5 @@ if(player distance _vehicle < 10) then { }; s_player_lockUnlock_crtl = -1; +s_player_lockUnlockInside_ctrl = -1; DZE_ActionInProgress = false; \ No newline at end of file diff --git a/SQF/dayz_code/compile/fn_gearMenuChecks.sqf b/SQF/dayz_code/compile/fn_gearMenuChecks.sqf index 2f5b24fae..ab36609ba 100644 --- a/SQF/dayz_code/compile/fn_gearMenuChecks.sqf +++ b/SQF/dayz_code/compile/fn_gearMenuChecks.sqf @@ -1,20 +1,23 @@ -private ["_cTarget","_isOk","_Dis","_display","_inVehicle"]; -disableSerialization; -_display = (_this select 0); -_inVehicle = (vehicle player) != player; -_cTarget = cursorTarget; -if(_inVehicle) then { - _cTarget = (vehicle player); -}; +private ["_cTarget","_dis","_display","_friendlies","_rcharID"]; -_isOk = false; -{ - if(!_isOk) then { - _isOk = _cTarget isKindOf _x; +// players inside vehicle can always access its gear +if ((vehicle player) == player) then { + disableSerialization; + _display = _this select 0; + _cTarget = cursorTarget; + _dis = if (_cTarget isKindOf "USEC_ch53_E" || _cTarget isKindOf "MV22") then {25} else {12}; + + if ((locked _cTarget) && {(_cTarget isKindOf "LandVehicle") or {_cTarget isKindOf "Air"} or {_cTarget isKindOf "Ship"}} && {(player distance _cTarget) < _dis}) then { + cutText [(localize "str_epoch_player_7"),"PLAIN DOWN"]; + _display closeDisplay 1; }; -} count ["LandVehicle","Air", "Ship"]; -_Dis = if (_cTarget isKindOf "USEC_ch53_E" || _cTarget isKindOf "MV22") then {25} else {12}; -if((locked _cTarget) && _isOk && (((vehicle player) distance _cTarget) < _Dis)) then { - cutText [(localize "str_epoch_player_7") , "PLAIN DOWN"]; - _display closeDisplay 1; -}; + + if (DZE_BackpackAntiTheft) then { + _friendlies = player getVariable ["friendlies",[]]; + _rcharID = _cTarget getVariable ["CharacterID","0"]; + if ((!canbuild) && {_cTarget isKindOf "Man"} && {alive _cTarget} && {!((typeOf _cTarget) in serverTraders)} && {!(_rcharID in _friendlies)} && {(player distance _cTarget) < 12}) then { + cutText [(localize "STR_EPOCH_PLAYER_316"),"PLAIN DOWN"]; + _display closeDisplay 1; + }; + }; +}; \ No newline at end of file diff --git a/SQF/dayz_code/compile/fn_selfActions.sqf b/SQF/dayz_code/compile/fn_selfActions.sqf index 6fa1cc04d..ebde6ee96 100644 --- a/SQF/dayz_code/compile/fn_selfActions.sqf +++ b/SQF/dayz_code/compile/fn_selfActions.sqf @@ -4,11 +4,12 @@ scriptName "Functions\misc\fn_selfActions.sqf"; - Function - [] call fnc_usec_selfActions; ************************************************************/ -private ["_isWreckBuilding","_temp_keys","_magazinesPlayer","_isPZombie","_vehicle","_inVehicle","_hasFuelE","_hasRawMeat","_hasKnife","_hasToolbox","_onLadder","_nearLight","_canPickLight","_canDo","_text","_isHarvested","_isVehicle","_isVehicletype","_isMan","_traderType","_ownerID","_isAnimal","_isDog","_isZombie","_isDestructable","_isTent","_isFuel","_isAlive","_Unlock","_lock","_buy","_dogHandle","_lieDown","_warn","_hastinitem","_allowedDistance","_menu","_menu1","_humanity_logic","_low_high","_cancel","_metals_trader","_traderMenu","_isWreck","_isRemovable","_isDisallowRepair","_rawmeat","_humanity","_speed","_dog","_hasbottleitem","_isAir","_isShip","_playersNear","_findNearestGens","_findNearestGen","_IsNearRunningGen","_cursorTarget","_isnewstorage","_itemsPlayer","_ownerKeyId","_typeOfCursorTarget","_hasKey","_oldOwner","_combi","_key_colors","_player_deleteBuild","_player_flipveh","_player_lockUnlock_crtl","_player_butcher","_player_studybody","_player_cook","_player_boil","_hasFuelBarrelE","_hasHotwireKit","_player_SurrenderedGear","_isSurrendered","_isModular","_isModularDoor","_ownerKeyName","_temp_keys_names","_hasAttached","_allowTow","_liftHeli","_found","_posL","_posC","_height","_liftHelis","_attached"]; +private ["_isWreckBuilding","_temp_keys","_magazinesPlayer","_isPZombie","_vehicle","_inVehicle","_hasFuelE","_hasRawMeat","_hasKnife","_hasToolbox","_onLadder","_nearLight","_canPickLight","_canDo","_text","_isHarvested","_isVehicle","_isVehicletype","_isMan","_traderType","_ownerID","_isAnimal","_isDog","_isZombie","_isDestructable","_isTent","_isFuel","_isAlive","_Unlock","_lock","_buy","_dogHandle","_lieDown","_warn","_hastinitem","_allowedDistance","_menu","_menu1","_humanity_logic","_low_high","_cancel","_metals_trader","_traderMenu","_isWreck","_isRemovable","_isDisallowRepair","_rawmeat","_humanity","_speed","_dog","_hasbottleitem","_isAir","_isShip","_playersNear","_findNearestGens","_findNearestGen","_IsNearRunningGen","_cursorTarget","_isnewstorage","_itemsPlayer","_typeOfCursorTarget","_hasKey","_oldOwner","_combi","_player_deleteBuild","_player_flipveh","_player_lockUnlock_crtl","_player_butcher","_player_studybody","_player_cook","_player_boil","_hasFuelBarrelE","_hasHotwireKit","_player_SurrenderedGear","_isSurrendered","_isModular","_isModularDoor","_temp_keys_names","_hasAttached","_allowTow","_liftHeli","_found","_posL","_posC","_height","_liftHelis","_attached","_vehicleOwnerID","_totalKeys"]; if (DZE_ActionInProgress) exitWith {}; // Do not allow if any script is running. _vehicle = vehicle player; +_vehicleOwnerID = _vehicle getVariable ["CharacterID","0"]; _isPZombie = player isKindOf "PZombie_VB"; _inVehicle = (_vehicle != player); @@ -37,6 +38,44 @@ if (_canPickLight && !dayz_hasLight && !_isPZombie) then { s_player_removeflare = -1; }; +if (_inVehicle && {_vehicleOwnerID != "0"} && {!(_vehicle isKindOf "Bicycle")}) then { + if (s_player_lockUnlockInside_ctrl < 0) then { + DZE_myVehicle = _vehicle; + _totalKeys = call epoch_tempKeys; + _temp_keys = _totalKeys select 0; + _temp_keys_names = _totalKeys select 1; + _hasKey = _vehicleOwnerID in _temp_keys; + _oldOwner = (_vehicleOwnerID == dayz_playerUID); + _text = getText (configFile >> "CfgVehicles" >> (typeOf DZE_myVehicle) >> "displayName"); + if (locked DZE_myVehicle) then { + if (_hasKey || _oldOwner) then { + _Unlock = DZE_myVehicle addAction [format[localize "STR_EPOCH_ACTIONS_UNLOCK",_text], "\z\addons\dayz_code\actions\unlock_veh.sqf",[DZE_myVehicle,(_temp_keys_names select (parseNumber _vehicleOwnerID))], 2, true, true, "", ""]; + s_player_lockUnlockInside set [count s_player_lockUnlockInside,_Unlock]; + s_player_lockUnlockInside_ctrl = 1; + } else { + if (_hasHotwireKit) then { + _Unlock = DZE_myVehicle addAction [format[localize "STR_EPOCH_ACTIONS_HOTWIRE",_text], "\z\addons\dayz_code\actions\hotwire_veh.sqf",DZE_myVehicle, 2, true, true, "", ""]; + } else { + _Unlock = DZE_myVehicle addAction [format["%1",localize "STR_EPOCH_ACTIONS_VEHLOCKED"], "",DZE_myVehicle, 2, true, true, "", ""]; + }; + s_player_lockUnlockInside set [count s_player_lockUnlockInside,_Unlock]; + s_player_lockUnlockInside_ctrl = 1; + }; + } else { + if (_hasKey || _oldOwner) then { + _lock = DZE_myVehicle addAction [format[localize "STR_EPOCH_ACTIONS_LOCK",_text], "\z\addons\dayz_code\actions\lock_veh.sqf",DZE_myVehicle, 1, true, true, "", ""]; + s_player_lockUnlockInside set [count s_player_lockUnlockInside,_lock]; + s_player_lockUnlockInside_ctrl = 1; + }; + }; + }; +} else { + if (!isNil "DZE_myVehicle") then { + {DZE_myVehicle removeAction _x} count s_player_lockUnlockInside;s_player_lockUnlockInside = []; + s_player_lockUnlockInside_ctrl = -1; + }; +}; + if (DZE_HeliLift) then { _hasAttached = _vehicle getVariable["hasAttached",false]; if(_inVehicle && (_vehicle isKindOf "Air") && ((([_vehicle] call FNC_getPos) select 2) < 30) && (speed _vehicle < 5) && (typeName _hasAttached == "OBJECT")) then { @@ -143,22 +182,8 @@ if (!isNull cursorTarget && !_inVehicle && !_isPZombie && (player distance curso _hasHotwireKit = "ItemHotwireKit" in _magazinesPlayer; _itemsPlayer = items player; - - _temp_keys = []; - _temp_keys_names = []; - // find available keys - _key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"]; - { - if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in _key_colors) then { - _ownerKeyId = getNumber(configFile >> "CfgWeapons" >> _x >> "keyid"); - _ownerKeyName = getText(configFile >> "CfgWeapons" >> _x >> "displayName"); - _temp_keys_names set [_ownerKeyId,_ownerKeyName]; - _temp_keys set [count _temp_keys,str(_ownerKeyId)]; - }; - } count _itemsPlayer; - - _hasKnife = "ItemKnife" in _itemsPlayer; - _hasToolbox = "ItemToolbox" in _itemsPlayer; + _hasKnife = "ItemKnife" in _itemsPlayer; + _hasToolbox = "ItemToolbox" in _itemsPlayer; _isMan = _cursorTarget isKindOf "Man"; _traderType = _typeOfCursorTarget; @@ -315,6 +340,9 @@ if (!isNull cursorTarget && !_inVehicle && !_isPZombie && (player distance curso // Allow Owner to lock && unlock vehicle if(_player_lockUnlock_crtl) then { if (s_player_lockUnlock_crtl < 0) then { + _totalKeys = call epoch_tempKeys; + _temp_keys = _totalKeys select 0; + _temp_keys_names = _totalKeys select 1; _hasKey = _ownerID in _temp_keys; _oldOwner = (_ownerID == dayz_playerUID); if(locked _cursorTarget) then { diff --git a/SQF/dayz_code/init/compiles.sqf b/SQF/dayz_code/init/compiles.sqf index 7c26b36db..1bd1383b0 100644 --- a/SQF/dayz_code/init/compiles.sqf +++ b/SQF/dayz_code/init/compiles.sqf @@ -163,6 +163,23 @@ if (!isDedicated) then { dayz_hunger = dayz_hunger + (_this select 0); dayz_thirst = dayz_thirst + (_this select 1); }; + + epoch_tempKeys = { + private ["_temp_keys","_temp_keys_names","_key_colors","_ownerKeyId","_ownerKeyName"]; + _temp_keys = []; + _temp_keys_names = []; + // find available keys + _key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"]; + { + if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in _key_colors) then { + _ownerKeyId = getNumber(configFile >> "CfgWeapons" >> _x >> "keyid"); + _ownerKeyName = getText(configFile >> "CfgWeapons" >> _x >> "displayName"); + _temp_keys_names set [_ownerKeyId,_ownerKeyName]; + _temp_keys set [count _temp_keys,str(_ownerKeyId)]; + }; + } count (items player); + [_temp_keys,_temp_keys_names] + }; epoch_totalCurrency = { // total currency diff --git a/SQF/dayz_code/init/variables.sqf b/SQF/dayz_code/init/variables.sqf index f6425eccf..613643bbd 100644 --- a/SQF/dayz_code/init/variables.sqf +++ b/SQF/dayz_code/init/variables.sqf @@ -258,6 +258,7 @@ dayz_resetSelfActions = { s_player_heli_lift = -1; s_player_heli_detach = -1; s_player_lockUnlock_crtl = -1; + s_player_lockUnlockInside_ctrl = -1; s_player_toggleSnap = -1; s_player_toggleSnapSelect = -1; s_player_toggleSnapSelectPoint=[]; @@ -269,6 +270,7 @@ call dayz_resetSelfActions; s_player_lastTarget = [objNull,objNull,objNull,objNull,objNull]; s_player_repairActions = []; s_player_lockunlock = []; +s_player_lockUnlockInside = []; // Custom s_player_madsci = []; @@ -564,6 +566,9 @@ if (isNil "DZE_checkNearbyRadius") then { if (isNil "DZE_RestrictSkins") then { DZE_RestrictSkins = []; }; +if (isNil "DZE_BackpackAntiTheft") then { + DZE_BackpackAntiTheft = false; +}; // needed on server if(isNil "DZE_PlotPole") then { DZE_PlotPole = [30,45]; diff --git a/SQF/dayz_epoch_b/stringtable.xml b/SQF/dayz_epoch_b/stringtable.xml index 40c202982..9d281e4d7 100644 --- a/SQF/dayz_epoch_b/stringtable.xml +++ b/SQF/dayz_epoch_b/stringtable.xml @@ -6084,6 +6084,16 @@ \n\n%1 est restreint. \n\n%1 je omezeno. + + \n\nYou may only access friends' gear in this area. + \n\nYou may only access friends' gear in this area. + \n\nSie können Zahn 'Freunde Zugriff nur in diesem Bereich. + \n\nВы можете получить доступ только к шестерню знакомого в этой области. + \n\nSólo se puede acceder engranaje amigos en esta área. + \n\nU mag alleen toegang tot versnelling vrienden 'op dit gebied. + \n\nVous ne pouvez accéder à des engins de vos amis dans ce domaine. + \n\nMůžete mít přístup pouze zařízení uživatele do této oblasti. + Repair Vehicle Repair Vehicle