Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override void WorldThingDamaged(WorldEvent e)
- {
- let damager = e.DamageSource;
- let damagee = e.Thing;
- if(!damagee || !damager) return;
- // If damage isn't from the player but the damaging object was fired from another actor
- // redirect the damager to the firer.
- if( !(damager is "PlayerPawn") && damager)
- {
- Actor sudo_damager = damager.target;
- if(sudo_damager)damager = sudo_damager;
- }
- // Determine if shooter is a player, if so take into account players
- // view height and if the player is crouching.
- let plr = PlayerPawn(damager);
- double hitslope = damager.height/2;
- if(plr) hitslope = plr.viewheight*plr.Player.crouchfactor;
- // Preform ray cast to determine where the shooter is aiming.
- FLineTraceData lt;
- damager.LineTrace(damager.angle,2048,damager.pitch,0,hitslope,0,0,lt);
- float dmgz = lt.HitLocation.z;
- // Get "head" location from where shooter is aiming.
- float headz = (damagee.pos.z + damagee.height);
- float head_top = 18;
- float feetz = damagee.pos.z;
- float feet_len = damagee.height/2;
- // Compare ray location with the head hit boundaries
- // Only comparing the Y axis as the actor must've been hit already to
- // get this event to trigger ("WorldThingDamaged")
- if(dmgz <= headz && dmgz >= headz-head_top && damagee)
- {
- // The victim of headshot damage needs to be healed because our goal here is to
- // simply convert the damage type being delt.
- damagee.A_SetHealth(damagee.health+e.Damage);
- // Calculate Damage type based on recieved damage amount.
- Name damage_type = e.Damage <= 10 ? "HeadMinor" : "Head";
- // Preform "headshot"
- damagee.DamageMobj(NULL,NULL,e.Damage,damage_type);
- }
- else if (dmgz >= feetz && dmgz <= feetz+feet_len && damagee)
- {
- damagee.A_SetHealth(damagee.health + e.Damage);
- Name damage_type = (e.Damage <= 10) ? "MinorLeg" : (e.Damage >= 50 ? "LegDual" : "Leg");
- damagee.DamageMobj(NULL,NULL,e.Damage,damage_type);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement