Verse Library verse

01 Device

Detects when a player enters a zone and handles the interaction with type-safe casting.

verse-library/page-not-found/01-device.verse

# This is our main script file.
# It lives on a device in your island.

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

# We create a new type for our Treasure Device.
# This is like a blueprint for our special chest.
treasure_hunter := class(creative_device):

    # This is a trigger_device. It is like a radio button.
    # When the player walks into it, this device fires its event.
    # Place a trigger_device on your island and connect it here.
    @editable
    TriggerDevice : trigger_device = trigger_device{}

    # This is our main function. It runs when the game starts.
    OnBegin<override>()<suspends> : void =
        # We subscribe to the trigger's activated event.
        # The game calls our handler whenever a player activates the trigger.
        TriggerDevice.TriggeredEvent.Subscribe(OnTriggered)

    # This function runs each time the trigger fires.
    # Agent is the player (or object) that activated the trigger.
    OnTriggered(Agent : ?agent) : void =
        # Here is the magic check!
        # We try to cast Agent to a fort_character to confirm a real player triggered it.
        # note: Verse does not expose a bare IsAlive(); instead we check the cast succeeds.

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