# damage.Pickup(Agent) not working

**URL:** <https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [February 12, 2024, 5:05am UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220 "2024-02-12T05:05:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Burntoast422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Burntoast422](https://forums.unrealengine.com/u/Burntoast422)\
**Post date:** [February 12, 2024, 5:05am UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/1 "2024-02-12T05:05:54Z")

</div>

im trying to create a damage multiplier power up where every second the damage multiplier device increase by 0.1 and then is picked up by a player automatically. im trying to make it so that once the player select class 1 it starts the loop of giving the player who switched to class 1 the damage multiplier.

```auto
hello_world_device := class(creative_device):
    @editable
    damagedevice:damage_amplifier_powerup_device = damage_amplifier_powerup_device{}
    
    @editable
    var increaserate : float = 1.0

    @editable
    var damage : float = 1.0

    DamagePower(Agent:agent)<suspends>:void=
        loop: 
            Sleep(increaserate)
            damagedevice.SetMagnitude(damage)
            damagedevice.Pickup(Agent)
            set damage += 0.1

```

and the code that calls the function:

```auto
game_manager := class(creative_device):
    var PlayersMap:[agent]CustomPlayer = map{}
    DamageClass:int = 1

    @editable
    Class1Selector:class_and_team_selector_device = class_and_team_selector_device{}

    @editable
    SpawnPad1:player_spawner_device = player_spawner_device{}

    Powers:hello_world_device = hello_world_device{}

    OnBegin<override>()<suspends>:void=
        SpawnPad1.SpawnedEvent.Subscribe(OnPlayerSpawned)
        Class1Selector.ClassSwitchedEvent.Subscribe(OnClass1Change)

    OnPlayerSpawned(Agent:agent):void=
        if(PlayerExists := PlayersMap[Agent]):
            Print("player already exists")
            #do nothing since player already exists
        else:
            CP:CustomPlayer = CustomPlayer{MyAgentObj := Agent}
            option:
                set PlayersMap[Agent] = CP

    OnClass1Change(Agent:agent):void = 
        if(CP:CustomPlayer = PlayersMap[Agent]):
            CP.SetClass(DamageClass)
            spawn{Powers.DamagePower(Agent)}
            

    OnPlayerRemoved(OutPlayer:player):void=
        if(Agent:=agent[OutPlayer]):
            if(ActualPlayer := PlayersMap[Agent]):
                var TempAllPlayersMap:[agent]CustomPlayer = map{}
                for (Key -> Value : PlayersMap, Key <> Agent):
                    set TempAllPlayersMap = ConcatenateMaps(TempAllPlayersMap, map{Key => Value})
                
                set PlayersMap = TempAllPlayersMap

```

any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 8:08pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/2 "2024-02-12T20:08:06Z")

</div>

If you could, please describe the behavior that you are seeing, or the error message you are getting. That would help narrow down where the problem could be.

---

<div class="post-metadata">

**Author:** ![Burntoast422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Burntoast422](https://forums.unrealengine.com/u/Burntoast422)\
**Post date:** [February 12, 2024, 8:15pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/3 "2024-02-12T20:15:56Z")

</div>

there is no error, when i start the game i step into the class selector and the loop starts but it doesnt give me the damage multiplier effect.

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 8:21pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/4 "2024-02-12T20:21:51Z")

</div>

Place a Print statement inside of the if statement for OnClass1Change(), to make sure it is finding the Player in the Map.

Also place a Print inside of the loop for DamagePower() to see if it is actually getting called as well.

Let me know which of these prints you can actually see.

---

<div class="post-metadata">

**Author:** ![Burntoast422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Burntoast422](https://forums.unrealengine.com/u/Burntoast422)\
**Post date:** [February 12, 2024, 8:46pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/5 "2024-02-12T20:46:04Z")

</div>

![20240212_224135_mfnr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/b/23b0f72fa8a40aab9747b2fed3d913c7a8aa619a.jpeg)  
i also added a print function to display the players name, the proper name pops up on the screen on the top left but when i open the logs it shows anonymous[256]

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 9:17pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/6 "2024-02-12T21:17:40Z")

</div>

Alright. Now, what do you have the min and max values for the damage\_powerup\_device set to? Also, what is the duration? We should make sure they are all reasonable values.

---

<div class="post-metadata">

**Author:** ![Burntoast422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Burntoast422](https://forums.unrealengine.com/u/Burntoast422)\
**Post date:** [February 12, 2024, 9:23pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/7 "2024-02-12T21:23:07Z")

</div>

i have everything set to default except that i enabled respawn and made it respawn immediately. So the duration is 3 seconds. (sorry i don’t know what you mean min max values im new to uefn : / )

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 9:29pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/8 "2024-02-12T21:29:28Z")

</div>

That’s fine. What might be happening is that the SetMagnitude might be getting mad.

First, can you clarify what you want it to do?

Option 1:

- The power up is sitting in the world, slowly increasing it’s damage multiplier.
- the player picks up the pickup, and they get whatever multiplier that the pickup had at that point in time.  
Ex: If it was 5x when they picked it up, they get 5x forever (or until the power up is done)

