# BarnTrapScript.v # This script makes a barn give players a Confetti Cannon when they enter. use Fortitude // The library that lets us talk to Fortnite devices use FortniteGame // The library for game-specific logic like items and players # This is our "Entity" definition. # Think of this as the blueprint for our trap. # "BarnTrap" is the name of our script type. BarnTrap = script: # This is a "Variable" (a container for data). # We will store the Item Granter device here. # In Verse, variables need a type. Here, it's a "Device". # A Device is any interactive object in Creative (like a button, speaker, or granter). ItemGranter: Device = Device{} # This is a "Function" (a reusable block of code). # Functions are like recipes. You define the steps once, then call them. # This function will handle giving the item. GiveLoot = function(): # We check if the ItemGranter exists and is valid. if ItemGranter.IsValid(): # "Grant" is a method (a function attached to a device). # We are telling the granter to give an item. # We need to specify the item ID. ItemGranter.GrantItem("ItemID_ConfettiCannon") # This is an "Event Handler". # It listens for the player entering the volume. # "OnBeginOverlap" is the event. It fires when two things touch. OnBeginOverlap = function(other: Actor): # "other" is the Actor (player or object) that touched us. # We check if the thing touching us is a Player. if other.IsPlayer(): # If it is a player, call our loot function. GiveLoot() # Optional: Print a message to the debug console for testing. Print("Player entered the barn! Sending confetti.") # This is the "Initialization" function. # It runs once when the game starts or the script is attached. Initialize = function(): # Here we link our script to the actual Device in the level. # In a real scenario, you'd drag the Item Granter device into this slot in the editor. # For this example, we assume the device is already linked via the editor's "Variables" panel. # If no device is linked, this script does nothing, which is safe. if ItemGranter.IsValid(): Print("Barn Trap is active and waiting for victims...")