using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } using { /Verse.org/Random } # This is our main script block SpookyCandyDevice := class(creative_device): # This is the Item Granter device # We connect it in the editor @editable CandyMachine : item_granter_device = item_granter_device{} # This is the Trigger device # We connect it in the editor @editable PlayerTrigger : trigger_device = trigger_device{} # This is the list of all candies # Each entry is an item_granter_device set up in the editor # to grant a specific candy type via its Item setting # note: Verse has no built-in candy item enum; candy type is # configured per-device in the editor, so we use one # item_granter_device per candy and pick among them randomly. @editable CandyGranters : []item_granter_device = array{} # OnBegin runs once when the game starts OnBegin() : void = # Subscribe to the trigger's agent-enters event PlayerTrigger.TriggeredEvent.Subscribe(OnEnter) # This function runs when a player enters the trigger OnEnter(Instigator : ?agent) : void = # Make sure we have at least one granter configured if (CandyGranters.Length > 0): # Pick a random index from the list RandomIndex := GetRandomInt(0, CandyGranters.Length - 1) # Look up the chosen granter; bracket access is failable if (SelectedGranter := CandyGranters[RandomIndex]): # Give the candy to the triggering agent if present if (TheAgent := Instigator?): SelectedGranter.GrantItem(TheAgent)