stinkys

fn_damageHandler.sqf

Sep 9th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.27 KB | None | 0 0
  1. scriptName "Functions\misc\fn_damageHandler.sqf";
  2. /***********************************************************
  3.  
  4. Modifyed by Alby
  5.  
  6. PROCESS DAMAGE TO A UNIT
  7. - Function
  8. - [unit, selectionName, damage, source, projectile] call fnc_usec_damageHandler;
  9. ************************************************************/
  10. private["_newtypezed","_forceHit","_zClose","_bloodPercentage","_unit","_humanityHit","_myKills","_isBandit","_hit","_damage","_isPlayer","_unconscious","_wound","_isHit","_isInjured","_type","_hitPain","_inPain","_isDead","_isCardiac","_killerID","_evType","_recordable","_inVehicle","_isHeadHit","_isMinor","_scale","_canHitFree"];
  11. _unit = _this select 0;
  12. _hit = _this select 1;
  13. _damage = _this select 2;
  14. _unconscious = _unit getVariable ["NORRN_unconscious", false];
  15. _source = _this select 3;
  16. _ammo = _this select 4;
  17. if (count _this > 5) then {
  18. _forceHit = _this select 5;
  19. };
  20. _type = [_damage,_ammo] call fnc_usec_damageType;
  21. _newtypezed = typeOf _source in DayZ_NewZeds;
  22. _isMinor = (_hit in USEC_MinorWounds);
  23. _isHeadHit = (_hit == "head_hit");
  24. _evType = "";
  25. _recordable = false;
  26. _isPlayer = (isPlayer _source);
  27. _currentAnim = animationState _unit;
  28.  
  29. _sourceZombie = _source isKindOf "zZombie_base";
  30. _bloodPercentage = (r_player_blood / r_player_bloodTotal);
  31.  
  32. //Publish Damage
  33. //player sidechat format["Processed damage for %1",_unit];
  34. //USEC_SystemMessage = format["CLIENT: %1 damaged for %2 (in vehicle: %5)",_unit,_damage,_isMinor,_isHeadHit,_inVehicle];
  35. //PublicVariable "USEC_SystemMessage";
  36.  
  37. if (_unit == player) then {
  38. if (_hit == "") then {
  39. if ((_source != player) and _isPlayer) then {
  40. //Enable aggressor Actions
  41. if (_source isKindOf "CAManBase") then {
  42. _source setVariable["startcombattimer",1];
  43. };
  44. _canHitFree = player getVariable ["freeTarget",false];
  45. //_isBandit = (typeOf player) == "Bandit1_DZ";
  46. _isBandit = (player getVariable["humanity",0]) <= -2000;
  47. if (!_canHitFree and !_isBandit) then {
  48. // "humanKills" from local character is used to compute attacker player "PVDZ_plr_Humanity" change
  49. _myKills = -1 max (1 - (player getVariable ["humanKills",0]) / 7); // -1 (good action) to 1 (bad action)
  50. _humanityHit = -200 * _myKills * _damage;
  51. if (_humanityHit != 0) then {
  52. PVDZ_plr_Humanity = [_this select 0, _humanityHit, 30];
  53. publicVariable "PVDZ_plr_Humanity";
  54. };
  55. };
  56. };
  57. };
  58. };
  59.  
  60. //Pure blood damage
  61. if (_newtypezed) then { _scale = 400; } else { _scale = 200; };
  62. if (_damage > 0.1) then {
  63. if (_ammo != "zombie") then {
  64. _scale = _scale + 50;
  65. };
  66. //Start body part scale
  67. if (_ammo == "zombie" and _hit == "body") then {
  68. _scale = _scale * 3;
  69. };
  70. if (_ammo == "zombie" and _hit == "legs" and !_newtypezed) then {
  71. _scale = _scale / 2;
  72. };
  73. /*
  74. if (_ammo == "zombie" and _hit == "hands" and !_newtypezed) then {
  75. _scale = _scale / 4;
  76. };
  77. */
  78. if (_isHeadHit) then {
  79. _scale = _scale * 6;
  80. };
  81. if (_ammo == "zombie" and _unconscious and !_newtypezed) then {
  82. _scale = 50;
  83. };
  84. //End body part scale
  85. if ((isPlayer _source) and !(player == _source)) then {
  86. _scale = _scale + 800;
  87. if (_isHeadHit) then {
  88. _scale = _scale + 500;
  89. };
  90. };
  91. switch (_type) do {
  92. case 1: {_scale = _scale + 200};
  93. case 2: {_scale = _scale + 200};
  94. };
  95. if (_unit == player) then {
  96. diag_log ("DAMAGE: player hit by " + typeOf _source + " in " + _hit + " with " + _ammo + " for " + str(_damage) + " scaled " + str(_damage * _scale) + " Conscious " + str (!_unconscious));
  97. r_player_blood = r_player_blood - (_damage * _scale);
  98. };
  99. };
  100.  
  101. //Record Damage to Minor parts (legs, arms)
  102. if (_hit in USEC_MinorWounds) then {
  103. if (_ammo == "zombie") then {
  104. if (_hit == "legs") then {
  105. [_unit,_hit,(_damage / 6)] call object_processHit;
  106. } else {
  107. [_unit,_hit,(_damage / 4)] call object_processHit;
  108. };
  109. } else {
  110. if ((_hit == "legs") AND (_source==_unit) AND (_ammo=="")) then {
  111. if ((!isNil "Dayz_freefall") AND {(abs(time - (Dayz_freefall select 0))<1)}) then {
  112. _nrj = ((Dayz_freefall select 1)*20) / 100; // h=5m => nrj=1
  113. // diag_log(format["%1 Broken legs registered from freefall _hit:""%2"" _source:%3 _unit:%4 _ammo:""%5"" _damage:%6 freefall:%7 time:%8 _nrj:%9(%10) pos:%11",__FILE__,
  114. // _hit,_source,_unit,_ammo,_damage, Dayz_freefall, time, _nrj,((1+_nrj)^2)-1, getPos player]);
  115. if (random(((1+_nrj)^2)-1) > 1.5) then { // freefall from 5m => 1/2 chance to get hit legs registered
  116. diag_log(format["%1 Legs damage registered from freefall. _damage:%2 _nrj:%3 (odds %4:1) freefall:%5",__FILE__,
  117. _damage, _nrj,(((1+_nrj)^2)-1)/1.5, Dayz_freefall, time]);
  118. [_unit,_hit,_damage] call object_processHit;
  119. }
  120. else {
  121. [_unit,"arms",_damage/6] call object_processHit; // prevent broken legs due to arma bugs
  122. };
  123. };
  124. }
  125. else {
  126. [_unit,_hit,_damage/2] call object_processHit;
  127. };
  128. };
  129. };
  130.  
  131. if (_unit == player) then {
  132. //incombat
  133. _unit setVariable["startcombattimer", 1];
  134. };
  135.  
  136. //Shake the cam, frighten them!
  137. if (_damage > 0.1) then {
  138. if (_unit == player) then {
  139. //player sidechat format["Processed bullet hit for %1 (should only be for me!)",_unit];
  140. 1 call fnc_usec_bulletHit;
  141. };
  142. if (local _unit) then {
  143. _unit setVariable["medForceUpdate",true,true];
  144. };
  145. };
  146.  
  147. if (_damage > 0.4) then { //0.25
  148. //Pain and Infection
  149. if (_unit == player) then {
  150. _hitPain = (((_damage * _damage) min 0.75) > _bloodPercentage);
  151.  
  152. //Infection from zombies
  153. if (_ammo == "zombie") then {
  154. //_rndInfection = random (_damage - _bloodPercentage);
  155. //_hitInfection = ((exp _rndInfection) > dayz_infectionTreshold);
  156. //if (_newtypezed) then {
  157. //_rndInfection = random (_damage - _bloodPercentage);
  158. //_hitInfection = ((exp _rndInfection * dayz_infectionTreshold*1.1) > dayz_infectionTreshold);
  159. //};
  160. _zClose = count ((getposATL player) nearEntities ["zZombie_Base",5]);
  161. _rndInfection = random (_damage - _bloodPercentage);
  162. _hitInfection = ((exp _rndInfection) > (dayz_infectionTreshold / (_zClose * 0.25)));
  163. if (_newtypezed) then {
  164. _rndInfection = random (_damage - _bloodPercentage);
  165. _hitInfection = ((exp _rndInfection) > (dayz_infectionTreshold / _zClose));
  166. };
  167. if (_hitInfection) then {
  168. r_player_infected = true;
  169. player setVariable["USEC_infected",true,true];
  170. };
  171. //diag_log format["%1 (_damage - _bloodPercentage):%2 _rndInfection:%3 (exp _rndInfection):%4 _hitInfection:%5 ", __FILE__, (_damage - _bloodPercentage), _rndInfection, exp _rndInfection, _hitInfection];
  172. };
  173. if (_hitPain) then {
  174. r_player_inpain = true;
  175. player setVariable["USEC_inPain",true,true];
  176. };
  177. if ((_damage > 1.5) and _isHeadHit) then {
  178. _id = [_source,"shothead"] spawn player_death;
  179. };
  180. };
  181.  
  182. //Create wound and cause bleed
  183. _wound = _hit call fnc_usec_damageGetWound;
  184. _isHit = _unit getVariable["hit_"+_wound,false];
  185.  
  186. if (_ammo == "zombie") then {
  187. if(!_isHit and ((_damage > 0.7) or _isHeadHit)) then {
  188. //Create Wound
  189. _unit setVariable["hit_"+_wound,true,true];
  190. PVDZ_hlt_Bleed = [_unit,_wound,_damage];
  191. publicVariable "PVDZ_hlt_Bleed"; // draw blood stream on character, on all gameclients
  192. [_unit,_wound,_hit] spawn fnc_usec_damageBleed; // draw blood stream on character, locally
  193. //Set Injured if not already
  194. _isInjured = _unit getVariable["USEC_injured",false];
  195. if (!_isInjured) then {
  196. _unit setVariable["USEC_injured",true,true];
  197. if ((_unit == player) and (_ammo != "zombie")) then {
  198. dayz_sourceBleeding = _source;
  199. };
  200. };
  201. //Set ability to give blood
  202. _lowBlood = _unit getVariable["USEC_lowBlood",false];
  203. if (!_lowBlood) then {
  204. _unit setVariable["USEC_lowBlood",true,true];
  205. };
  206. if (_unit == player) then {
  207. r_player_injured = true;
  208. };
  209. };
  210. } else {
  211. if(!_isHit) then {
  212. //Create Wound
  213. _unit setVariable["hit_"+_wound,true,true];
  214. PVDZ_hlt_Bleed = [_unit,_wound,_damage];
  215. publicVariable "PVDZ_hlt_Bleed"; // draw blood stream on character, on all gameclients
  216. [_unit,_wound,_hit] spawn fnc_usec_damageBleed; // draw blood stream on character, locally
  217. //Set Injured if not already
  218. _isInjured = _unit getVariable["USEC_injured",false];
  219. if (!_isInjured) then {
  220. _unit setVariable["USEC_injured",true,true];
  221. if ((_unit == player) and (_ammo != "zombie")) then {
  222. dayz_sourceBleeding = _source;
  223. };
  224. };
  225. //Set ability to give blood
  226. _lowBlood = _unit getVariable["USEC_lowBlood",false];
  227. if (!_lowBlood) then {
  228. _unit setVariable["USEC_lowBlood",true,true];
  229. };
  230. if (_unit == player) then {
  231. r_player_injured = true;
  232. };
  233. };
  234. };
  235. };
  236. if (_type == 1) then {
  237. /*
  238. BALISTIC DAMAGE
  239. */
  240. if ((_damage > 0.01) and (_unit == player)) then {
  241. //affect the player
  242. [20,45] call fnc_usec_pitchWhine; //Visual , Sound
  243. };
  244. if (_damage > 4) then {
  245. //serious ballistic damage
  246. if (_unit == player) then {
  247. _id = [_source,"explosion"] spawn player_death;
  248. };
  249. } else {
  250. if (_damage > 2) then {
  251. _isCardiac = _unit getVariable["USEC_isCardiac",false];
  252. if (!_isCardiac) then {
  253. _unit setVariable["USEC_isCardiac",true,true];
  254. r_player_cardiac = true;
  255. };
  256. };
  257. };
  258. };
  259. if (_type == 2) then {
  260. /*
  261. HIGH CALIBRE
  262. */
  263. if (_damage > 4) then {
  264. //serious ballistic damage
  265. if (_unitIsPlayer) then {
  266. _id = [_source,"shotheavy"] spawn player_death;
  267. };
  268. } else {
  269. if (_damage > 2) then {
  270. _isCardiac = _unit getVariable["USEC_isCardiac",false];
  271. if (!_isCardiac) then {
  272. _unit setVariable["USEC_isCardiac",true,true];
  273. r_player_cardiac = true;
  274. };
  275. };
  276. };
  277. };
  278.  
  279. if (_ammo == "zombie") then {
  280. if (!_unconscious and !_isMinor and _isHeadHit) then {
  281. _chance = random 1;
  282. if ((_damage > 0.8) and (_chance < 0.5)) then {
  283. [_unit,_damage] call fnc_usec_damageUnconscious;
  284. };
  285. /*
  286. if (_ammo == "zombie" and _damage > (_bloodPercentage + 0.1)) then {
  287. if ((_damage - _bloodPercentage) > 0.2) then {
  288. [_unit,(_damage - _bloodPercentage)] call fnc_usec_damageUnconscious;
  289. };
  290. };
  291. */
  292. };
  293. } else {
  294. if (!_unconscious and !_isMinor and ((_damage > 2) or ((_damage > 0.5) and _isHeadHit))) then {
  295. //set unconsious
  296. [_unit,_damage] call fnc_usec_damageUnconscious;
  297. };
  298. };
  299.  
  300. // all "HandleDamage event" functions should return the effective damage that the engine will record
  301. 0
Advertisement
Add Comment
Please, Sign In to add comment