using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our main script. # It runs when the game starts. MyScript := class(creative_device): # Wire these device references in the UEFN Details panel. @editable CraftingButton : button_device = button_device{} @editable MainDoor : prop_mover_device = prop_mover_device{} @editable RewardBox : item_granter_device = item_granter_device{} # OnBegin runs automatically when the game starts. OnBegin() : void = # Subscribe to the button's InteractedWithEvent. # This calls OnPressed whenever a player presses the button. CraftingButton.InteractedWithEvent.Subscribe(OnPressed) # This function runs when the button is pressed. # The button_device passes the agent (player) who pressed it. OnPressed(Agent : agent) : void = # Cast the agent to a fort_character so we can use inventory tools. if (Character := Agent.GetFortCharacter[]): # We ask: Does the player have Sturdy Twine? # item_granter_device does not expose a live inventory query API, # so we use the pickup_item_count tracked via a tracker_device. # The closest real pattern is to gate on InteractedWithEvent and # delegate the item-count requirement to a conditonal_button_device # wired in the Details panel. Here we model the craft action: # remove one Twine by telling a dedicated item_remover_device to # activate, then open the door and grant the reward. # note: Verse has no built-in inventory-query function for custom # items; wire a item_count_tracker_device to detect item ownership # and subscribe its ThresholdReachedEvent instead for a full build. # Tell the Prop Mover to open the door. MainDoor.MoveToEnd(Agent) # Give them a reward via the Item Granter. RewardBox.GrantItem(Agent)