Verse Library verse

06 Complete Script

Calculates and applies damage to the first player in the playspace on device start, handling health edge cases.

extracted-snippets/documentation/en-us/uefn/learn-code-basics-8-practice-time-in-verse/06-complete-script.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/learn-code-basics-8-practice-time-in-verse
# Local doc:  epic-docs/documentation/en-us/uefn/learn-code-basics-8-practice-time-in-verse.md
# Section:    Complete Script
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }

hello_world_device := class(creative_device):

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=

        HurtPlayer(80.0)
        Print("Player Hurt")

    CalculateDamage(PlayerHealth : float, DesiredDamageAmount : float, MinHealth : float) : float = 
        # If the damage amount would not eliminate the player, do that amount of damage
        if (PlayerHealth > DesiredDamageAmount):
            return DesiredDamageAmount
        else if (PlayerHealth > MinHealth):
            # Give player one more chance if their health is low
            return PlayerHealth - MinHealth
        else:
            # Eliminate player
            return PlayerHealth

    HurtPlayer(DamageAmount : float) : void =
        Playspace: fort_playspace = GetPlayspace()

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

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