# This is a comment. It's like a sticky note for yourself. # The compiler (the program that checks your code) ignores these. # We need to tell Verse which "parts" of Fortnite we want to use. # Think of this as checking your backpack before a match. using { /Fortnite.com/Devices } using { /Fortnite.com/Characters } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # This is the main "Brain" of our script. # It attaches to a Device (like a Trigger or a Spawn Pad) # so it knows when to wake up. RespawnLootDevice := class(creative_device): # This is the "Trigger" that watches for players. # It's like a sensor that says "Hey, someone just came back!" # Wire this slot to a Spawn Pad device in the UEFN Details Panel. @editable SpawnPad : spawn_pad_device = spawn_pad_device{} # OnBegin runs once when the game session starts. # We use it to subscribe to the SpawnPad's SpawnedEvent. OnBegin() : void = # Subscribe: every time the SpawnPad fires SpawnedEvent, # call our give_respawn_loot function with the player who spawned. SpawnPad.SpawnedEvent.Subscribe(OnPlayerSpawned) # This is the "Event Listener." # It's like a security camera recording. # It watches the SpawnPad. OnPlayerSpawned(Player : player) : void = # When the spawn pad activates (player respawns), call our function. GiveRespawnLoot(Player) # This function is the "Action" that happens. # It takes a Player as an argument. # Think of it as a vending machine: You put a coin (Player) in, you get a snack (Items) out. GiveRespawnLoot(Player : player) : void = # 1. Check if the player is actually alive. # We don't want to give items to a ghost. # fort_character is the Verse type for a living Fortnite character. if (FortChar := Player.GetFortCharacter[]): # 2. Give the Shield Potion. # GrantedPickupItemEvent on item_granter_device is the standard # Verse-accessible way to hand items to a player. # Here we use GiveItem on the fort_character, which is the real API. # note: fort_character.GiveItem[] accepts a game_item_definition asset reference. # Bind your Shield Potion asset to ShieldPotionItem and MedkitItem # via @editable properties on the device (see Step 3 notes). FortChar.GivePickup(ShieldPotionPickup) # Give the Shield Potion FortChar.GivePickup(MedkitPickup) # Give the Medkit