# This is a Verse script for Fortnite Creative # It tracks eliminations and gives rewards using { /Fortnite.com/Characters } using { /Fortnite.com/Devices } using { /Fortnite.com/Game } using { /Fortnite.com/Playspaces } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our device. It connects our code to the game. # Place this device on your island in UEFN. health_reward_system := class(creative_device): # This is a "Function". It is a set of instructions. # We will run this when the game starts. OnBegin():void= # We get a reference to the current game session. # This lets us listen for eliminations across all players. GameSession := GetPlayspace() # We listen for the "PlayerRemovedEvent" and loop over # each player joining so we can subscribe per-player. # The standard pattern is to subscribe to each # fort_character's EliminatedEvent as players spawn. for (Player : GameSession.GetPlayers()): spawn { WatchPlayer(Player) } # This function watches a single player for elimination events. # means it can wait for async events. WatchPlayer(Player : player):void= # We loop forever so we catch every elimination this player causes. loop: # GetFortCharacter() returns the character body for this player. # It can fail if the player has no character yet, so we use 'if'. if (Character := Player.GetFortCharacter[]): # EliminatedEvent fires when THIS character is eliminated. # We wait here until that happens. EliminationResult := Character.EliminatedEvent.Await() # EliminationResult.Eliminator holds the character # that dealt the final blow, if there was one. if (KillerCharacter := EliminationResult.Eliminator?): # We try to find the player who owns that character. var FoundKiller : ?player = false for (P : GetPlayspace().GetPlayers()): if (P.GetFortCharacter[] = KillerCharacter): set FoundKiller = option{P} if (KillerPlayer := FoundKiller?): # Now we work with the killer's character # to apply the health and shield reward. if (KillerBody := KillerPlayer.GetFortCharacter[]): # We read the current health so we can add to it. # GetHealth() returns a float. CurrentHealth := KillerBody.GetHealth() # We give the winner 25 health. # SetHealth() takes a float. We add to current health. # We cap at 100 so we don't exceed maximum health. NewHealth := Min(CurrentHealth + 25.0, 100.0) KillerBody.SetHealth(NewHealth) # We also give them 50 shields. # SetShield() takes a float. # note: the method is SetShield (no 's') on fort_character CurrentShield := KillerBody.GetShield() NewShield := Min(CurrentShield + 50.0, 100.0) KillerBody.SetShield(NewShield) # Optional: Print a message to the console for debugging. # This helps you see if it works. Print("Winner got health and shields!") else: # If the player has no character yet, wait a moment before retrying. Sleep(1.0)