Page 1 of 2

Damage per second

Posted: Thu Nov 01, 2018 5:22 am
by dot
Small mutator for show amount of last damage, and average damage per second for last 4 seconds.

It can be useful for MH server because players must know damage of each shot for select best weapon. It especially actually if on map can be custom weapons.
Average necessary, because need know speed of damage, not always damage for one shot give this info. Now you can compare sniper and pulse gun.
Algorithm is far from the best. It is very simple - count damage in ring buffer, exclude last second and calc average. For MH this will be enough.

Usually can be at any place in mutator chain. But if you get problem - place it first.

in action:
scr_1541046110.jpg
scr_1541046110.jpg (3.47 KiB) Viewed 2107 times

Code: Select all

class DmgPerSecond extends Mutator;

const AVG_SECONDS = 5;
var int history[5];

var int curr;
var int pos;
var int last;
var PlayerPawn MyPlayer;
var bool Initialized;
var Font FirstFont;

function PostBeginPlay() {
   if (Initialized) return;
   Initialized = True;
   
   Level.Game.RegisterDamageMutator( Self );
}

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

function nextPos() {
	if (curr != Level.Second) {
		curr = Level.Second;
		pos = pos + 1;
		if (pos >= AVG_SECONDS) pos = 0;
		history[pos] = 0;
	}
}

simulated function PostRender(canvas C) {
	local int avg;
	local int i;
	
    if ( NextHUDMutator != None )
        NextHUDMutator.PostRender(C);
        
    MyPlayer = C.Viewport.Actor;
        
    avg = 0;
    for (i = 0; i < AVG_SECONDS; i++) {
    	if (i != pos) avg = avg + history[i];
    }
    avg = 1.0 * avg / (1.0 * AVG_SECONDS - 1);
        
	C.SetPos( 0, C.ClipY/2 );
	if (FirstFont == None) {
		FirstFont = C.Font;
	} else if (FirstFont != C.Font) {
		C.Font = FirstFont;
	}
	C.DrawColor.R = 255;
	C.DrawColor.G = 255;
	C.DrawColor.B = 255;
	C.DrawText("[Dmg] avg: " $ avg $ " last: " $ last);
}

function MutatorTakeDamage( out int ActualDamage, Pawn Victim, Pawn InstigatedBy, out Vector HitLocation, 
						out Vector Momentum, name DamageType) {		
	if ( NextDamageMutator != None )
		NextDamageMutator.MutatorTakeDamage( ActualDamage, Victim, InstigatedBy, HitLocation, Momentum, DamageType );
		
	if (MyPlayer == InstigatedBy && ActualDamage != 0) {
		nextPos();
		history[pos] = history[pos] + ActualDamage;
		last = ActualDamage;
	}
}
Download: viewtopic.php?p=109439#p109439
old
DmgPerSecond.zip
(2.44 KiB) Downloaded 54 times

Re: Damage per second

Posted: Thu Nov 01, 2018 12:28 pm
by papercoffee
Oh that's neat.
Does it work with other game types as well?

Re: Damage per second

Posted: Thu Nov 01, 2018 12:53 pm
by dot
Yes of course. You can use it with any game type. I tested with DM, for example.
But for other type games it can not so helpful, because your enemies die very fast usually. only in MH you can fire in monster few minutes.

Re: Damage per second

Posted: Thu Nov 01, 2018 1:07 pm
by papercoffee
Who knows, for debugging or simple testing can it be interesting.

Re: Damage per second

Posted: Thu Nov 01, 2018 1:41 pm
by dot
Little improvement - skip zero damage, use float for calc, use constant for avg seconds.

Re: Damage per second

Posted: Thu Nov 01, 2018 2:05 pm
by papercoffee
To avoid mismatch should you name your new .u file with a prefix.
We already have enough different files with the same name floating around the UT community.

Re: Damage per second

Posted: Thu Nov 01, 2018 2:35 pm
by dot
Only two downloads. So I decide simple replace it.
But in general you right.

Re: Damage per second

Posted: Sun Dec 02, 2018 3:23 pm
by sektor2111
Can anybody answer at the question: Does this thing works On-Line ? I see it loaded but nothing shows up in client-side...

Re: Damage per second

Posted: Sun Dec 02, 2018 3:51 pm
by JackGriffin
There's no replication of the new vars from server to client. Also isn't this

Code: Select all

    if ( NextHUDMutator != None )
        NextHUDMutator.PostRender(C);
supposed to be at the end of the function?

Re: Damage per second

Posted: Sun Dec 02, 2018 6:49 pm
by Chamberly
Wow I'm so totally gonna use this, I'd like to implement this into online play so I can see if my shot goes through or not. :thuup:

Re: Damage per second

Posted: Sun Dec 02, 2018 7:28 pm
by esnesi
Indeed real convenient with MH!
Thanks!

Re: Damage per second

Posted: Sun Dec 02, 2018 9:16 pm
by sektor2111
JackGriffin wrote:There's no replication of the new vars from server to client.
That's why I've asked. For first stage I've tested it in a simple network LAN environment, I did not see anything in client, I could not even smell it. For such cases I might recommend a description in a read_me about ZERO net compatibility rather than wasting people's time for setting up things in servers with no results. Okay, perhaps I'll look into net options later, so far I have to check well another small toy which I did, and then this one can wait...
papercoffee wrote:To avoid mismatch should you name your new .u file with a prefix.
We already have enough different files with the same name floating around the UT community.
Actually this is not a problem since this mutator is pointless in a server and for playing OFF-Line I don't think a mismatch will occur, just saying...

Re: Damage per second

Posted: Sun Dec 02, 2018 11:08 pm
by dot
JackGriffin wrote:Also isn't this

Code: Select all

    if ( NextHUDMutator != None )
        NextHUDMutator.PostRender(C);
supposed to be at the end of the function?
No.
sektor2111 wrote:Does this thing works On-Line ? I see it loaded but nothing shows up in client-side...
I do not test it.
In general it is proof of concept.

Re: Damage per second

Posted: Mon Dec 03, 2018 10:31 am
by esnesi
i've noticed indeed.
Automaticly assumed it would.

According to the log the mutator is loaded through mapvote.
Only not visible for client indeed.

It would be great if it would Dot!
If you need to know which config i use, let me know.

Re: Damage per second

Posted: Mon Dec 03, 2018 1:56 pm
by dot
Network mutators is not easy things. I try fix it later maybe.