Saethkept

Fn_damageHandlerZ.sqf (headshot zombies)

Apr 28th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.08 KB | None | 0 0
  1. //[unit, selectionName, damage, source, projectile]
  2. //will only run when local to the created object
  3. //record any key hits to the required selection
  4. private["_zed","_selection","_damage","_hitter","_projectile","_headShots","_damageOrg"];
  5.  
  6. _zed =          _this select 0;
  7. _selection =    _this select 1;
  8. _damage =       _this select 2;
  9. _hitter =       _this select 3;
  10. _projectile =   _this select 4;
  11.  
  12. //Makes zombies almost headshot-only to kill
  13. private ["_unit","_damage","_ammo","_gethit","_damMults"];
  14. // Stolen from Celery, modifications by Nullkigan
  15.  
  16. _ammo=_this select 4;                //Type of damage unit takes
  17.  
  18. _damMults=[0.001,0.5,0.002,0.003,0.4];    //Structural, Head, Body, Hands, Legs
  19.  
  20. //player sideChat format ["%1 isKindOf BulletCore = %2, dealt %3 damage",_ammo,(_ammo isKindOf "BulletCore"),_damage];//Debug; tells you what hit the player and how much base damage it did
  21.  
  22. //if (!(_ammo isKindOf "BulletCore")) then {_damMults=[1.0,1.0,1.0,1.0,1.0];};                                        // Only modify damage if from a bullet; grenades and stuff still hurt! NB: .50 at point blank just kills instead of doing damage.  
  23. //Comment out the above IF statement for resistance to ALL damage types. NB: As well as instakills, some weapons do tens or more damage per hit, which even after scaling can still kill units outright.
  24.  
  25. if (isNil {_zed getVariable "gethit"}) then {_zed setVariable ["gethit",[0,0,0,0]]};                                 // Fresh unit starts at full health
  26. _gethit=_zed getVariable "gethit"; // load health of each part of body
  27.  
  28. switch (_this select 1) do {                                                                                           // Depending on which part of body is damaged
  29.     case "":{                                                                                                         // Overall structure damage
  30.         _damage=damage _zed+_damage*(_damMults select 0)                                                            // Total damage to unit + percentage of incoming damage
  31.     };
  32.      
  33.     case "head_hit":{                                                                                                // damage applied to head
  34.         _damage=(_gethit select 0)+(_damage-(_gethit select 0))*(_damMults select 1);_gethit set [0,_damage]        // damage dealt to head so far + damage from current shot (minus existing damage) * factor; essentially, damage accumulates with the number of shots you take
  35.     };
  36.      
  37.     case "body":{
  38.         _damage=(_gethit select 1)+(_damage-(_gethit select 1))*(_damMults select 2);_gethit set [1,_damage]        //As previously
  39.     };    
  40.      
  41.     case "hands":{                                                                                                      // cannot kill a unit on own, only affect aim
  42.         _damage=(_gethit select 2)+(_damage-(_gethit select 2))*(_damMults select 3);_gethit set [2,_damage]
  43.     };        
  44.      
  45.     case "legs":{                                                                                                      // cannot kill a unit on own, only affect movement
  46.         _damage=(_gethit select 3)+(_damage-(_gethit select 3))*(_damMults select 4);_gethit set [3,_damage]
  47.     };  
  48. };      
  49.  
  50. // Do not put a semicolon or comment after the next line otherwise the script will not output the correct result
  51.  
  52. if (local _zed) then {
  53.     if (_damage > 1 and _projectile != "") then {
  54.         //Record deliberate critical damages
  55.         switch (_selection) do {
  56.             case "head_hit": {
  57.                 if (!(_zed getVariable["hitRegistered",false])) then {
  58.                     _headShots = _hitter getVariable["headShots",0];
  59.                     _hitter setVariable["headShots",(_headShots + 1),true];
  60.                     _zed setVariable["hitRegistered",true];
  61.                 };
  62.             };
  63.         };
  64.         if (_projectile isKindOf "Bolt") then {
  65.             _damageOrg = _hitter getVariable["firedDamage",0]; //_unit getVariable["firedSelection",_selection];
  66.             if (_damageOrg < _damage) then {
  67.                 _hitter setVariable["firedHit",[_zed,_selection],true];
  68.                 _hitter setVariable["firedDamage",_damage,true];
  69.             };
  70.         };
  71.     };
  72. };
  73. _damage
Advertisement
Add Comment
Please, Sign In to add comment