# Import the Verse standard modules we need using { /Verse.org/Simulation } using { /Verse.org/Random } using { /Fortnite.com/Devices } using { /UnrealEngine.com/Temporary/Diagnostics } # Define our creative device class. # A creative_device is the standard base for all Verse-powered island devices. loot_box_device := class(creative_device) { # We need to reference our devices. # These are "Properties" – variables that hold references to devices in the level. # You will set these in the Verse Device's properties panel in the editor. @editable LootBoxTrigger : trigger_device = trigger_device{} @editable ShieldGranter : item_granter_device = item_granter_device{} @editable BandageGranter : item_granter_device = item_granter_device{} # This function picks the loot and gives it. GiveRandomLoot(Agent : agent) : void = # Roll the die: 0 or 1 Roll := GetRandomInt(0, 1) # Use an if/else to pick which granter to use based on Roll, # then grant the item to the agent. if (Roll = 0): ShieldGranter.GrantItem(Agent) else: BandageGranter.GrantItem(Agent) # OnBegin runs automatically when the game session starts. # We subscribe to the trigger's TriggeredEvent here so the device # calls GiveRandomLoot whenever a player steps on the trigger. OnBegin() : void = # Subscribe to the trigger's TriggeredEvent. # The lambda receives the optional agent who activated the trigger. LootBoxTrigger.TriggeredEvent.Subscribe(OnTriggered) # Handler called by the trigger subscription. # Agent is ?agent because triggers fire with an optional agent. OnTriggered(MaybeAgent : ?agent) : void = # Unwrap the optional agent before passing it to GiveRandomLoot. if (Agent := MaybeAgent?): GiveRandomLoot(Agent) }