Verse Library verse

01 Standalone

Handles logic for awarding creative items to players upon touch, including inventory checks and feedback.

verse-library/working-with-items-pickups-and-inventory-in-verse/01-standalone.verse

using { /UnrealEngine.com/Itemization }
using { /Fortnite.com/Itemization/CreativeItems }

# This is our main script block
ItemPickupEvent := struct():
    # This is the item we want to give the player
    ItemToGive: creative_item = CreativeItems.Create_Healing_Herb()
    
    # This is the function that runs when someone touches the trigger
    OnPlayerTouch := func(trigger: trigger_component, player: player_character): void:
        # Get the player's inventory
        inventory: inventory_component = player.Get_Inventory()
        
        # Try to pick up the item
        # This moves the item from the ground to the player's bag
        result: change_inventory_result = ItemToGive.PickUp(inventory)
        
        # Check if it worked
        if (result.Success == true):
            # Item was picked up!
            # We can make a sound or show text here
            print("You got an item!")
        else:
            # It failed (maybe bag is full)
            print("You can't take that!")

Comments

    Sign in to vote, comment, or suggest an edit. Sign in