# Advanced LootGoblin.verse using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } LootGoblin := class(creative_device): # A reference to the Collectible Object device in the scene. # Drag your Collectible Object into this slot in the Verse panel. @editable CollectibleDevice : collectible_object_device = collectible_object_device{} # A reference to another device in the scene. # This is like a remote control pointed at the Item Granter. # Drag your Item Granter device into this slot in the Verse panel. @editable MyGranter : item_granter_device = item_granter_device{} # 'var' makes PlayerScore mutable so we can update it during gameplay. var PlayerScore : int = 0 OnBegin() : void = # Wire the collectible's built-in event to our handler function. # Subscribe takes a function that matches the event's signature. CollectibleDevice.PickedUpEvent.Subscribe(OnCollectiblePickedUp) Print("System Online. Collectibles active.") # This handler is called automatically by PickedUpEvent. # 'agent' is the Verse type for any participant in the simulation, # which includes players. Use it to target per-player devices. OnCollectiblePickedUp(Agent : agent) : void = # Increase Score. set PlayerScore += 100 Print("Score Updated: {PlayerScore}") # Activate the Item Granter! # GrantItem takes the agent so the granter knows who to reward. MyGranter.GrantItem(Agent) # Optional: Play a sound or spawn particles here. # Add a sound device reference with @editable and call Enable() on it.