Hitmark Mutator

Search, find and discuss about Mutators!
InstantMix
Posts: 2
Joined: Tue Nov 10, 2020 12:34 pm

Hitmark Mutator

Post by InstantMix » Tue Nov 10, 2020 12:54 pm

I made a hitmark mutator last night as a fun little distraction. I have but the shallowest understanding of the language and how Unreal engine actually functions, so I'm not convinced this will work on anything but singleplayer.
  • I can't determine how to make some of these variables clientside, or failing that, how to store values by player.
  • I can't determine how headshots are registered,
  • Players with a shield do not trigger the MutatorTakeDamage function,

Image

Code: Select all

class HMU extends Mutator;

#exec AUDIO IMPORT FILE="Sounds\hitmarker.wav" NAME="Hitmark" GROUP="CustomSound";
#exec AUDIO IMPORT FILE="Sounds\hitmarker_headshot.wav" NAME="HitmarkHeadshot" GROUP="CustomSound";

#exec TEXTURE IMPORT NAME=HitTex FILE=Textures\Hit.PCX GROUP=Skins LODSET=2



var float curr;
var bool bLastHitKill;
var bool bInitialized;
var float lastHit;


function PreBeginPlay()
{
    if (!bInitialized)
    {
        bInitialized = True;
        Level.Game.RegisterDamageMutator(Self);
    }
}

simulated function Tick(float DeltaTime) {
    if ( !bHUDMutator && Level.NetMode != NM_DedicatedServer )
        RegisterHUDMutator();
        
    curr = curr + DeltaTime;
}

function MutatorTakeDamage ( out int ActualDamage, Pawn Victim, Pawn InstigatedBy, out Vector HitLocation, out Vector Momentum, name DamageType)
{
    local PlayerPawn PP;
    if ( NextDamageMutator != None )
		NextDamageMutator.MutatorTakeDamage( ActualDamage, Victim, InstigatedBy, HitLocation, Momentum, DamageType );

    if (ActualDamage !=0 && InstigatedBy != None ) {
        if (InstigatedBy.IsA('PlayerPawn') && PP == None) 
        {
            PP = PlayerPawn(InstigatedBy);

            bLastHitKill = Victim.Health - ActualDamage <= 0;

            // No idea how to determine headshots
            if ( bLastHitKill || ActualDamage > 50 || DamageType == 'decapitated' || DamageType == 'beheaded' || DamageType == 'cmheadshot')
            {   
                PP.clientPlaySound(Sound'HitmarkHeadshot', true, true);
            }
            else
            {
                PP.clientPlaySound(Sound'Hitmark', true, true);
            }
            
            lastHit = curr;
        }
    }
}

simulated function PostRender(canvas C) {

    local float offset;
    offset = FClamp(lastHit-curr+0.25,0,25)*1020;
	
    if ( NextHUDMutator != None )
    {
        NextHUDMutator.PostRender(C);
    }
        
	C.SetPos( C.ClipX/2 -64, C.ClipY/2 -64);
    C.bNoSmooth = False;

    if (curr < (lastHit + 0.25))
    {
        C.DrawColor.R = offset;

        if (bLastHitKill) {
            C.DrawColor.G = 0;
	    C.DrawColor.B = 0;
        }
        else
        {
            C.DrawColor.G = offset;
	    C.DrawColor.B = offset;
        }
        
        C.DrawTile (texture'HitTex', 128, 128, 0, 0, 128, 128);
    }
}
Download

ProAsm
Skilled
Posts: 193
Joined: Sun Sep 29, 2013 7:12 am

Re: Hitmark Mutator

Post by ProAsm » Tue Nov 10, 2020 6:56 pm

To detect a Headshot, use the Mutator function PreventDeath then:
if ( DamageType == 'decapitated' )
Here you can find all sorts of stuff like 'shot', 'Gibbed', 'RedeemerDeath', 'RocketDeath', 'GrenadeDeath' etc
Good luck with your coding :)

User avatar
OjitroC
Godlike
Posts: 2521
Joined: Sat Sep 12, 2015 8:46 pm

Re: Hitmark Mutator

Post by OjitroC » Wed Nov 11, 2020 12:25 am

Yes, interesting that. Certainly works - the only thing is it seems to replace the Player's taunt after a kill - the text appears in the talk area OK but what the Player says isn't heard.

What's that on the ramp in your screenshot (apart from Nikita :P)?

InstantMix
Posts: 2
Joined: Tue Nov 10, 2020 12:34 pm

Re: Hitmark Mutator

Post by InstantMix » Wed Nov 11, 2020 5:34 pm

ProAsm wrote:
Tue Nov 10, 2020 6:56 pm
To detect a Headshot, use the Mutator function PreventDeath then:
if ( DamageType == 'decapitated' )
Here you can find all sorts of stuff like 'shot', 'Gibbed', 'RedeemerDeath', 'RocketDeath', 'GrenadeDeath' etc
Good luck with your coding :)
Ahh thank you, I'll try giving that a bash and see what I can come up with.
OjitroC wrote:
Wed Nov 11, 2020 12:25 am
Yes, interesting that. Certainly works - the only thing is it seems to replace the Player's taunt after a kill - the text appears in the talk area OK but what the Player says isn't heard.

What's that on the ramp in your screenshot (apart from Nikita :P)?
I'm sure missing a vocal taunt won't be the end of the world. I think it's just a bullet casing, for some odd reason the crosshair isn't centered if your viewmodel is using the left or right hand setting, so I made it invisible. Didn't want it to look like the mitmark image was off!

User avatar
OjitroC
Godlike
Posts: 2521
Joined: Sat Sep 12, 2015 8:46 pm

Re: Hitmark Mutator

Post by OjitroC » Wed Nov 11, 2020 7:08 pm

InstantMix wrote:
Wed Nov 11, 2020 5:34 pm
I'm sure missing a vocal taunt won't be the end of the world.
Perhaps make the hitsounds an option - quite often they are not audible with all the weapon, explosion and gib sounds around - apart from liking the vocalisations of my 'character' (chosen with care from the multitude available), the kill taunt does actually indicate that I have killed something when I may not be able to see that that is the case. I raise it because it may be important for other players as well - at least, it is something to consider.

John Cleese
Novice
Posts: 5
Joined: Wed Oct 07, 2009 10:14 am

Re: Hitmark Mutator

Post by John Cleese » Thu Feb 25, 2021 9:06 am

This is awesome! Thanks. I was just thinking about this today, happy to find this and thanks for the source. :gj: