Advertisement
iaretechnician

Untitled

Nov 3rd, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.92 KB | None | 0 0
  1. scriptName "Functions\misc\fn_damageHandler.sqf";
  2. /***********************************************************
  3.     PROCESS DAMAGE TO A UNIT
  4.     - Function
  5.     - [unit, selectionName, damage, source, projectile] call fnc_usec_damageHandler;
  6. ************************************************************/
  7. private ["_unit","_humanityHit","_myKills","_hit","_damage","_isPlayer","_unconscious","_wound","_isHit","_isInjured","_type","_hitPain","_isCardiac","_isHeadHit","_isMinor","_scale","_canHitFree","_rndPain","_rndInfection","_hitInfection","_lowBlood","_isPZombie","_source","_ammo","_unitIsPlayer","_isBandit"];
  8. _unit = _this select 0;
  9. _hit = _this select 1;
  10. _damage = _this select 2;
  11. _unconscious = _unit getVariable ["NORRN_unconscious", false];
  12. _isPZombie = player isKindOf "PZombie_VB";
  13. _source = _this select 3;
  14. _ammo = _this select 4;
  15. _type = [_damage,_ammo] call fnc_usec_damageType;
  16.  
  17. _isMinor = (_hit in USEC_MinorWounds);
  18. _isHeadHit = (_hit == "head_hit");
  19. //_evType = "";
  20. //_recordable = false;
  21. _isPlayer = (isPlayer _source);
  22. _humanityHit = 0;
  23. _myKills = 0;
  24. _unitIsPlayer = _unit == player;
  25.  
  26. if (_unitIsPlayer) then {
  27.     if (_hit == "") then {
  28.         if ((_source != player) && _isPlayer) then {
  29.         //Enable aggressor Actions
  30.             if (_source isKindOf "CAManBase") then {
  31.                 _source setVariable["startcombattimer",1];
  32.             };
  33.             _canHitFree =   player getVariable ["freeTarget",false];
  34.             _isBandit = (player getVariable["humanity",0]) <= -5000;
  35.             _isPZombie = player isKindOf "PZombie_VB";
  36.  
  37.             if (!_canHitFree && !_isBandit && !_isPZombie) then {
  38.                 //Process Morality Hit
  39.                 _myKills = 0 max (1 - (player getVariable ["humanKills",0]) / 5);
  40.                 _humanityHit = -100 * _myKills * _damage;
  41.  
  42.                 /* PVS/PVC - Skaronator */
  43.                 if (_humanityHit != 0) then {
  44.                     [_source,_humanityHit] spawn {
  45.                         private ["_source","_humanityHit"];
  46.                         _source = _this select 0;
  47.                         _humanityHit = _this select 1;
  48.                         PVDZE_send = [_source,"Humanity",[_source,_humanityHit,30]];
  49.                         publicVariableServer "PVDZE_send";
  50.                     };
  51.                 };
  52.             };
  53.         };
  54.     };
  55. };
  56.  
  57. //PVP Damage
  58. _scale = 200;
  59. if (_damage > 0.4) then {
  60.     if (_ammo != "zombie") then {
  61.         _scale = _scale + 50;
  62.     };
  63.     if (_isHeadHit) then {
  64.         _scale = _scale + 500;
  65.     };
  66.     if ((isPlayer _source) && !(player == _source)) then {
  67.         _scale = _scale + 800;
  68.         if (_isHeadHit) then {
  69.             _scale = _scale + 500;
  70.         };
  71.     };
  72.     switch (_type) do {
  73.         case 1: {_scale = _scale + 200};
  74.         case 2: {_scale = _scale + 200};
  75.     };
  76.     if (_unitIsPlayer) then {
  77.         //Cause blood loss
  78.         //Log Damage
  79.         /*
  80.         if (DZE_Debug_Damage) then {
  81.             diag_log ("DAMAGE: player hit by " + typeOf _source + " in " + _hit + " with " + _ammo + " for " + str(_damage) + " scaled " + str(_damage * _scale));
  82.         };
  83.         */
  84.         r_player_blood = r_player_blood - (_damage * _scale);
  85.     };
  86. };
  87.  
  88. //Record Damage to Minor parts (legs, arms)
  89. if (_hit in USEC_MinorWounds) then {
  90.     if (_ammo == "zombie") then {
  91.         if (_hit == "legs") then {
  92.             [_unit,_hit,(_damage / 6)] call object_processHit;
  93.         } else {
  94.             [_unit,_hit,(_damage / 4)] call object_processHit;
  95.         };
  96.     } else {
  97.         [_unit,_hit,(_damage / 2)] call object_processHit;
  98.     };
  99.     if (_ammo == "") then {
  100.         [_unit,_hit,_damage] call object_processHit;
  101.     };
  102. };
  103.  
  104.  
  105. if (_unitIsPlayer) then {
  106. //incombat
  107.     _unit setVariable["startcombattimer", 1];
  108. };
  109.  
  110. if (_damage > 0.1) then {
  111.     if (_unitIsPlayer) then {
  112.         //shake the cam, frighten them!
  113.         //player sidechat format["Processed bullet hit for %1 (should only be for me!)",_unit];
  114.         1 call fnc_usec_bulletHit;
  115.     };
  116.     if (local _unit) then {
  117.         _unit setVariable["medForceUpdate",true,true];
  118.     };
  119. };
  120. if (_damage > 0.4) then {   //0.25
  121.     /*
  122.         BLEEDING
  123.     */
  124.     _wound = _hit call fnc_usec_damageGetWound;
  125.     _isHit = _unit getVariable[_wound,false];
  126.     if (_unitIsPlayer) then {
  127.         _rndPain =      (random 10);
  128.         _rndInfection = (random 500);
  129.         _hitPain =      (_rndPain < _damage);
  130.         if ((_isHeadHit) || (_damage > 1.2 && _hitPain)) then {
  131.             _hitPain = true;
  132.         };
  133.         if (_ammo == "zombie") then {
  134.             _rndInfection = (random 2);
  135.             if (_ishit) then{__rndInfection = 1;};
  136.             };
  137.         _hitInfection = (_rndInfection < 1);
  138.         //player sidechat format["HitPain: %1, HitInfection %2 (Damage: %3)",_rndPain,_rndInfection,_damage]; //r_player_infected
  139.         if (_isHit) then {
  140.             //Make hit worse
  141.             if (_unitIsPlayer) then {
  142.                 r_player_blood = r_player_blood - 50;
  143.             };
  144.         };
  145.         if (_hitInfection) then {
  146.             //Set Infection if not already
  147.             if (_unitIsPlayer && !_isPZombie) then {
  148.                 r_player_infected = true;
  149.                 player setVariable["USEC_infected",true,true];
  150.             };
  151.  
  152.         };
  153.         if (_hitPain) then {
  154.             //Set Pain if not already
  155.             if (_unitIsPlayer) then {
  156.                 r_player_inpain = true;
  157.                 player setVariable["USEC_inPain",true,true];
  158.             };
  159.         };
  160.         if ((_damage > 1.5) && _isHeadHit) then {
  161.             [_source,"shothead"] spawn player_death;
  162.         };
  163.     };
  164.     if(!_isHit) then {
  165.  
  166.         if(!_isPZombie) then {
  167.             //Create Wound
  168.             _unit setVariable[_wound,true,true];
  169.  
  170.             [_unit,_wound,_hit] spawn fnc_usec_damageBleed;
  171.             /* PVS/PVC - Skaronator */
  172.             _pos = getPosATL _unit;
  173.             _inRange = _pos nearEntities ["CAManBase",1000];
  174.             {
  175.                 // only send to other players
  176.                 if(isPlayer _x && _x != player) then {
  177.                     PVDZE_send = [_x,"Bleed",[_unit,_wound,_hit]];
  178.                     publicVariableServer "PVDZE_send";
  179.                 };
  180.             } count _inRange;
  181.  
  182.             //Set Injured if not already
  183.             _isInjured = _unit getVariable["USEC_injured",false];
  184.             if (!_isInjured) then {
  185.                 _unit setVariable["USEC_injured",true,true];
  186.             if ((_unitIsPlayer) && (_ammo != "zombie")) then {
  187.                     dayz_sourceBleeding = _source;
  188.                 };
  189.             };
  190.             //Set ability to give blood
  191.             _lowBlood = _unit getVariable["USEC_lowBlood",false];
  192.             if (!_lowBlood) then {
  193.                 _unit setVariable["USEC_lowBlood",true,true];
  194.             };
  195.             if (_unitIsPlayer) then {
  196.                 r_player_injured = true;
  197.             };
  198.         };
  199.     };
  200. };
  201. if (_type == 1) then {
  202.     /*
  203.         BALISTIC DAMAGE
  204.     */
  205.     if ((_damage > 0.01) && (_unitIsPlayer)) then {
  206.         //affect the player
  207.         [20,45] call fnc_usec_pitchWhine; //Visual , Sound
  208.     };
  209.     if (_damage > 4) then {
  210.         //serious ballistic damage
  211.         if (_unitIsPlayer) then {
  212.             [_source,"explosion"] spawn player_death;
  213.         };
  214.     } else {
  215.         if (_damage > 2) then {
  216.             _isCardiac = _unit getVariable["USEC_isCardiac",false];
  217.             if (!_isCardiac) then {
  218.                 _unit setVariable["USEC_isCardiac",true,true];
  219.                 r_player_cardiac = true;
  220.             };
  221.         };
  222.     };
  223. };
  224. if (_type == 2) then {
  225.     /*
  226.         HIGH CALIBRE
  227.     */
  228.     if (_damage > 4) then {
  229.         //serious ballistic damage
  230.         if (_unitIsPlayer) then {
  231.             [_source,"shotheavy"] spawn player_death;
  232.         };
  233.     } else {
  234.         if (_damage > 2) then {
  235.             _isCardiac = _unit getVariable["USEC_isCardiac",false];
  236.             if (!_isCardiac) then {
  237.                 _unit setVariable["USEC_isCardiac",true,true];
  238.                 r_player_cardiac = true;
  239.             };
  240.         };
  241.     };
  242. };
  243.  
  244. if (!_unconscious && !_isMinor && ((_damage > 2) || ((_damage > 0.5) && _isHeadHit))) then {
  245.     //set unconsious
  246.     [_unit,_damage] call fnc_usec_damageUnconscious;
  247. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement