Do something on Player spawns/respawn

Hi Guys a simple Question.
How can i use a function on Player Spawn?

You can add a Trigger Device to your level, then in the “User Options - Functions” in the details panel, add a Player Spawn Pad to “Trigger”, and Choose the “On Player Spawned” Event

Then from Verse:

@editable Trigger : trigger_device = trigger_device{}
OnBegin<override>()<suspends>:void=
    Trigger.TriggeredEvent.Subscribe(OnPlayerSpawn)
    
OnPlayerSpawn(Instigator : ?agent):void=
    Print("Hello")
1 Like

If you have a player_spawn_device on your level, you can use the following code to respond to an player spawning on it:

SpawnDevice.SpawnedEvent.Subscribe(OnPlayerSpawned)

SpawnDevice would be the name of your spawner. OnPlayerSpawned would be a function like the following:

    OnPlayerSpawned(InPlayer : agent): void=
        if(Player:= player[InPlayer]) :
            etc...

Note: There also functions on the Playspace that let you react to players joining the game but not necessarily spawning. You can access the Playspace from within the verse code of any Device, like so:

        PlaySpace:= GetPlayspace()
        PlaySpace.PlayerAddedEvent().Subscribe(OnPlayerAdded)
        PlaySpace.PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
3 Likes

Yeah, that seems a bit easier than what I suggested

I had looked through the Verse Digest, but completely missed the player_spawner_device :stuck_out_tongue:

1 Like

Thx Guys, that helped alot. :+1:

1 Like