# This is a comment. The game ignores lines starting with #. # 1. IMPORTS: Bringing in the tools we need. # Think of this as opening your toolbox. using { /Fortnite.com/Devices } using { /Verse.org/Simulation } # 2. THE CLASS: This is our "Blueprint" for the Score Manager. # It’s like the rulebook for how this specific manager behaves. score_manager_device := class(creative_device): # 3. VARIABLES (The Changing Stuff) # 'leaderboard' is a list that stores players and their times. # It starts empty, like a blank scoreboard. leaderboard: list = [] # 'race_active' is a boolean (true/false). # It’s like the storm timer: is the storm on? Yes/No. race_active: bool = false # 4. DEVICE REFERENCES (The Connections) # We need to tell this script which Checkpoints to listen to. # 'start_checkpoint' and 'finish_checkpoint' are placeholders. # You will drag-and-drop your actual devices here in the editor. start_checkpoint: race_checkpoint_device = create() finish_checkpoint: race_checkpoint_device = create() race_manager: race_manager_device = create() # 5. FUNCTIONS (The Actions) # 'OnBegin' runs once when the game starts. # Like the "Loadout" screen before you drop in. override OnBegin() : super.OnBegin() # Set the race to inactive initially race_active = false # Clear any old scores leaderboard = [] # 'OnPlayerCrossedStart' is an EVENT. # It fires when a player hits the START checkpoint. OnPlayerCrossedStart(player: player, checkpoint: race_checkpoint_device) : if race_active == false: # Start the race if it hasn't started race_manager.Start() race_active = true # Tell everyone the race is on Print("Race Started!") # 'OnPlayerCrossedFinish' is the MAIN EVENT. # This is what happens when someone crosses the finish line. OnPlayerCrossedFinish(player: player, checkpoint: race_checkpoint_device) : # Only do this if the race is actually going if race_active == true: # Get the player's current time from the race manager # (This is a simplified concept; real Verse needs more setup) # For this tutorial, we just record the finish. # Add this player to our 'leaderboard' variable # Think of this like adding a name to the 'Elimination List' new_score := player_score(PlayerId = player.GetPlayerId(), FinishTime = 0) leaderboard = Append(leaderboard, new_score) # Sort the list (Who finished first?) # This is like the 'Squads' tab sorting by eliminations leaderboard = SortBy(leaderboard, FinishTime) # Announce the winner winner := leaderboard[0] # The first person in the sorted list Print("Winner is Player: ", winner.PlayerId)