# 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 () SetSkyColor (sky_color) } # This function "binds" the event to the handler. # It tells the button: "Hey, when you get interacted with, call OnButtonPressed." Initialize := func () : void { if (Button != nil) { # Subscribe to the button's interaction event. # This is the magic link between the device and the code. Button.InteractedWithEvent.Subscribe (OnButtonPressed) } } } # To start the script, we need an instance. # This is like hitting "Start Game" to begin the match. MyScript := ChaosButtonScript ()