using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # SPAWNER WAVES — a survival horde driven by the NPC Spawner device. # # The npc_spawner_device is the front door to putting characters in your world # from Verse. You pick WHO it spawns in the editor (its NPC Character Definition); # Verse decides WHEN and HOW MANY. Here a button starts a wave, the device fires # SpawnedEvent for every character it creates, EliminatedEvent every time one # falls, and when the whole wave is down we roll the next one — bigger each time. wave_horde_device := class(creative_device): # Drop your NPC Spawner here. Choose its character (zombie, husk, custom) in # the editor — Verse just commands the spawns. @editable Spawner : npc_spawner_device = npc_spawner_device{} # Press to begin the horde. @editable StartButton : button_device = button_device{} # How many enemies the FIRST wave spawns. Each wave adds one more. @editable FirstWaveSize : int = 3 # Which wave we're on (0 = not started). var WaveNumber : int = 0 # How many of the current wave are still alive. var AliveCount : int = 0 OnBegin() : void = # Listen to the spawner's own lifecycle events. Spawner.SpawnedEvent.Subscribe(OnSpawned) Spawner.EliminatedEvent.Subscribe(OnEliminated) StartButton.InteractedWithEvent.Subscribe(OnStart) # First press kicks off wave 1. OnStart(Presser : agent) : void = if (WaveNumber = 0): StartNextWave() # Roll the next wave: enable the device and spawn (WaveNumber + base) enemies. StartNextWave() : void = set WaveNumber += 1 Count := FirstWaveSize + WaveNumber - 1 Print("=== WAVE {WaveNumber} — spawning {Count} ===") Spawner.Enable() # Reset the spawn count so a new batch is allowed, then spawn each one. Spawner.Reset() var I : int = 0 loop: if (I >= Count): break Spawner.Spawn() set I += 1 # Every character the device spawns bumps the alive counter. OnSpawned(Spawned : agent) : void = set AliveCount += 1 Print("Enemy spawned — {AliveCount} alive") # device_ai_interaction_result carries Source (killer) and Target (the dead). OnEliminated(Result : device_ai_interaction_result) : void = set AliveCount -= 1 Print("Enemy down — {AliveCount} left") # Wave cleared? Roll the next, tougher one. if (AliveCount <= 0): Print("Wave {WaveNumber} cleared!") StartNextWave()