# We define a new Device type. Think of this as a new "Device" in the editor. # It will hold our logic for managing the sentry. struct SentryTestDevice: WorldDevice = # This is our "Sentry Entity" variable. # We'll assign the actual Sentry Device from the level to this variable later. SentryEntity: Entity = Invalid # This is the "Main" function. It runs when the game starts. OnBegin()= # 1. Find the Sentry in the level. # We use FindEntityByDisplayName to grab the specific Sentry we placed. # Make sure your Sentry in the editor is named "TestSentry". sentry_device := FindEntityByDisplayName("TestSentry") if sentry_device != Invalid: # 2. Get the underlying Entity from the Sentry Device. # Devices wrap Entities. We need the Entity to access events. SentryEntity := sentry_device.GetEntity() # 3. SUBSCRIBE to the Elimination Event. # This is the magic line. We tell Verse: # "When this entity is eliminated, run the 'OnSentryDown' function." # The `?` means the Agent might be null (e.g., if the sentry died from storm damage). _ := SentryEntity.EliminatedEvent.Subscribe(OnSentryDown) Print("Sentry is live. Come get some.") else: Print("Error: Could not find 'TestSentry' in the level!") # This function runs ONLY when the sentry dies. # It receives the 'Agent' (who killed it) as a parameter. OnSentryDown(Agent: ?Agent) = # Check if the Agent is valid (i.e., a player or object killed it, not just falling). if Agent != Invalid: # Get the player's name or ID to print it. # For simplicity, we just print a message. Print("Sentry eliminated by Agent!") # REAL-WORLD EXAMPLE: # If the Agent is a Player, you would now grant them a weapon. # Player := Agent.GetPlayer() # Player.GrantItem(ItemGranterDevice.GetGrantedItem()) else: Print("Sentry died mysteriously (no agent).")