How do I add custom events in verse creative devices?

I found a workaround on this post:

This is my implementation of a player manager that listen to Spawn Pads and dispatch to subscribers…

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Simulation/Tags }
using { /UnrealEngine.com/Temporary/Diagnostics }

SpawnerTag := class(tag){}

players_subscribable_type := type{_(:agent):void}
players_subscribable := class:
    var Subscribers<private>:[]players_subscribable_type = array{}
    Subscribe<public>(Sub:players_subscribable_type):void =
        set Subscribers += array{Sub}
    Dispatch<public>(Player: agent):void =
        for (Sub:Subscribers):
            Sub(Player)

players_manager := class(creative_device):
    var PlayerSpawners : []player_spawner_device = array{}
    var Players : []agent = array{}
  
    OnBegin<override>()<suspends>:void=
        Print("Hello, Players!!")
        # Get all the spawners
        var TaggedSpawners : []creative_object_interface = GetCreativeObjectsWithTag(SpawnerTag{})
        for (TaggedSpawner : TaggedSpawners, Spawner := player_spawner_device[TaggedSpawner]):
            set PlayerSpawners = PlayerSpawners + array{Spawner}
            # Subscribe to each player spawn pad
            Spawner.SpawnedEvent.Subscribe(OnPlayerSpawn)
   
    OnPlayerSpawn(SpawnedPlayer : agent) : void =
        Print("A Player just spawned!")
        set Players = Players + array{SpawnedPlayer}
        # Emit event for subscribers
        PlayerSpawnedEvent.Dispatch(SpawnedPlayer)

    # Custom event
    var PlayerSpawnedEvent<public>:players_subscribable = players_subscribable{}
6 Likes