# This is a Verse Script. Think of it as the "Brain" of the device. # It listens for events and changes things in the world. using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Fortnite.com/Playspaces } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # We define a "Device" that holds our Player Reference and Text Display. # This is like creating a custom object in the game. kill_counter_device := class(creative_device): # These are the "Components" or parts of our device. # Imagine these are the wires connecting things together. # Wire these up in the UEFN editor by selecting the device and # dragging the matching device into each slot. @editable MyTextDisplay : text_display_device = text_display_device{} # This is a "Variable". # In game terms: A variable is like a scoreboard that changes. # Here, we store the player's current elimination count. var CurrentScore : int = 0 # This function runs when the island starts. OnBegin() : void = { # Get the playspace so we can access all players and their events. Playspace := GetPlayspace() # Listen for every player who joins the session. # When they join, we subscribe to their elimination event. Playspace.PlayerAddedEvent().Subscribe(OnPlayerAdded) # Also subscribe for players already in the session at start. for (Player : Playspace.GetPlayers()): OnPlayerAdded(Player) } # Called whenever a new player is added to the session. OnPlayerAdded(Player : player) : void = { # Cast the player to a fort_character so we can access # game-specific events like EliminatedEvent. if (FortCharacter := Player.GetFortCharacter[]): # Subscribe to this character's EliminatedEvent. # It fires whenever THIS player is eliminated by someone else. FortCharacter.EliminatedEvent().Subscribe(OnCharacterEliminated) } # This function runs EVERY TIME a character is eliminated. # "Event" = A moment in time that something happens (like a bomb exploding). # The EliminatedEvent gives us an elimination_result payload. OnCharacterEliminated(Result : elimination_result) : void = { # The eliminator is the player who got the kill. # Result.Eliminator is of type ?agent, so we check it with 'if'. if (EliminatorAgent := Result.Eliminator?): # Cast agent -> player so we can query Fortnite-specific stats. if (EliminatorPlayer := player[EliminatorAgent]): # 1. Get the eliminator's current score from the playspace. # GetPlayspace().GetPlayerStats() is the real API for # reading per-player stat values set up in the experience. # note: There is no bare GetEliminations() method on player. # Increment our own counter instead, which is the # standard pattern for custom kill-count tracking. set CurrentScore += 1 # 2. Update the Text Display. # We convert the number to text (e.g., 5 -> "5") and show it. MyTextDisplay.SetText(StringToMessage($"Eliminations: {CurrentScore}")) # Helper to convert a string interpolation to the message type # required by text_display_device.SetText(). StringToMessage(S : string) : message = { # note: text_display_device.SetText() accepts a message value. # The easiest real way to build one is a localizable string # literal; here we use the string directly via HudMessageFromString. return HudMessageFromString(S) }