Advertisement
Redxone

[ZScript] GZDoom - Headshot/Legshot System (No Hitboxes)

Apr 1st, 2019
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1.     override void WorldThingDamaged(WorldEvent e)
  2.     {
  3.         let damager = e.DamageSource;
  4.         let damagee = e.Thing;
  5.         if(!damagee || !damager) return;
  6.        
  7.         // If damage isn't from the player but the damaging object was fired from another actor
  8.         // redirect the damager to the firer.
  9.         if( !(damager is "PlayerPawn") && damager)
  10.         {
  11.             Actor sudo_damager = damager.target;
  12.             if(sudo_damager)damager = sudo_damager;
  13.         }
  14.        
  15.         // Determine if shooter is a player, if so take into account players
  16.         // view height and if the player is crouching.
  17.         let plr = PlayerPawn(damager);
  18.         double hitslope = damager.height/2;
  19.         if(plr) hitslope = plr.viewheight*plr.Player.crouchfactor;
  20.        
  21.         // Preform ray cast to determine where the shooter is aiming.
  22.         FLineTraceData lt;
  23.         damager.LineTrace(damager.angle,2048,damager.pitch,0,hitslope,0,0,lt);
  24.         float dmgz = lt.HitLocation.z;
  25.            
  26.         // Get "head" location from where shooter is aiming.
  27.         float headz    = (damagee.pos.z + damagee.height);
  28.         float head_top =  18;
  29.         float feetz    =  damagee.pos.z;
  30.         float feet_len =  damagee.height/2;
  31.         // Compare ray location with the head hit boundaries
  32.         // Only comparing the Y axis as the actor must've been hit already to
  33.         // get this event to trigger ("WorldThingDamaged")
  34.         if(dmgz <= headz && dmgz >= headz-head_top && damagee)
  35.         {
  36.             // The victim of headshot damage needs to be healed because our goal here is to
  37.             // simply convert the damage type being delt.
  38.             damagee.A_SetHealth(damagee.health+e.Damage);
  39.            
  40.             // Calculate Damage type based on recieved damage amount.
  41.             Name damage_type = e.Damage <= 10 ? "HeadMinor" : "Head";
  42.            
  43.             // Preform "headshot"
  44.             damagee.DamageMobj(NULL,NULL,e.Damage,damage_type);
  45.         }
  46.         else if (dmgz >= feetz && dmgz <= feetz+feet_len && damagee)
  47.         {
  48.             damagee.A_SetHealth(damagee.health + e.Damage);
  49.             Name damage_type = (e.Damage <= 10) ? "MinorLeg" : (e.Damage >= 50 ? "LegDual" : "Leg");
  50.             damagee.DamageMobj(NULL,NULL,e.Damage,damage_type);
  51.         }
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement