Verse Library verse

02 Fragment

Struct providing a reusable function to retrieve player health via APIs.

verse-library/how-to-use-fortnite-api-module-declarations-in-verse-uefn/02-fragment.verse

// 1. IMPORT: Bring in the "Cheat Sheet" for Players
// Without this, Verse doesn't know what a "Player" is.
import Players from "Fortnite.com"

// 2. DEFINE: Create a new Device type called HealthChecker
// Think of this as the blueprint for your trap/healer.
struct HealthChecker : WorldDevice {
    // 3. DEFINE: A simple event that fires when the game starts
    // This is like the "Start" button on a controller.
    OnBegin<override>()<suspends> {
        // We don't do anything yet, but this is where we'd set up listeners
    }
    
    // 4. DEFINE: A function that takes a Player and returns their health
    // This is a reusable tool. You can use this on ANY player.
    GetPlayerHealth(player: Players.Player) : int32 {
        // 5. API CALL: Access the Health component of the Player
        // player.GetHealth() is the question we ask the game.
        // The game answers with an integer (whole number).
        return player.GetHealth()
    }
}

Comments

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