using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/SpatialMath } using { /UnrealEngine.com/Temporary/Diagnostics } # WHO'S PLAYING? — find the player's character and read its state. # # There is no "give me the player" global. You walk a short chain: # this device -> its playspace -> the players in it -> each player's # fort_character (the body that runs around the map). Once you hold a # fort_character you can ask it where it is, where it's looking, and what # it's doing right now. This device prints a quick status report for every # player when a Button is pressed — a roll-call you can drop into any island. char_roll_call_device := class(creative_device): # Press this to run the roll-call. @editable ReportButton : button_device = button_device{} OnBegin() : void = ReportButton.InteractedWithEvent.Subscribe(OnReport) # Fires each time a player presses the button. OnReport(Presser : agent) : void = # Step 1: every device lives inside a playspace. Ask for ours. Playspace := GetPlayspace() # Step 2: the playspace knows every human player currently in the match. AllPlayers := Playspace.GetPlayers() Print("Roll call: {AllPlayers.Length} player(s) in the playspace") for (P : AllPlayers): # Step 3: a player's BODY is its fort_character. This can FAIL # (a player mid-respawn has no character yet), so we use the # failable [] form and skip anyone without a live body. if (Body := P.GetFortCharacter[]): # Step 4: read its state. A fort_character is `positional`, # so GetTransform() hands back where it is in the world. Where := Body.GetTransform().Translation # GetViewLocation is the eye/aim point — where it's looking FROM. Eye := Body.GetViewLocation() Print(" at ({Where.X}, {Where.Y}, {Where.Z}) eye-height {Eye.Z}") # The Is... checks are failable tests: they SUCCEED when true. if (Body.IsCrouching[]): Print(" ...is crouching") if (Body.IsInAir[]): Print(" ...is airborne")