using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/SpatialMath } # This is our main script class. Think of it as the "brain" for the powerup. class GlassCannonPowerup is WorldDevice(): # DATA MEMBERS (Variables): # These are the settings you can tweak in the editor or here. # Duration is how long the buff lasts (in seconds). Duration: float = 15.0 # Multiplier is how much damage is boosted. 2.0 means double damage. DamageMultiplier: float = 2.0 # This is a reference to the actual Powerup Device in the editor. # We link this in the editor, or we can find it programmatically. # For simplicity, we assume this script IS attached to the device. SelfDevice: DamageAmplifierPowerupDevice = Self # This tracks who currently has the buff. # An "Agent" is a player or NPC. # We use an "optional" type because no one has the buff at the start. CurrentHolder: optional Agent = none # INITIALIZATION: # This runs once when the island starts or the device spawns. OnBegin(): void = super.OnBegin() # We connect our custom function to the device's pickup event. # Think of this like plugging a wire into a trigger. SelfDevice.ItemPickedUpEvent += OnItemPickedUp SelfDevice.ItemDroppedEvent += OnItemDropped # EVENT HANDLER: When someone picks up the powerup OnItemPickedUp: func(Holder: Agent): void = # 1. Check if someone already has the buff. # If CurrentHolder is not none, someone is already "Glass Cannoning." if CurrentHolder != none: # Remove the buff from the previous holder. RemoveBuff(CurrentHolder) # 2. Set the new holder. CurrentHolder = Holder # 3. Apply the buff. # In Verse/UEFN, we often use device methods or state changes. # Here we simulate the "amplified state" by changing a visual cue # or using the device's native amplification if available. # For this example, we'll assume we are managing the logic manually # to demonstrate the timer and state tracking. # NOTE: The native DamageAmplifierPowerupDevice handles the actual # damage math internally. We are just managing the lifecycle here. # We trigger the device's activation if it wasn't already active. # (Assuming the device is set to "Manual" trigger in editor, # or we rely on the event to signal the effect start). # 4. Start the countdown timer. # "After" creates a delay. When the delay finishes, it runs the lambda. After(Duration): # This code runs exactly 'Duration' seconds later. if CurrentHolder == Holder: # Only remove if this holder is still the current one. RemoveBuff(Holder) CurrentHolder = none # EVENT HANDLER: When someone drops the powerup (rare for powerups, but good practice) OnItemDropped: func(Dropper: Agent): void = if CurrentHolder == Dropper: RemoveBuff(Dropper) CurrentHolder = none # HELPER FUNCTION: Removes the buff effect RemoveBuff: func(AgentToRemove: Agent): void = # In a full implementation, you might play a sound, change their color, # or reset their damage stats if you were doing custom damage math. # Since DamageAmplifierPowerupDevice handles the damage multiplier natively, # we just need to ensure the device stops affecting them if we were # using a custom damage volume. # For this device, the "effect" is tied to the pickup event triggering # the internal state. When the timer ends, we rely on the device's # internal timeout or we simply stop tracking it in our script. # Let's play a "power down" sound for feedback! # (Assuming a sound prop exists or using a simple visual cue) # We'll just print to the debug console for now. DebugPrint("{AgentToRemove.GetName()} lost the Glass Cannon buff!")