Hey i'm working on a ranked system for my game, how can I hide a hud message device for one player only?

Here is my current code:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation/Tags }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/Diagnostics }
using {/UnrealEngine.com/Temporary/UI }
using { /Verse.org/Colors/NamedColors }

# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

# A Verse-authored creative device that can be placed in a level

spawner := class(tag){}

sentries := class(tag){}

TextForUI< localizes>(InText : string, Agent : agent) : message = "💀 {Agent}'s Kills: {InText}"

TextForUI2< localizes>(InText : string) : message = "🎯 Goal For \n Next Rank: {InText}"

KillTrackUI := class(creative_device):

    var playerMap : [player]KillTrackUI = map{}

    var CurrentGoal : int = 0
    
    @editable Tracker : tracker_device = tracker_device{}

    @editable Bronze : hud_message_device = hud_message_device{}

    @editable SilverR : hud_message_device = hud_message_device{}
    
    InitSpawners():void =
        Spawners := GetCreativeObjectsWithTag(spawner{})

        for (Obj : Spawners):
            if (Spawner := player_spawner_device[Obj]):
                Spawner.SpawnedEvent.Subscribe(OnPlayerAdded)

    # Runs when the device is started in a running game
    OnBegin< override>()< suspends>:void=
        # TODO: Replace this with your code
        Print("Kill ui device has started")
        InitSpawners()
        GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
    
    SpawnKillLoop(Player : player, TextBlock : text_block, Agent : agent)<suspends>:void = 
        loop: 
            Sleep(0.1) 
            if (AgentStats := playerMap[Player]):
                TextBlock.SetText(TextForUI("{Tracker.GetValue(Player)}", Agent))
                    

    RankSpawnLoop(Player: player, Agent : agent, TextBlock : text_block)<suspends>:void =
        loop:
            Sleep(0.1)
            if (Tracker.GetValue(Player) >= 15):
                if (PlayerUi := GetPlayerUI[Player]):
                    Bronze.Show(Agent)
                    TextBlock.SetText(TextForUI2("50"))
                    break
        loop:
            Sleep(0.1)
            if (Tracker.GetValue(Player) >= 50):
                if (PlayerUi := GetPlayerUI[Player]):
                    SilverR.Show(Agent)
                    TextBlock.SetText(TextForUI2("150"))
                    break

    
    OnPlayerAdded(NewPlayer : agent): void =
        Print("Player Added")
        if (PlayerObj := player[NewPlayer]):
            if (PlayerExists := playerMap[NewPlayer]):
            
            else:
                if (set playerMap[PlayerObj] = KillTrackUI{}):
                    if(AgentStats := playerMap[PlayerObj]):
                        if (FortChar:fort_character := NewPlayer.GetFortCharacter[]):
                            if (PlayerUi := GetPlayerUI[PlayerObj]):
                                var TextBlock2 : text_block = text_block{DefaultTextColor:= Beige}

                                #Does Player Have Rank?
                                if (Tracker.GetValue(PlayerObj) < 15):
                                    MyCanvas2:=canvas:
                                        Slots:=array:
                                            canvas_slot:
                                                Anchors := anchors{Minimum := vector2{X := 0.025, Y := 0.35}, Maximum := vector2{X := 0.025, Y := 0.35}}
                                                Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
                                                Alignment := vector2{X := 0.025, Y := 0.35}
                                                SizeToContent := true
                                                Widget := TextBlock2
                                    Print("Canvas Should be added")
                                    PlayerUi.AddWidget(MyCanvas2)
                                    TextBlock2.SetText(TextForUI2("15"))

                                #Check If Is On Bronze Rank
                                if (Tracker.GetValue(PlayerObj) >= 15):
                                    Bronze.Show(NewPlayer)
                                    MyCanvas2:=canvas:
                                        Slots:=array:
                                            canvas_slot:
                                                Anchors := anchors{Minimum := vector2{X := 0.025, Y := 0.35}, Maximum := vector2{X := 0.025, Y := 0.35}}
                                                Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
                                                Alignment := vector2{X := 0.025, Y := 0.35}
                                                SizeToContent := true
                                                Widget := TextBlock2
                                    Print("Canvas Should be added")
                                    PlayerUi.AddWidget(MyCanvas2)
                                    TextBlock2.SetText(TextForUI2("50"))
                                    if (Tracker.GetValue(PlayerObj) >= 50):
                                        SilverR.Show(NewPlayer)
                                        TextBlock2.SetText(TextForUI2("150"))
                                        
                                

                                #Creating Total Kills Ui
                                    
                                var TextBlock : text_block = text_block{DefaultTextColor:= White}
                                    MyCanvas:=canvas:
                                        Slots:=array:
                                            canvas_slot:
                                                Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.05}, Maximum := vector2{X := 0.5, Y := 0.05}}
                                                Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
                                                Alignment := vector2{X := 0.5, Y := 0.05}
                                                SizeToContent := true
                                                Widget := TextBlock
                                    Print("Canvas Should be added")
                                    PlayerUi.AddWidget(MyCanvas)
                                    spawn{SpawnKillLoop(PlayerObj, TextBlock, NewPlayer)}

                                    spawn{RankSpawnLoop(PlayerObj, NewPlayer, TextBlock2)}
                

    OnPlayerRemoved(PlayerLeave : player):void =
        if(ActualPlayer := playerMap[PlayerLeave]):
            var TempPlayerMap:[player]KillTrackUI = map{}
            for(Key -> Value : playerMap, Key <> PlayerLeave):
                set TempPlayerMap = ConcatenateMaps(TempPlayerMap, map{Key => Value})
            
            set playerMap = TempPlayerMap
1 Like

Do you mean HUDMessageDevice.Hide(Agent)

Depending on your use case you could maybe also put all hud message devices on the same layer and set a higher priority for message devices of higher ranks. This depends if you want players to be able to derank or not

When I try HudMessageDevice.Hide(Agent) it comes up with an error

Could you give some extra information on where you want to hide the hud message device for an agent? and about the error you’re getting?

Hi bro im creating map to so i dont know how to code verse and i dont have Time to learn it because im student do you can send me your Ranked code verse when its fonctional please

Why would I do this, you wouldn’t understand the code and you wouldn’t be able to figure what to change in the code to make it work with your map

Look Here

Could you post your whole code?

Correct me if I’m wrong but I think you’re also able to use the priority system I described in post 2. It depends on whether you want people to derank or not.

In the Editor, in your HUDMessage settings, you can set your message recipient to Enemies for instance. And then when in Verse you do HUDMessage.Show(Agent) it will show it only to the enemies of Agent.

But if your Agent is in a team and you want to show the message to the team, that wouldn’t work.
In that case you could have an array or map of all players, and when you want to send a message to all but Agent, you make a function that takes your Agent as a parameter, you loop through the array and call HUDMessage.Show() on all agents except the one passed as a parameter.

Does that help?

No I don’t want people to able to derank

In that case you have an easy solution. Hud Message Devices have a priority system (lower is better). You can give your hud message device with the Bronze rank a priority of 10, your message device of silver a priority of 9, gold 8, etc. This will only show the Message device with the lowest priority. Make sure the setting ‘layer’ is the same value for all message devices.

And if the silver one has a higher priority then it would hide the bronze rank with lower priority?

yes, because only one message can appear per layer, so the one with the worse priority will be hidden. Keep note that Hud Message Devices work kinda weird and their priority system isn’t normal. with hud devices the lower the priority the better. That’s why you would give bronze a high priorit (10 for example) silver lower (9 for example) and so forth

1 Like

Thanks, I will test it out!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.