C++ Killstreak Counter

Greetings,

This is my first post and I am a very new user of UE4 and C++ so go easy on me :slight_smile:

I have a C++ project I picked up from the marketplace and Im wanting to set up a kill streak counter that plays a sound and displays the text on screen when achieving a milestone, such as:

2 consecutive kills within 5 seconds, with no deaths: playsound “doublekill” and display that text on screen.
If death has occurred between kills then reset to zero kills (no consecutive kills). Like the Unreal Tournament announcer does when you obtain a killstreak.

I contacted a programmer who at the time, was short on time but he offered this:


I can’t give you a complete working setup, however I will give you some tips how you could achieve it:

-Add an int32 variable to your player called something like LastDeathKillCount.

  • Done, C++ compiled and shows up in details panel of character blueprint.

-In ABasePlayerController::OnEnterDeathState set that variable to the current kill count which you can get from the PlayerState (Cast to ABasePlayerState first)

  • Confused, I dont know how to complete this step but I have found the block of code with OnEnterDeathState inside of it.

-Add a rep notify function for your ABasePlayerState::Kills variable
-In this function you can subtract the current Kills value with LastDeathKillCount of the player controller and you will get the amount of consecutive kills.

  • I have found the block of code with the “kills” variable, but I dont know how to create a rep notify function or “subtract the current Kills value with LastDeathKillCount of the player controller.”

-Implement a blueprint implementable event in the UGameOverlayWidget class which could look like this:

UFUNCTION(BlueprintImplementable, Category = Misc)
void OnKillStreak(int32 NumConsecutiveKills);

  • I added this code to UGameOverlayWidget class.

-Call this function from the rep notify function

  • No idea how to do this.

-Compile and implement the OnKillStreak event in the WBP_GameOverlay asset.

  • Will attempt when I get to this step and the widget is premade.

Maybe you can help me with the code so I can plug it in. :slight_smile:

Cheers.

Hello Bluntmaster,

I’ve never setup this particular kind of system myself but I’m interested in looking into it and the programmer you contacted seems to be correct in this implementation, but I can’t tell as I’m not sure of the setup of the project. What project is it that you got from the Marketplace? I’ll take a look at it, this way I can tell exactly what those functions do.

From what I can see right now, I’ll try to explain a bit.

The bit about not knowing what to do w/ OnEnterDeathState. You’ll want to cast to the currently controlled player’s player state, get its current kill count and assign that value to the variable you set up in the first step, LastDeathKillCount.

The part about the RepNotify for your Kills variable. When you make a rep notify function for a variable, this function will be called any time this variable is updated, which makes it very useful for tracking and updating things. You can find out more about RepNotifys here, and their C++ usage here and here.

Once you make the rep notify function, you’ll just need to call the OnKillStreak function, but I’d imagine, depending on what this function does, you’ll want to set up a condition so it’s only called or only executes its logic if Kills - LastDeathKillCount is actually resulting in 2 or more kills.

Greetings Matthew,

It is the FPS Kit: Multiplayer First Person Shooter Kit in Blueprints - UE Marketplace

I see you have explained what to do on the parts that I was stuck on, and it all sounds foreign to me as Im very new and not a programmer. I have been consulting programmers for snippets of code I can copy and paste into the project so far,

This is the setup Im wanting to achieve:
[link text][1]
[1]: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

Just the Killing Spree / MultiKills parts.

Thank you for your time.

I understand. If you’re looking for more direct help with your project, I would suggest posting on our forums in the Job Offerings section. You could offer Unpaid or Paid work and see if anyone is available to help you out. Unfortunately I don’t have the time to put the whole system together, I can only nudge you in the right direction.

Have a nice day!