# Verse code to heal the player

**URL:** <https://forums.unrealengine.com/t/verse-code-to-heal-the-player/1674893>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [February 8, 2024, 7:44pm UTC](https://forums.unrealengine.com/t/verse-code-to-heal-the-player/1674893 "2024-02-08T19:44:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FinestCreative](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finestcreative/32/1034971_2.png) [@FinestCreative](https://forums.unrealengine.com/u/FinestCreative)\
**Post date:** [February 8, 2024, 7:44pm UTC](https://forums.unrealengine.com/t/verse-code-to-heal-the-player/1674893/1 "2024-02-08T19:44:34Z")

</div>

I use this code in all my maps to heal a player, use it like this or add to it if you want!

```auto
HealAgent<public>(Agent:agent, Amount:float):void={
  if(FortCharacter := Agent.GetFortCharacter[]):
      HP := FortCharacter.GetHealth()
      Shield := FortCharacter.GetShield()
    
      HPMissing := FortCharacter.GetMaxHealth() - HP
    
      FortCharacter.SetHealth(Clamp(HP + Amount,0.0,FortCharacter.GetMaxHealth()))
      FortCharacter.SetShield(Clamp(Shield + Clamp(Amount - HPMissing,0.0,Amount),0.0,FortCharacter.GetMaxShield()))
  }

```

Example: Heal player for 3s, +10 healing per second, on elimination

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
example := class(creative_device):
    @editable EliminationManager:elimination_manager_device = elimination_manager_device{}

    OnBegin<override>()<suspends>:void={
        EliminationManager.EliminationEvent.Subscribe(PlayerEliminatedHelper)
    }

    PlayerEliminatedHelper<private>(MaybeAgent:?agent):void={
        if( Agent:= MaybeAgent?):
            spawn{PlayerEliminated(Agent)}
    }
    PlayerEliminated<private>(Agent:agent)<suspends>:void={
        for(I:=0..2):
          HealAgent(Agent,10)
          Sleep(1.0)
    }

```

---

<div class="post-metadata">

**Author:** ![WeaselUNRL10407](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@WeaselUNRL10407](https://forums.unrealengine.com/u/WeaselUNRL10407)\
**Post date:** [April 23, 2024, 11:51pm UTC](https://forums.unrealengine.com/t/verse-code-to-heal-the-player/1674893/2 "2024-04-23T23:51:03Z")

</div>

Hello, the code is now down with many errors, I made a version that works :

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Fortnite.com/Characters }

example := class(creative_device):
    @editable
    EliminationManager: elimination_manager_device = elimination_manager_device{}

    OnBegin<override>()<suspends>: void = {
        EliminationManager.EliminationEvent.Subscribe(PlayerEliminatedHelper)
    }

    PlayerEliminatedHelper<private>(MaybeAgent: ?agent): void = {
        if (Agent := MaybeAgent?) {
            spawn { PlayerEliminated(Agent) }
        }
    }

    PlayerEliminated<private>(Agent: agent)<suspends>: void = {
        for (I := 0..2) {
            HealAgent(Agent, 10.0) # Ensure 10 is treated as a float
            Sleep(1.0)
        }
    }

    HealAgent<public>(Agent: agent, Amount: float): void = {
        if (FortCharacter := Agent.GetFortCharacter[]) {
            HP := FortCharacter.GetHealth()
            Shield := FortCharacter.GetShield()

            HPMissing := FortCharacter.GetMaxHealth() - HP

            FortCharacter.SetHealth(Clamp(HP + Amount, 0.0, FortCharacter.GetMaxHealth()))
            FortCharacter.SetShield(Clamp(Shield + Clamp(Amount - HPMissing, 0.0, Amount), 0.0, FortCharacter.GetMaxShield()))
        }
    }
```

---

<div class="post-metadata">

**Author:** ![LosesoIcanwin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LosesoIcanwin](https://forums.unrealengine.com/u/LosesoIcanwin)\
**Post date:** [April 15, 2025, 10:40am UTC](https://forums.unrealengine.com/t/verse-code-to-heal-the-player/1674893/3 "2025-04-15T10:40:08Z")

</div>

Do you know how you’d go about calling an event when a players health is full/fully healed?
