# Import basic Verse tools using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # Define the shape of our player data # This is like a template for the notebook page player_data := struct: Score : int = 0 # Start with 0 points Items : []string = array{} # Start with no items Version : int = 1 # The sticker version # A device class that manages player data resets. # Place one instance of this device on your island. player_reset_manager := class(creative_device): # This is our shared locker room (weak_map) # It holds data for every player who joins # note: weak_map keys on player identity; data is cleared if the player leaves. var PlayerLockers : weak_map(player, player_data) = map{} # Called automatically by UEFN when the device starts OnBegin() : void = # Subscribe to the player-joined event for this session GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerJoined) # This function resets a player's data # Think of it as erasing the notebook page ResetPlayerData(P : player) : void = # Create a fresh, empty data template FreshData := player_data{} # Put the fresh data into the player's locker # This overwrites any old data if (set PlayerLockers[P] = FreshData) {} # This event runs when a player joins the island OnPlayerJoined(P : player) : void = # Check if the player already has a locker if (CurrentData := PlayerLockers[P]): # Locker exists. Check the version sticker. # If the version is old (0), reset the data. # We use 0 to mean "no version set yet." if (CurrentData.Version = 0): ResetPlayerData(P) else: # No locker exists. Create one with default data. if (set PlayerLockers[P] = player_data{}) {}