Damage per second

Search, find and discuss about Mutators!
dot
Average
Posts: 59
Joined: Tue Oct 30, 2018 3:41 am

Damage per second

Post 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 2102 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
Last edited by dot on Tue Dec 04, 2018 9:54 am, edited 2 times in total.
User avatar
papercoffee
Godlike
Posts: 10443
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Damage per second

Post by papercoffee »

Oh that's neat.
Does it work with other game types as well?
dot
Average
Posts: 59
Joined: Tue Oct 30, 2018 3:41 am

Re: Damage per second

Post 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.
User avatar
papercoffee
Godlike
Posts: 10443
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Damage per second

Post by papercoffee »

Who knows, for debugging or simple testing can it be interesting.
dot
Average
Posts: 59
Joined: Tue Oct 30, 2018 3:41 am

Re: Damage per second

Post by dot »

Little improvement - skip zero damage, use float for calc, use constant for avg seconds.
User avatar
papercoffee
Godlike
Posts: 10443
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Damage per second

Post 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.
dot
Average
Posts: 59
Joined: Tue Oct 30, 2018 3:41 am

Re: Damage per second

Post by dot »

Only two downloads. So I decide simple replace it.
But in general you right.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Damage per second

Post 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...
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Damage per second

Post 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?
So long, and thanks for all the fish
User avatar
Chamberly
Godlike
Posts: 1963
Joined: Sat Sep 17, 2011 4:32 pm
Personal rank: Dame. Vandora
Location: TN, USA
Contact:

Re: Damage per second

Post 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:
Image
Image
Image Edit: Why does my sig not work anymore?
User avatar
esnesi
Godlike
Posts: 1018
Joined: Mon Aug 31, 2015 12:58 pm
Personal rank: Dialed in.

Re: Damage per second

Post by esnesi »

Indeed real convenient with MH!
Thanks!
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Damage per second

Post 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...
dot
Average
Posts: 59
Joined: Tue Oct 30, 2018 3:41 am

Re: Damage per second

Post 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.
User avatar
esnesi
Godlike
Posts: 1018
Joined: Mon Aug 31, 2015 12:58 pm
Personal rank: Dialed in.

Re: Damage per second

Post 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.
dot
Average
Posts: 59
Joined: Tue Oct 30, 2018 3:41 am

Re: Damage per second

Post by dot »

Network mutators is not easy things. I try fix it later maybe.
Post Reply