# We import the tools we need from Fortnite. using { /Fortnite.com/Devices } using { /Fortnite.com/Game } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } # This is our keycard door manager device. # It lives alongside a door_device placed on the island. keycard_door_manager := class(creative_device): # Wire this to the Door device in the UEFN editor. @editable Door : lock_device = lock_device{} # Wire this to the Item Spawner device in the UEFN editor. @editable KeycardSpawner : item_spawner_device = item_spawner_device{} # OnBeginPlay runs once when the game starts. OnBeginPlay()() : void = # We print a message to the console. # This helps us know the code is running. Print("The door is waiting for a keycard.") # We listen for the item spawner's pickup event. # When a player picks up the keycard, we fire our check. KeycardSpawner.ItemPickedUpEvent.Subscribe(OnKeycardPickedUp) # This function runs when a player picks up the item from the spawner. OnKeycardPickedUp(Agent : agent) : void = # Cast agent to fort_character so we can use player APIs. if (Character := Agent.GetFortCharacter[]): Print("Keycard picked up! Opening the door.") # Open the door for the agent who picked up the keycard. Door.Open(Agent) else: Print("Something picked up the keycard, but it was not a player.")