From e7dbc5dd4c398cab3ab37f07585d445d71a590d1 Mon Sep 17 00:00:00 2001 From: A Man Date: Mon, 11 Nov 2019 10:00:47 +0100 Subject: [PATCH] Adding basic pve support Around 50% of all servers are pve servers. This commit adds a basic support and prevent the player vs. player damage. Also if pve is enabled and DZE_BackpackAntiTheft too, the backpack anti theft is active for the whole server. --- CHANGE LOG 1.0.7.txt | 1 + SQF/dayz_code/compile/fn_damageHandler.sqf | 177 ++++++++++---------- SQF/dayz_code/compile/fn_gearMenuChecks.sqf | 6 +- SQF/dayz_code/configVariables.sqf | 1 + 4 files changed, 98 insertions(+), 87 deletions(-) diff --git a/CHANGE LOG 1.0.7.txt b/CHANGE LOG 1.0.7.txt index 3e8235bfc..ac04417e3 100644 --- a/CHANGE LOG 1.0.7.txt +++ b/CHANGE LOG 1.0.7.txt @@ -6,6 +6,7 @@ [NEW] Added new waterbottles from DayZ Mod. Icons made by @DeVloek. Fully functional with all actions. @AirwavesMan [NEW] All fuel containers can be emptied now. (276615a) @AirwavesMan [NEW] Different boxes of matches can be combined now. (bc75ad8) @AirwavesMan +[NEW] Adding a basic support for PVE Servers. This disables the PvP damage on the server. Disabled by default, configVariables.sqf/DZE_PVE_Mode @AirwavesMan [FIXED] Some more occurrences of zero_building interiors misaligned or at the wrong terrain height (eaaedf2, 048caa5) @ebayShopper [FIXED] Player could switch into gunner's seat of ArmoredSUV while the hatch was being closed (e89eebc) #2009 @TheFirstNoob diff --git a/SQF/dayz_code/compile/fn_damageHandler.sqf b/SQF/dayz_code/compile/fn_damageHandler.sqf index a22d2d3d4..dc78d018a 100644 --- a/SQF/dayz_code/compile/fn_damageHandler.sqf +++ b/SQF/dayz_code/compile/fn_damageHandler.sqf @@ -5,7 +5,7 @@ scriptName "Functions\misc\fn_damageHandler.sqf"; - Function - [unit, selectionName, damage, source, projectile] call fnc_usec_damageHandler; ************************************************************/ -private ["_end","_unit","_hit","_damage","_unconscious","_source","_ammo","_isMinor","_isHeadHit","_isPlayer","_isBandit","_punishment","_humanityHit","_myKills","_wpst","_sourceDist","_sourceWeap","_scale","_type","_rndPain","_hitPain","_wound","_isHit","_isbleeding","_rndBleed","_hitBleed","_isInjured","_lowBlood","_isCardiac","_chance","_falling","_model","_isZombieHit","_sourceType","_sourceVehicleType","_isMan","_isVehicle","_isLocal","_inVehicle"]; +private ["_end","_unit","_hit","_damage","_unconscious","_source","_ammo","_isMinor","_isHeadHit","_isPlayer","_isBandit","_punishment","_humanityHit","_myKills","_wpst","_sourceDist","_sourceWeap","_scale","_type","_rndPain","_hitPain","_wound","_isHit","_isbleeding","_rndBleed","_hitBleed","_isInjured","_lowBlood","_isCardiac","_chance","_falling","_model","_isZombieHit","_sourceType","_sourceVehicleType","_isMan","_isVehicle","_isLocal","_inVehicle","_vehicleArray","_isPZombie","_isScratched","_rndBleedChance"]; _unit = _this select 0; _hit = _this select 1; _damage = _this select 2; @@ -49,12 +49,12 @@ _falling = (((_hit == "legs") AND {(_source==_unit)}) AND {((_ammo=="") AND {(Da _end = false; if (!_falling) then { - if (_ammo == "" && _hit == "" && _inVehicle) then {_ammo = "Crash";}; + if (_ammo == "" && {_hit == ""} && {_inVehicle}) then {_ammo = "Crash";}; //No _ammo type exit, indirect/physics damage. if (_ammo == "") exitwith { _end = true; }; - + //If _source contains no object exit. But lets not exit if the unit returns player. Maybe its his own fault. - if (isNull _source && !(_ammo in ["Dragged","RunOver"])) then { + if (isNull _source && {!(_ammo in ["Dragged","RunOver"])}) then { _vehicleArray = nearestObjects [([vehicle _unit] call fnc_getPos),["Air","LandVehicle","Ship","TrapTripwireGrenade"],25]; //Don't exit if a drivable vehicle (or drivable vehicle wreck) is nearby, because vehicle explosions register as a null source if (({typeOf _x != "ParachuteWest"} count _vehicleArray) == 0) then { @@ -81,6 +81,8 @@ _isPZombie = _model isKindOf "PZombie_VB"; _isMan = _sourceType isKindOf "CAManBase"; _isPlayer = (isPlayer _source); +if (DZE_PVE_Mode && {_isPlayer} && {!_falling}) exitWith {}; + if (_unit == player) then { //Set player in combat _unit setVariable["startcombattimer", 1]; @@ -88,23 +90,23 @@ if (_unit == player) then { _unit setVariable["inCombat",true,true]; }; - if (_hit == "" && _ammo != "Crash") exitWith //Ignore none part dmg. Exit after processing humanity hit. Don't punish driver for damaging passenger in crash + if (_hit == "" && {_ammo != "Crash"}) exitWith //Ignore none part dmg. Exit after processing humanity hit. Don't punish driver for damaging passenger in crash { - if (!_isLocal && _isPlayer && alive player && !_isPZombie) then //Do not punish for shooting a player zombie + if (!_isLocal && {_isPlayer} && {alive player} && {!_isPZombie}) then //Do not punish for shooting a player zombie { _isBandit = (player getVariable["humanity",0]) <= -5000; //_isBandit = (_model in ["Bandit1_DZ","BanditW1_DZ"]); - + //if player is not free to shoot at inform server that _source shot at player - if (!_isBandit && !(player getVariable ["OpenTarget",false])) then + if (!_isBandit && {!(player getVariable ["OpenTarget",false])}) then { PVDZ_send = [(effectiveCommander vehicle _source),"OpenTarget",[]]; publicVariableServer "PVDZ_send"; }; - // Due to server errors or desync killing someone in a bandit skin with >-2000 humanity CAN occur. - // Attacker should not be punished for killing a Bandit skin under any circumstances. - // To prevent this we check for Bandit Skin. + // Due to server errors or desync killing someone in a bandit skin with >-2000 humanity CAN occur. + // Attacker should not be punished for killing a Bandit skin under any circumstances. + // To prevent this we check for Bandit Skin. // - Accidental Murder - \\ When wearing the garb of a non-civilian you are taking your life in your own hands // Attackers humanity should not be punished for killing a survivor who has shrouded his identity in military garb. @@ -122,9 +124,9 @@ if (_unit == player) then { if (_humanityHit < -800) then { _humanityHit = -800; }; - // In the case of outrageous damage (crashes, explosions, desync repeated headshots); cap the limit on humanity lost. + // In the case of outrageous damage (crashes, explosions, desync repeated headshots); cap the limit on humanity lost. - [(effectiveCommander vehicle _source),_humanityHit] spawn { + [(effectiveCommander vehicle _source),_humanityHit] spawn { private ["_source","_humanityHit"]; _source = _this select 0; _humanityHit = _this select 1; @@ -134,26 +136,30 @@ if (_unit == player) then { }; }; }; - + if (r_player_timeout == 0 && !_inVehicle) then { if (_ammo == "tranquiliser_bolt") then { r_player_timeout = 20 + round(random 60); [_unit] spawn { + private "_unit"; + _unit = _this select 0; - localize "str_player_tranquilized" call dayz_rollingMessages; + localize "str_player_tranquilized" call dayz_rollingMessages; [_unit,0.01] call fnc_usec_damageUnconscious; _unit setVariable ["NORRN_unconscious", true, true]; player setVariable["medForceUpdate",true,true]; }; }; - + if (_damage > 0.4) then { //Melee knockout system - if ((_isHeadHit) && (_ammo in ["Crowbar_Swing_Ammo","Bat_Swing_Ammo","Sledge_Swing_Ammo"])) then { + if ((_isHeadHit) && {_ammo in ["Crowbar_Swing_Ammo","Bat_Swing_Ammo","Sledge_Swing_Ammo"]}) then { r_player_timeout = 20 + round(random 60); [_unit] spawn { + private "_unit"; + _unit = _this select 0; - localize "str_actions_medical_knocked_out" call dayz_rollingMessages; + localize "str_actions_medical_knocked_out" call dayz_rollingMessages; [_unit,0.01] call fnc_usec_damageUnconscious; _unit setVariable ["NORRN_unconscious", true, true]; player setVariable["medForceUpdate",true,true]; @@ -161,7 +167,7 @@ if (_unit == player) then { }; }; }; - + //(vehicle _source != _source) does not work to detect if source unit is in a vehicle in HandleDamage EH _isVehicle = ({_sourceVehicleType isKindOf _x} count ["LandVehicle","Air","Ship"] > 0); @@ -170,46 +176,46 @@ if (_unit == player) then { _wpst = weaponState _source; _source setVariable ["lastloghit",diag_ticktime]; _sourceDist = round(_unit distance _source); - _sourceWeap = switch (true) do { - case (_ammo in ["PipeBomb","Mine","MineE"]): { format["with %1",_ammo] }; - case (_isVehicle) : { format ["with %1",_sourceVehicleType] }; - case (_ammo in MeleeAmmo) : { format ["with %2%1",_wpst select 0, if (_sourceDist>6) then {"suspicious weapon "} else {""}] }; - case (_wpst select 0 == "Throw") : { format ["with %1 thrown", _wpst select 3] }; - case (["Horn",currentWeapon _source] call fnc_inString) : { format ["with %1 suspicious", currentWeapon _source]}; - case ((_wpst select 0 == "") AND {_wpst select 4 == 0}) : { format ["with %1/%2 suspicious", primaryWeapon _source, _ammo] }; - case (_wpst select 0 != "") : { format ["with %1/%2 ", _wpst select 0, _ammo, _wpst select 4] }; - default { "with suspicious weapon" }; + _sourceWeap = call { + if (_ammo in ["PipeBomb","Mine","MineE"]) exitwith { format["with %1",_ammo] }; + if (_isVehicle) exitwith { format ["with %1",_sourceVehicleType] }; + if (_ammo in MeleeAmmo) exitwith { format ["with %2%1",_wpst select 0, if (_sourceDist>6) then {"suspicious weapon "} else {""}] }; + if (_wpst select 0 == "Throw") exitwith { format ["with %1 thrown", _wpst select 3] }; + if (["Horn",currentWeapon _source] call fnc_inString) exitwith { format ["with %1 suspicious", currentWeapon _source]}; + if ((_wpst select 0 == "") AND {_wpst select 4 == 0}) exitwith { format ["with %1/%2 suspicious", primaryWeapon _source, _ammo] }; + if (_wpst select 0 != "") exitwith { format ["with %1/%2 ", _wpst select 0, _ammo, _wpst select 4] }; + "with suspicious weapon"; }; - + PVDZ_sec_atp = [_unit, _source, _sourceWeap, _sourceDist, _hit, (_damage min 999999)]; publicVariableServer "PVDZ_sec_atp"; }; - - dayz_lastDamageSource = switch (true) do { - case (_falling): {"fall"}; - case (_isZombieHit): {"zombie"}; - case (_ammo == "Crash"): {"crash"}; - case (_ammo == "RunOver"): {"runover"}; - case (_ammo == "Dragged"): {"eject"}; - case (_ammo in MeleeAmmo): {"melee"}; - case (!_isLocal && {(_isMan && !(currentWeapon _source in ["","Throw"])) or _isVehicle}): {"shot"}; - default {"none"}; + + dayz_lastDamageSource = call { + if (_falling) exitwith {"fall"}; + if (_isZombieHit) exitwith {"zombie"}; + if (_ammo == "Crash") exitwith {"crash"}; + if (_ammo == "RunOver") exitwith {"runover"}; + if (_ammo == "Dragged") exitwith {"eject"}; + if (_ammo in MeleeAmmo) exitwith {"melee"}; + if (!_isLocal && {(_isMan && !(currentWeapon _source in ["","Throw"])) or _isVehicle}) exitwith {"shot"}; + "none"; }; if (dayz_lastDamageSource != "none") then {dayz_lastDamageTime = diag_tickTime;}; }; //Ignore none part dmg. Exit after processing humanity hit -if (_hit == "" && _ammo != "Crash") exitWith { 0 }; +if (_hit == "" && {_ammo != "Crash"}) exitWith { 0 }; //Ammo Type Setup -_type = switch true do { - case ({_ammo isKindOf _x} count ["Grenade","ShellBase","TimeBombCore","BombCore","MissileCore","RocketCore","FuelExplosion","GrenadeBase"] > 0): { 1 }; - case ((_ammo isKindof "B_127x107_Ball") or (_ammo isKindof "B_127x99_Ball")): { 2 }; - case (_isZombieHit): { 3 }; - case (_ammo == "RunOver"): { 4 }; - case (_ammo == "Dragged"): { 5 }; - case (_ammo == "Crash"): { 6 }; - default { 0 }; +_type = call { + if ({_ammo isKindOf _x} count ["Grenade","ShellBase","TimeBombCore","BombCore","MissileCore","RocketCore","FuelExplosion","GrenadeBase"] > 0) exitwith { 1 }; + if ((_ammo isKindof "B_127x107_Ball") or (_ammo isKindof "B_127x99_Ball")) exitwith { 2 }; + if (_isZombieHit) exitwith { 3 }; + if (_ammo == "RunOver") exitwith { 4 }; + if (_ammo == "Dragged") exitwith { 5 }; + if (_ammo == "Crash") exitwith { 6 }; + 0; }; //Shake the cam, frighten them! @@ -226,15 +232,15 @@ if (_damage > 0.1) then { //Pure base blood damage _scale = 200; -if (_damage > 0.4) then { +if (_damage > 0.4) then { //Scale damage based on headhits. if (_isHeadHit) then { _scale = _scale * 2; //700 = Normal, 900 = Viral, 500 = wild }; - + //End body part scale //??????????? - if (!(player == _source) && (_isPlayer or (_isMan && !_isZombieHit))) then { //Scale shots from AI units the same as shots from players + if (!(player == _source) && {_isPlayer or (_isMan && {!_isZombieHit})}) then { //Scale shots from AI units the same as shots from players dayz_sourceBleeding = _source; //Used in player_death _scale = _scale + 800; if (_isHeadHit) then { @@ -245,36 +251,36 @@ if (_damage > 0.4) then { }; }; }; - + //Modify base scale based on the types, Allows us to modify specific types of damage if needed. - switch (_type) do { + call { //Explosions - case 1: {_scale = _scale + 300}; + if (_type == 1) exitwith {_scale = _scale + 300}; //Bullet types - case 2: {_scale = _scale + 150}; + if (_type == 2) exitwith {_scale = _scale + 150}; //Zombies - case 3: {_scale = getNumber (configFile >> "CfgVehicles" >> _sourceType >> "damageScale"); if (dayz_DamageMultiplier > 1) then {_scale = _scale * dayz_DamageMultiplier;};}; + if (_type == 3) exitwith {_scale = getNumber (configFile >> "CfgVehicles" >> _sourceType >> "damageScale"); if (dayz_DamageMultiplier > 1) then {_scale = _scale * dayz_DamageMultiplier;};}; //RunOver - case 4: {_scale = 10}; //Based on 12k blood for run over with SUV at 70km/h + if (_type == 4) exitwith {_scale = 10}; //Based on 12k blood for run over with SUV at 70km/h //Dragged - case 5: {_scale = 25}; + if (_type == 5) exitwith {_scale = 25}; //Crash - case 6: {_scale = 400}; + if (_type == 6) exitwith {_scale = 400}; }; - + //Display some info in the players log file. if (_unit == player) then { diag_log format["DAMAGE: player hit by %1 in %2 with %3 for %4 scaled to %5, Conscious %6",_sourceVehicleType,_hit,_ammo,(str(_damage)),(str(_damage * _scale)),(str (!_unconscious))]; r_player_blood = r_player_blood - (_damage * _scale); - + //Pain and Infection - _rndPain = floor(random 10); - _hitPain = (_rndPain < _damage); - - if ((_isHeadHit) or (_hitPain)) then { + _rndPain = floor(random 10); + _hitPain = (_rndPain < _damage); + + if ((_isHeadHit) || {_hitPain}) then { _hitPain = true; }; - + if (_hitPain) then { r_player_inpain = true; player setVariable["USEC_inPain",true,true]; @@ -284,10 +290,10 @@ if (_damage > 0.4) then { //Create wound and cause bleed _wound = _hit call fnc_usec_damageGetWound; _isHit = _unit getVariable["hit_"+_wound,false]; - + _isbleeding = false; _isScratched = false; - + _rndBleed = floor(random 100); _rndBleedChance = getNumber (configFile >> "CfgVehicles" >> _sourceType >> "BleedChance"); _hitBleed = (_rndBleed < _rndBleedChance); @@ -297,25 +303,25 @@ if (_damage > 0.4) then { }; if (_type == 3) then { - if (!_isHit && _isbleeding && !_isPZombie) then { + if (!_isHit && {_isbleeding} && {!_isPZombie}) then { //Create Wound _unit setVariable["hit_"+_wound,true,true]; - + PVDZ_hlt_Bleed = [_unit,_wound]; publicVariable "PVDZ_hlt_Bleed"; // draw blood stream on character, on all gameclients - + [_unit,_wound] spawn fnc_usec_damageBleed; // draw blood stream on character, locally - + //Set Injured if not already _isInjured = _unit getVariable["USEC_injured",false]; - + if (!_isInjured) then { _unit setVariable["USEC_injured",true,true]; if ((_unit == player) and (!_isZombieHit)) then { dayz_sourceBleeding = _source; }; }; - + //Set ability to give blood _lowBlood = _unit getVariable["USEC_lowBlood",false]; if (!_lowBlood) then { @@ -324,10 +330,12 @@ if (_damage > 0.4) then { if (_unit == player) then { r_player_injured = true; }; - + //HitInfection from zombies - if ((!r_player_infected) and !(r_player_Sepsis select 0)) then { + if ((!r_player_infected) && {!(r_player_Sepsis select 0)}) then { if (_type == 3) then { + private ["_rndSepsis", "_sepsisChance"]; + _rndSepsis = floor(random 100); _sepsisChance = getNumber (configFile >> "CfgVehicles" >> _sourceType >> "sepsisChance"); @@ -342,7 +350,7 @@ if (_damage > 0.4) then { if (!_isHit && !_isPZombie) then { //Create Wound _unit setVariable["hit_"+_wound,true,true]; - + PVDZ_hlt_Bleed = [_unit,_wound]; publicVariable "PVDZ_hlt_Bleed"; // draw blood stream on character, on all gameclients [_unit,_wound] spawn fnc_usec_damageBleed; // draw blood stream on character, locally @@ -350,7 +358,7 @@ if (_damage > 0.4) then { _isInjured = _unit getVariable["USEC_injured",false]; if (!_isInjured) then { _unit setVariable["USEC_injured",true,true]; - if ((_unit == player) and (!_isZombieHit)) then { + if ((_unit == player) && {!_isZombieHit}) then { dayz_sourceBleeding = _source; }; }; @@ -376,10 +384,12 @@ if (_hit in USEC_MinorWounds) then { }; } else { if (_falling) then { + private ["_nrj2", "_gravity"]; + _gravity = 9.81 min (2*(Dayz_freefall select 1)/((0.00001 + (Dayz_freefall select 2))^2)); _nrj2 = _gravity * (Dayz_freefall select 1); if (random(_nrj2 / (5 * 9.81)) > 0.5) then { // freefall from 5m => 1/2 chance to get hit legs registered - diag_log[__FILE__, "Legs damage registered from freefall, damage:",_damage,"gravity:", _gravity, + diag_log[__FILE__, "Legs damage registered from freefall, damage:",_damage,"gravity:", _gravity, "height:", (Dayz_freefall select 1), "blood loss", (_nrj2 * 25) ]; [_unit,_hit,_damage] call object_processHit; } else { @@ -399,7 +409,7 @@ if (_type == 1) then { /* BALISTIC DAMAGE */ - if ((_damage > 0.01) and (_unit == player)) then { + if ((_damage > 0.01) && {_unit == player}) then { //affect the player [20,45] call fnc_usec_pitchWhine; //Visual , Sound }; @@ -440,14 +450,14 @@ if (_type == 2) then { }; if (_type == 3) then { - if (!_unconscious and !_isMinor and _isHeadHit) then { + if (!_unconscious && {!_isMinor} && {_isHeadHit}) then { _chance = random 1; - if ((_damage > 0.8) and (_chance < 0.5)) then { + if ((_damage > 0.8) && {_chance < 0.5}) then { [_unit,_damage] call fnc_usec_damageUnconscious; }; }; } else { - if (!_unconscious and !_isMinor and ((_damage > 2) or ((_damage > 0.5) and _isHeadHit))) then { + if (!_unconscious && {!_isMinor} && {(_damage > 2) || {(_damage > 0.5) && {_isHeadHit}}}) then { //set unconsious [_unit,_damage] call fnc_usec_damageUnconscious; }; @@ -455,4 +465,3 @@ if (_type == 3) then { // all "HandleDamage event" functions should return the effective damage that the engine will record 0 - diff --git a/SQF/dayz_code/compile/fn_gearMenuChecks.sqf b/SQF/dayz_code/compile/fn_gearMenuChecks.sqf index cff1f9526..54132b9e0 100644 --- a/SQF/dayz_code/compile/fn_gearMenuChecks.sqf +++ b/SQF/dayz_code/compile/fn_gearMenuChecks.sqf @@ -1,13 +1,13 @@ setMousePosition [0.5, 0.5]; -private ["_exit","_nearestObjects","_rID","_display","_cTarget","_dis","_friendlyTo","_lastSave","_startTime"]; +private ["_exit","_nearestObjects","_rID","_display","_cTarget","_dis","_friendlyTo","_lastSave","_startTime","_vehType","_gearSelection","_supplyPositionWorld","_ctType"]; // 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}; + _dis = [12,25] select (_cTarget isKindOf "USEC_ch53_E" || {_cTarget isKindOf "MV22"}); _exit = false; if (!DZE_GearCheckBypass) then { @@ -33,7 +33,7 @@ if ((vehicle player) == player) then { if (DZE_BackpackAntiTheft) then { _friendlyTo = player getvariable ["friendlyTo",[]]; _rID = if (DZE_permanentPlot) then { getPlayerUID _cTarget } else { _cTarget getVariable ["CharacterID","0"] }; - if ((!canbuild or isInTraderCity) && {alive _cTarget} && {isPlayer _cTarget} && {!(_rID in _friendlyTo) && !(_cTarget in (units group player))} && {(player distance _cTarget) < 12}) then { + if ((isInTraderCity || {DZE_PVE_Mode} || {!canbuild}) && {alive _cTarget} && {isPlayer _cTarget} && {!(_rID in _friendlyTo) && !(_cTarget in (units group player))} && {(player distance _cTarget) < 12}) then { localize "STR_EPOCH_PLAYER_316" call dayz_rollingMessages; _display closeDisplay 2; }; diff --git a/SQF/dayz_code/configVariables.sqf b/SQF/dayz_code/configVariables.sqf index 373b57bb6..a6dc57acf 100644 --- a/SQF/dayz_code/configVariables.sqf +++ b/SQF/dayz_code/configVariables.sqf @@ -35,6 +35,7 @@ DZE_NutritionDivisor = [1, 1, 1, 1]; //array of DIVISORS that regulate the rate DZE_ZombieSpeed = [0,0]; //Default agro speed is 6 per zombie config, set array elements 0 and 1 the same for non-variable speed, set to 0 to disable. array format = [min, max]; Ex: [2, 6]; results in a range of speed between 2 and 6 (2 is the old DZE_slowZombies hard-coded speed) DZE_lockablesHarderPenalty = true; // Enforce an exponential wait on attempts between unlocking a safe/lockbox from a failed code. DZE_Hide_Body = true; //Enable hide dead bodies. Hiding a dead body removes the corpse marker from the map too. Default = true +DZE_PVE_Mode = false; //Disable the PvP damage on the server. If DZE_BackpackAntiTheft = true, the backpack anti theft is active on the whle server. This is just a basic support for PVE Servers. Default = false // SafeZone DZE_SafeZoneZombieLoot = false; // Enable spawning of Zombies and loot in positions listed in DZE_SafeZonePosArray?