Subscribing to Player Events in Verse
This step shows how to assign a weapon to a player at the start of the game.
When a player spawns for the first time, grant them the first weapon in the WeaponGranters array. To do this, you’ll need to subscribe functions to each player spawn pad. See the Coding Device Interactions page for more details on subscribable events.
Follow these steps to subscribe to player spawn events and to assign their first weapon.
-
Add a new method
OnPlayerSpawn()to theteam_elimination_gameclass. This method makes sure that you assign the player the right weapon when they spawn for the first time, and when they respawn.Verse
| | | | --- | --- | | | OnPlayerSpawn(InPlayer : agent) : void = | | | Print("A Player just spawned!") |OnPlayerSpawn(InPlayer : agent) : void = Print("A Player just spawned!")
Copy full snippet(2 lines long)
-
To subscribe the functions you just set up to their associated events, you need to add new code to
OnBegin(). Create aforloop to subscribe to each player spawner’sSpawnedEventusingOnPlayerSpawn.Verse
| | | | --- | --- | | | OnBegin<override>()<suspends> : void = | | | # Get all the players | | | set Teams = GetPlayspace().GetTeamCollection().GetTeams() | | | set EliminationsToEndGame = WeaponGranters.Length | | | Print("Number of eliminations to end game is {EliminationsToEndGame}") | | | for (Spawner : PlayerSpawners): | | | Spawner.SpawnedEvent.Subscribe(OnPlayerSpawn) # Subscribe to each player spawn pad |
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.