Verse Library verse

01 Device

Listens for agents crossing race checkpoints and processes the event for valid players.

verse-library/using-rocket-racing-checkpoint-devices-in-unreal-editor-for-fortnite/01-device.verse

# This is a basic Verse script that listens for a player hitting a specific RR Checkpoint.
# Note: In the editor, you must link this script to the specific RR Checkpoint device.

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

# A Verse device that holds a reference to an RR Checkpoint placed in the editor.
# In the editor, drag your RR Checkpoint device into the 'MyCheckpoint' slot
# on this script's Details Panel.
checkpoint_listener := class(creative_device):

    # 'MyCheckpoint' is the editor-facing property slot.
    # rr_checkpoint_device is the real Verse type for the RR Checkpoint device.
    @editable
    MyCheckpoint : rr_checkpoint_device = rr_checkpoint_device{}

    # OnBegin runs once when the game session starts.
    # We use it to subscribe to the checkpoint's event.
    OnBegin<override>()<suspends> : void =
        # 'CheckpointReachedEvent' fires whenever any agent crosses this checkpoint.
        # We subscribe to it here so our handler runs every time it triggers.
        MyCheckpoint.CheckpointReachedEvent.Subscribe(OnCheckpointReached)

    # This function is called automatically each time a player hits the checkpoint.
    # 'Agent' is the Verse type for "whoever triggered the event."
    OnCheckpointReached(Agent : agent) : void =
        # Cast 'Agent' to 'player' so we can use player-specific APIs.
        # The 'if' block only runs if the cast succeeds (i.e., it really is a player).
        if (Player := player[Agent]):

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in