# We need access to Verse's core tools using { /Verse.org/Simulation } using { /Verse.org/Native } using { /UnrealEngine.com/Temporary/Diagnostics } using { /UnrealEngine.com/Temporary/SpatialMath } using { /Fortnite.com/Devices } using { /Fortnite.com/Game } using { /Fortnite.com/Characters } # This is our main script, implemented as a creative_device # so it can be placed directly on your UEFN island. castle_builder := class(creative_device): # CONSTANT: The radius of our castle. # Like setting the storm size once in the editor, this never changes. CastleRadius : float = 1000.0 # VARIABLE: Tracks if the gate is open. # Like a health bar, this changes during the game. var GateIsOpen : logic = false # Reference to a trigger device placed in the editor. # Wire your "castle entrance" trigger_device to this in the UEFN # outliner so the device knows which trigger to listen to. @editable EntranceTrigger : trigger_device = trigger_device{} # EVENT: This runs when the island starts. # Think of this as the "Start of Match" button. OnBegin() : void = # Call our function to build the castle walls BuildCastleWalls() # Start listening for players entering via the trigger ListenForPlayers() # FUNCTION: Builds a circle of castle towers. # This is like saying "Place a wall here" repeatedly. # Note: Runtime asset spawning from a string path is not supported in # Verse/UEFN. Instead, wire up to eight pre-placed creative_prop # devices (one per tower slot) in the editor and enable/teleport them # here. The loop below shows the position math; adapt it to your # prop references as needed. BuildCastleWalls() : void = # We'll place 8 towers in a circle var Index : int = 0 loop: if (Index >= 8): break # Calculate angle for this tower (0 to 360 degrees) Angle : float = (Index * 45.0) * (PiFloat / 180.0) # Convert to radians # Calculate X and Y position using built-in trig X : float = CastleRadius * Cos(Angle) Y : float = CastleRadius * Sin(Angle) # Build a transform at the computed position (Z = 0, flat ground). # In UEFN/Verse, X is forward, Y is right, Z is up. TowerTransform : transform = transform{ Translation := vector3{X := X, Y := Y, Z := 0.0}, Rotation := rotation{}, Scale := vector3{X := 1.0, Y := 1.0, Z := 1.0} } # --- Spawn point --- # Wire a creative_prop (set to your Castle Gate Tower asset in # the editor) to an array called TowerProps and call: # TowerProps[Index].TeleportTo[TowerTransform] # That is the real UEFN pattern for placing pre-configured props # at runtime. Direct string-based asset spawning is not available # in Verse. # Example (requires @editable TowerProps : []creative_prop): # if (Prop := TowerProps[Index]): # Prop.TeleportTo[TowerTransform] set Index += 1 # FUNCTION: Subscribes to the entrance trigger device. # This is like setting a tripwire at the castle gate. ListenForPlayers() : void = # trigger_device exposes a TriggeredEvent that fires with the # instigating agent whenever a player walks into the trigger volume. EntranceTrigger.TriggeredEvent.Subscribe(OnPlayerEntered) # EVENT HANDLER: Runs when a player enters the trigger zone. OnPlayerEntered(InstigatingAgent : ?agent) : void = # If the gate isn't already open... if (GateIsOpen = false): # Open the gate! set GateIsOpen = true # Cast agent to fort_character so we can use player-facing APIs. # note: fort_character is the real runtime type for a Fortnite player. if (ActualAgent := InstigatingAgent, Character := ActualAgent.GetFortCharacter[]): Print("Welcome to the Castle! Gate is open.") # In a full build you would find the gate prop here and call # something like: # GateProp.TeleportTo[OpenTransform] # or trigger a cinematic_sequence_device to play an open animation.