using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } using { /Verse.org/Random } using { /UnrealEngine.com/Temporary/Diagnostics } using { /UnrealEngine.com/Temporary/SpatialMath } # This is our main device. It attaches to a trigger_device placed in the level. chaos_explosion_device := class(creative_device): # CONFIGURATION # How many explosions do we want at most? # Change this value in the UEFN details panel. @editable ExplosionCount : int = 5 # The trigger device wired to this script (drag it in via the UEFN details panel). @editable Trigger : trigger_device = trigger_device{} # This runs when the game starts OnBegin() : void = # Subscribe to the trigger's TriggeredEvent so we react when a player steps on it. Trigger.TriggeredEvent.Subscribe(OnTriggered) # This runs when a player activates the trigger. # trigger_device passes an optional agent; we accept it as ?agent. OnTriggered(Agent : ?agent) : void = # Unwrap the agent; do nothing if no agent was provided. if (A := Agent?): # Cast the agent to a fort_character so we can read their position. if (Character := A.GetFortCharacter[]): spawn { RunExplosions(Character) } # Contains the loop logic, called from OnTriggered. RunExplosions(Character : fort_character) : void = # 1. Pick a random number of explosions between 1 and ExplosionCount. # GetRandomInt(Min, Max) returns an int in [Min, Max] inclusive. NumExplosions : int = GetRandomInt(1, ExplosionCount) # 2. Read the character's current world position once. OriginTransform := Character.GetTransform() OriginPosition := OriginTransform.Translation # 3. LOOP: Repeat the explosion logic 'NumExplosions' times. # Verse's counted for-loop syntax: for (I := 0..NumExplosions - 1). for (I := 0..NumExplosions - 1): # 4. Calculate a random offset on the XY plane around the player. OffsetX : float = GetRandomFloat(-200.0, 200.0) OffsetY : float = GetRandomFloat(-200.0, 200.0) # Build the spawn position by adding the offset to the origin. # vector3 is the correct SpatialMath type for positions in UEFN Verse. SpawnPosition : vector3 = vector3{ X := OriginPosition.X + OffsetX, Y := OriginPosition.Y + OffsetY, Z := OriginPosition.Z } # 5. Print to the output log so we know each iteration fired. # Print() writes to the UEFN output log; no player-facing API is needed here. Print("Boom! Explosion #{I + 1} at ({SpawnPosition.X}, {SpawnPosition.Y})") # 6. Small delay between explosions so they feel staggered, not instant. Sleep(0.1)