ActivatedEvent

event
ActivatedEvent<public>: listenable(?agent)

Triggers when someone enters the activation radius while nobody else is there. Sends the activating `agent`. If the activator is a non-agent then `false` is returned.

Module
/Fortnite.com/Devices
Declared in
automated_turret_device
Source
fortnite

Used in

@editable
    my_spawner: item_spawner_device = item_spawner_device{}

    # This runs when the game starts
    OnBegin<override>()<suspends>:void=
        # Subscribe to the button's activation event.
        # ActivatedEvent fires with the agent (player) who pressed it.
        my_button.InteractedWithEvent.Subscribe(OnActivated)

    # This function runs when the button is pressed
    # agent is the player who clicked the button
    OnActivated(Agent : agent) : void =
        # Try to get the fort_character from the agent so we can check inventory
# Disable the button so players cannot press it yet.
        MyButton.Disable()

        # Subscribe to the button's activated event.
        # When the conditional button decides all conditions are met
        # and the player presses it, fire OnButtonActivated.
        MyButton.ActivatedEvent.Subscribe(OnButtonActivated)

        # Subscribe to the item spawner's pickup event so we know
        # when the player collects the key item (the torch).
        # note: item_spawner_device.PickedUpEvent is the real event
        #       for detecting when a spawned item is collected.
        MyItemGranter.PickedUpEvent.Subscribe(OnKeyItemPickedUp)
@editable
    StatueTriggerVolume : trigger_device = trigger_device{}

    # Called once when the game session starts
    OnBegin<override>()<suspends> : void =
        # Subscribe to the trigger volume's ActivatedEvent.
        # When a player enters the volume, OnPlayerEntered fires.
        StatueTriggerVolume.TriggeredEvent.Subscribe(OnPlayerEntered)

    # Handler: receives the agent (player) who walked into the volume
    OnPlayerEntered(Agent : ?agent) : void =
        # Activate the Prop Manipulator to show the statue.
        # Because the Health Powerup is parented to the statue in the
        # Scene Graph, it becomes visible and pickable automatically.
        StatuePropManipulator.Enable()
        # note: prop_manipulator_device does not have an Activate(agent) method;
        # Enable() is used to activate the manipulator device.
@editable
    Timer : timer_device = timer_device{}

    # This function runs when the game starts.
    OnBegin<override>()<suspends> : void =
        # Subscribe to the checkpoint device's activation event.
        # CheckpointDevice fires ActivatedEvent when a player touches it.
        SavePoint.CheckpointActivatedEvent.Subscribe(OnPlayerReachedCheckpoint)

        # Start the race timer as soon as the game begins.
        Timer.Start()

    # This function runs when a player enters the Save Point.
# This function runs when the script starts. It's like loading the map.
    OnBegin<override>()<suspends>: void =
        # Here we are "Registering" an event.
        # Think of this as setting up a trap. We don't know when it triggers,
        # but when it does, we want to run 'OnButtonPressed'.
        # shop_button.ActivatedEvent.Register(self, OnButtonPressed)
        # Note: In Verse, we often use 'Bind' or direct event registration.
        # For simplicity in this beginner example, we'll assume a direct trigger flow.
        
        # Let's register the event listener.
        shop_button.ActivatedEvent += func(event: conditional_button_device_activated_event):
            OnButtonPressed(event)

    # This is a FUNCTION. A function is like a recipe.
    # It takes an input (the event) and does something.
    OnButtonPressed(event: conditional_button_device_activated_event)<suspends>: void =
        # The button was pressed AND the currency check passed!
        # Now we need to give the player the item.
        
        # Get the player who pressed the button.
        # 'event.Get_Instigator()' gets the player who triggered the event.
        player := event.Get_Instigator()
        
        if (player != null):
            # Grant the item to the player.
            # 'Grant()' is the function that says "Here, take this."
            reward_granter.Grant(player)
            
            # Optional: Send a message to the player.
            # "Thanks for your money!"
            player.Send_message("Item Granted! Enjoy your gear.")
RadioStation: channel_device = channel_device{}

    # This function runs when the game starts. Good for setup.
    OnBegin<override>()<suspends>: void =
        # Let's listen for when the button is pressed.
        # We bind to the Button's "Activated" event.
        ChaosButton.ActivatedEvent += OnButtonPressed

    # This function runs whenever the button is pressed.
    OnButtonPressed<override>(player: player): void =
        # TRANSMIT: This is the magic line.
        # We are shouting on "Channel 1".
        # The player who pressed it is also sent along (so devices can know WHO clicked).
if (Character := Player.GetFortCharacter[]):
            loop:
                # Await the built-in JumpedEvent on the character as a stand-in
                # for a "secondary action" trigger you can swap for your own device event.
                # To use a real secondary-action signal, wire a mutator zone or
                # item-ability device's ActivatedEvent here instead.
                # note: Verse has no direct "secondary fire" input event exposed at
                # this time; JumpedEvent is the closest single-press character event.
                Character.JumpedEvent().Await()

                # Hand off to the impulse logic.
                PerformDodge(Player, Character)
wait_time := 2.0

        # We start a forever loop
        loop:
            # We wait for a player to touch the tile
            TrickTile.ActivatedEvent.Await()

            # When touched, we hide the tile
            TrickTile.Hide()

            # We wait for the time in our variable
            Sleep(wait_time)

            # Then we show the tile again
            TrickTile.Show()
# 2. The Main Event Loop
    # This function runs once when the game starts.
    Main =
        # Listen for the TriggerDevice being activated.
        # When a player steps on the trigger, this block runs.
        TriggerDevice.ActivatedEvent.Subscribe(
            func():
                # Toggle the storm state
                is_storming = !is_storming
                
                # Call our helper function to update the clouds
                UpdateClouds()

    # 3. The Helper Function
    # This function actually changes the cloud settings.
    UpdateClouds =
        # If it's storming, set density to STORM_DENSITY
        # Otherwise, set it to CLEAR_DENSITY
        if (is_storming):
            CloudComponent.SetDensity(STORM_DENSITY)
        else:
            CloudComponent.SetDensity(CLEAR_DENSITY)
            
        # Optional: Play a sound or change sky color here too!
# This is the main event handler. It runs when the button is pressed.
OnActivated := (event:ActivatedEvent) -> result: void = {
    # Get the player who pressed the button
    player := event.Get_Owner()

    # Check if the player exists (safety first, like checking for a shield)
    if (player == none) {
        return
    }

    # Get the player's inventory component
    inventory := player.Get_Inventory()

    # Check if the player has Wheat (1) and Milk (1)
    # We assume Wheat was already checked by the Conditional Button,
    # but let's verify Milk here to be safe.
    has_wheat := inventory.Has_Item(Wheat_Item, 1)
    has_milk := inventory.Has_Item(Milk_Item, 1)

    # If we have BOTH ingredients, craft the bread!
    if (has_wheat && has_milk) {
        # Remove the ingredients
        inventory.Remove_Item(Wheat_Item, 1)
        inventory.Remove_Item(Milk_Item, 1)

        # Grant the crafted item
        inventory.Grant_Item(Bread_Item, 1)

        # Optional: Send a message to the player
        # player.Send_Server_Message("Crafted Bread!")
    } else {
        # If missing items, maybe play a sound or do nothing
        # We don't want to remove items if the recipe is incomplete!
    }