Option 2

- The player picks up the power up
- They get a damage multiplier that continuously increase until the time runs out.

---

<div class="post-metadata">

**Author:** ![Burntoast422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Burntoast422](https://forums.unrealengine.com/u/Burntoast422)\
**Post date:** [February 12, 2024, 9:33pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/9 "2024-02-12T21:33:50Z")

</div>

what im trying to create is similar to option 2, more specifically im trying to make it so that a player that joins class 1 has a slowly increasing damage multiplier ( +0.1 multiplier every 1 second)

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 9:44pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/10 "2024-02-12T21:44:57Z")

</div>

Actually, I am pretty sure the problem is with the references. In `game_manager`, you create a new `hello_world_device`. That would be fine, but the problem comes in when you try to set the `damagedevice` inside of `hello_world_device` to `@editable`. It is expecting you to pass it a `damage_amplifier`, but you can’t do that with the way you created `hello_world_device`.

Two Solutions:

1. Inside of `game_manager` make the `hello_world_device` `@editable`. Then, drag an instance of that device into the world. From there, you will be able to pass it a `damage_amplifier_device` through UEFN. But don’t forget to update the game\_manager’s reference to hello\_world\_device as well.

2. Remove the `@editable` from the `damagedevice` in hello\_world\_device

---

<div class="post-metadata">

**Author:** ![Burntoast422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Burntoast422](https://forums.unrealengine.com/u/Burntoast422)\
**Post date:** [February 12, 2024, 10:17pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/11 "2024-02-12T22:17:18Z")

</div>

still doesn’t work, i tried both methods, both give me the same result when i try to print the magnitude of the damage multiplier ( which is 0.00)

---

<div class="post-metadata">

**Author:** ![The3v0luti0n](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/the3v0luti0n/32/897083_2.png) [@The3v0luti0n](https://forums.unrealengine.com/u/The3v0luti0n)\
**Post date:** [February 12, 2024, 11:48pm UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/12 "2024-02-12T23:48:40Z")

</div>

I got home, so was able to make something to do what you want. Here is a prototype that I used and it seems to be working.

```auto
hello_world_device := class(creative_device):

    @editable
    DamagePowerup : damage_amplifier_powerup_device = damage_amplifier_powerup_device{}

    var IncreaseRate : float = 1.0

    # Starting Damage Multiplier
    var DamageMultiplier : float = 1.0

    # Set up the powerup with some default values
    OnBegin<override>()<suspends>:void=
        InitCustomDamagePowerup()

    InitCustomDamagePowerup():void=
        DamagePowerup.SetDuration(IncreaseRate)
        DamagePowerup.SetMagnitude(DamageMultiplier)
        DamagePowerup.Spawn()
    
    # This will loop through forever, and continuously increase the damage of the player
    # Goes beyond the max amplifier of 4.0

    IncreaseDamageLoop(Agent : agent)<suspends>:void=
        Print("Increasing damage!")
        loop: 
            Sleep(IncreaseRate)
            # Cast the agent to a player
            if (Player := player[Agent]):
                # If the powerup is still on, don't bother increasing. Wait till it times out
                if (DamagePowerup.GetRemainingTime(Player) = 0.0):
                    set DamageMultiplier += 0.1
                    DamagePowerup.SetMagnitude(DamageMultiplier)
                    
                    # Spawning and then picking it up
                    DamagePowerup.Spawn()
                    DamagePowerup.Pickup(Player)
                    Print("Set power up to {DamageMultiplier}")
                else:
                    Print("Agent has no effect. Remaining : {DamagePowerup.GetRemainingTime(Player)}")
            else:
                Print("Agent has no effect. No player or character found.")

```

```auto
game_manager := class(creative_device):

    @editable
    ClassSelector : class_and_team_selector_device = class_and_team_selector_device{}

    @editable
    var HelloWorldDevice : hello_world_device = hello_world_device{}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        ClassSelector.ClassSwitchedEvent.Subscribe(OnClassChanged)

    OnClassChanged(Agent:agent):void=
        # See if the person that switched is actually a player
        if (Player := player[Agent]):
            Print("Spawning HelloWorldDevice")
            spawn:
                # I pass the raw Agent here because I am paraniod. I check again that it is a player in the IncreaseDamageLoop
                HelloWorldDevice.IncreaseDamageLoop(Agent)

```

I then added the HelloWorldDevice, GameManager, ClassSelector, and Damage Power Up into the world, and assigned their references.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/8/6/4867dd4d2f4612f5787fc412ad3e9fe7987671b8.jpeg)

---

<div class="post-metadata">

**Author:** ![Burntoast422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Burntoast422](https://forums.unrealengine.com/u/Burntoast422)\
**Post date:** [February 13, 2024, 6:22am UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/13 "2024-02-13T06:22:54Z")

</div>

It works! thanks a bunch

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [March 14, 2024, 6:23am UTC](https://forums.unrealengine.com/t/damage-pickup-agent-not-working/1683220/14 "2024-03-14T06:23:18Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
