damage.Pickup(Agent) not working

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.

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:

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.

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.

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.

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.


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]

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.

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 : / )

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.

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)

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

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)

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.

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.")
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.

1 Like

It works! thanks a bunch

1 Like

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