Simple frag counter in UEFN

Despite the fact that the Fortnite game was released in 2017, it is still played with pleasure by quite a few players around the world. We think that the point here is not only that it is a pretty good multiplayer shooter, with a fairly large number of various jokes, but also that. thanks to the relative openness to creating maps for this game, anyone can create their own, with almost any mechanics.

Despite the fact that the basis is Unreal Engine, we did not write “almost” for nothing, the map editor for Fortnite is still a separate element, with its own structure and even programming language – Verse, which sometimes leads to a stupor, because it combines the syntax of a whole bunch of languages.

But this article is not dedicated to the thread how bad or difficult everything is, here we will make a small text guide on creating a small widget-counter of frags, from the video of the user hawaiifilmschool. Let’s just say that we personally looked for this widget for a map with NPCs, so we don’t know how it will work on multiplayer maps with real players.

You probably already have your own project in UEFN, where you need to add a counter.

First of all, we need to add from the Content Browser – Content – Elimination Manager.

Next, go to Verse Explorer, right-click and create a new script

After that, a pop-up will open where we will be asked to choose one of the script templates, select the Verse Device type, and enter the name of the script, for example – KillCounter, click on Create

Next, in Verse Explorer, we see our created file, and click on it to open it in the editor.

Below we will place a slightly modified code than was in the original video, because it caused some errors, possibly due to the difference in software versions.

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }


KillCounter := class(creative_device):

    @editable
    var ElimManager :elimination_manager_device = elimination_manager_device {}
    var KillCount : int = 0
    var Players: [] player = array {}
    var UIButton : button_loud = button_loud{}

    TextForUI<localizes>(Kills : int) : message = "Kills: {Kills}"

    EnemyKilled(Agent : ?agent) : void =
        set KillCount = KillCount +1
        Print ("Kills: {KillCount}")
        UIButton.SetText(TextForUI(KillCount))

    CreateUI (Player : player) : void =
            if(PlayerUI := GetPlayerUI [Player]):
                UIButton.SetText(TextForUI(0))
                MyCanvas : canvas = canvas:
                    Slots := array:
                        canvas_slot:
                            Widget := UIButton
                            Anchors := anchors{Minimum := vector2 {X := 0.5, Y := 0.0}, Maximum := vector2 {X := 0.5, Y := 0.0}}
                            Offsets := margin{Top := 50.0, Left := 50.0, Right := 50.0, Bottom := 50.0}
                            Alignment := vector2 {X := 0.5, Y := 0.5}
                            SizeToContent := true
                PlayerUI.AddWidget (MyCanvas)

    OnBegin<override>()<suspends>:void=
        ElimManager.EliminationEvent.Subscribe(EnemyKilled)

        set Players = GetPlayspace().GetPlayers()
        if(Player := Players[0]):
            CreateUI(Player)

Save the file. Then go to the top menu of UEFN and select Verse – Build Verse Code

Here, we essentially process our script so that it is already working in our editor.

Next, in the Content Browser, we search for our script and drag it onto our map.

We will see such a device, when we click on it, on the right, in Details, we will see the settings, namely, we need to set the Kill Counter to Elimination Manager, also, you can uncheck the Visible in Game checkbox so that players do not see the model of this device.

After that, we save the project and start a test session.

Now we can see a small counter like this on top.

In our case, where we have a map with NPCs, we made a counter to track the number of guards killed out of the maximum possible number on the map (30). So we only modified two lines

TextForUI<localizes>(Kills : int) : message = "Kills: {Kills} / 30"

та

Print ("Kills: {KillCount} / 30")

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *