# Import the necessary libraries for devices and game logic using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our main script file. Think of it as the "Brain" of the island. # It inherits from creative_device, which is the real base class for # island scripts that interact with placed devices in UEFN. my_mercenary_script := class(creative_device): # --- THE VARIABLES (The "Stats") --- # This variable tracks if the player has hired guards. # It starts as "false" (not hired). # 'var' makes it mutable so we can flip it later. var HasHiredGuards : logic = false # This is a reference to the Guard Spawner device. # In the UEFN editor, drag your placed Guard Spawner device # into this property slot to wire it up. @editable GuardSpawnerRef : guard_spawner_device = guard_spawner_device{} # This is the Button device. # In the UEFN editor, drag your placed Button device into this slot. @editable SummonButtonRef : button_device = button_device{} # --- THE SETUP (When the game starts) --- # This function runs once when the island loads. OnBegin() : void = # We want to listen for when the button is pressed. # This is like setting up a "Trigger" in the device editor, but in code. # We connect the Button's InteractedWithEvent to our handler below. # InteractedWithEvent sends the agent (player) who pressed the button. SummonButtonRef.InteractedWithEvent.Subscribe(HandleButtonPress) # Log a message to the debug console (optional, for testing) Print("Mercenary Mode Ready. Press the button to hire guards!") # --- THE LOGIC (What happens when the button is pressed) --- # This function is called when the button is pressed. # InteractedWithEvent passes the agent who triggered it. HandleButtonPress(Agent : agent) : void = # Check if the player has already hired guards. # In Verse, 'logic' values are tested with 'if (Var?)' or compared directly. if (HasHiredGuards = false): # If they haven't, we spawn the guards! # Enable() tells the Guard Spawner to spawn its configured guards. # The Guard Spawner device spawns however many guards you configured # in its device properties in the editor (set "Guard Count" there). # note: guard_spawner_device has no Spawn(n) method; use Enable() to trigger spawning. GuardSpawnerRef.Enable() # Now, we update the variable to "true". # This prevents the player from spawning more guards by pressing the button again. set HasHiredGuards = true # Print a message to the player (or debug log) Print("Guards hired! They are now patrolling.") else: # If they already hired guards, tell them to stop spamming. Print("You already hired your squad! Wait for them to finish or reset.")