Verse Library verse

01 Standalone

Struct containing an event handler that triggers on button press to spawn random loot items and dynamically change sky color.

verse-library/event-handler/01-standalone.verse

# This is our main script. Think of it as the "Brain" of the island.
ChaosButtonScript := struct {
    # We need a reference to the button device in the world.
    # This is like pointing to a specific player in the lobby.
    Button : button_device = nil

    # This is the "Event Handler" function.
    # It runs ONLY when the button is pressed.
    OnButtonPressed := func (player: agent) : void {
        # 1. DEBUG MESSAGE
        # This prints to the console so you know the code ran.
        Print ("Chaos Button Pressed by: ", player.GetDisplayName ())

        # 2. RANDOM LOOT DROP
        # We generate a random number between 1 and 5.
        # This is like rolling a dice to see how many items you get.
        loot_count := RandomInteger (1, 5)

        # Loop through the number we rolled.
        # For each number, we spawn a Medkit.
        for (i : 1..loot_count) {
            # This line spawns a Medkit at the button's location.
            # In a real build, you'd want to offset this so they don't clip into the floor.
            SpawnItem (ItemTypes.MEDKIT, Button.GetWorldLocation ())
        }

        # 3. CHAOS MODE (Sky Color)
        # We randomly pick a color for the sky.
        # This is like changing the storm color when the timer is low.
        sky_color := RandomColor ()

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