Verse Library verse

01 Device

Uses a random number generator to randomly grant players a sword or shield upon entering a zone.

verse-library/using-random-number-generator-devices-in-fortnite-creative/01-device.verse

# This is the main script for our Surprise Spinner
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }

# This is the main class for our device
surprise_spinner := class(creative_device):
    # These are the items we can give away
    # We link them to the Item Granters in the editor
    @editable
    sword_granter : item_granter_device = item_granter_device{}
    @editable
    shield_granter : item_granter_device = item_granter_device{}

    # This is the trigger a player walks into to spin the wheel
    # We link it to a Trigger device placed in the editor
    @editable
    spin_trigger : trigger_device = trigger_device{}

    # This function runs automatically when the game starts
    OnBegin<override>()<suspends> : void =
        # We subscribe to the trigger so we know when a player steps on it
        spin_trigger.TriggeredEvent.Subscribe(OnSpinTriggered)

    # This function runs when a player triggers the device
    OnSpinTriggered(Agent : agent) : void =
        # We roll a random integer between 1 and 2 inclusive
        # 1 means Sword, 2 means Shield
        # GetRandomInt returns a value in the range [Low, High]
        Result : int = GetRandomInt(1, 2)

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