using { /Fortnite.com/Devices } using { /Fortnite.com/Game } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our main script. It lives on a Game Manager or a specific device. # Think of this as the "Brain" of the operation. revenge_trap_script := class(creative_device): # We need a list of Player Reference devices. # You will place these in the level editor. Let's say you have 4. # Tag each device in the editor and bind them here with @editable. @editable PlayerRefs : []player_reference_device = array{} # The Prop Mover device acting as our trap door. # Place this in the level editor and bind it here. @editable TrapDoor : prop_mover_device = prop_mover_device{} # OnBegin is the built-in Verse lifecycle function that runs when the # creative_device starts. It's like hitting "Start" on the console. OnBegin() : void = # 1. Get all current players in the game. # This is like the lobby populating with players. Players := GetPlayspace().GetPlayers() # 2. We need to match each player to a Player Reference. # Imagine you have 4 Player References bound via @editable above. # We'll loop through them and assign each player by index. # # Think of it like assigning seat numbers in a classroom. # Player A gets Seat 1, Player B gets Seat 2, etc. InitializePlayerLinks(Players) # 3. Subscribe to the elimination event on the playspace so we # know whenever someone is knocked out. GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved) # This function links players to their respective Player Reference devices. InitializePlayerLinks(Players : []player) : void = # Loop through each Player Reference slot we have available. for (Index -> Ref : PlayerRefs): # Guard: only assign if a player exists at this index. if (Player := Players[Index]): # Register this player with their assigned reference device. # Register tells the Player Reference device which player # it is responsible for tracking. Ref.Register(Player) # Note: Register is the real API on player_reference_device # for assigning a player at runtime in UEFN Verse. # This function is called when a player leaves the playspace # (which includes being eliminated in most game modes). # It's triggered by the PlayerRemovedEvent subscription above. OnPlayerRemoved(RemovedPlayer : player) : void = # Walk through every Player Reference device we have. for (Ref : PlayerRefs): # GetAgent() returns an ?agent — the agent currently # assigned to this reference, if any. # We store the option first, then unwrap it in a separate if. MaybeAgent := Ref.GetAgent[] if (AssignedAgent := MaybeAgent?): # Check whether this reference belongs to the eliminated player. if (AssignedAgent = RemovedPlayer): # Found the right reference — activate the trap door. # Begin() tells the Prop Mover to run its movement sequence. TrapDoor.Begin()