How can I make it so when a player is hit it deals 5 damage to the hit player? I dont know why im having so much trouble with this.

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Game }
using { /Fortnite.com/Characters }

hit_detect_device := class(creative_device):
var Players : player = array{}

HandlePlayerHit(DamageResult : damage_result) : void =
    Target := DamageResult.Target
    Amount := DamageResult.Amount

    if (FortCharacterWhoWasHit := fort_character[Target]):
        Print("Was hit for {Amount}")
        FortCharacterWhoWasHit.Damage(Amount + 0.005)

    if (Instigator := DamageResult.Instigator?, Agent := Instigator.GetInstigatorAgent[], FortCharacterInstigator := Agent.GetFortCharacter[]):
        Print("Was hit by another player")
        FortCharacterInstigator.Damage(Amount * 0.005)

OnBegin<override>()<suspends>:void=
    set Players = GetPlayspace().GetPlayers()

    if (Boss := Players[0], FortBoss := Boss.GetFortCharacter[]):
        FortBoss.DamagedEvent().Subscribe(HandlePlayerHit)
1 Like
FortCharacterWhoWasHit.Damage(Amount + 0.005)
FortCharacterInstigator.Damage(Amount * 0.005)

if you want after they’re hit to take 5 more damage shouldn’t those be (5.0)

I will be able to try it myself maybe next hour and see if there’s anything else wrong

Ok so this took me WAYYY too long to work but here’s the fixed code

    var Players : []player = array{}
    OnBegin<override>()<suspends>:void=
        set Players = GetPlayspace().GetPlayers()
        if (Boss := Players[0], FortBoss := Boss.GetFortCharacter[]):
            FortBoss.DamagedEvent().Subscribe(HandlePlayerHit)

    HandlePlayerHit(DamageResult : damage_result) : void =
        Target := DamageResult.Target
        Amount := DamageResult.Amount
    
        if (FortCharacterWhoWasHit := fort_character[Target]):
            Print("Was Hit for {Amount}")
            if(not DamageResult.Source?):
                FortCharacterWhoWasHit.Damage(5.0)

Why does that ^ work, I don’t know. Initially I thought I could just make it so if the instigator was a agent or fort_character it would only work then, turned out damage_result would just give the agent who got damaged as the instigator instead of the agent who damaged them causing an infinite loop I will try to further search this and maybe do a bug report

Here’s the bug report if you want to vote on it

Hello! So it works I would like to thank you very much but there is still one issue. When using the script it only applies for the first player in the game and no one else. Meaning only that player can do the extra damage to himself and others can do it only to that player. Do you think you can make it so it applies to everyone in the game? Also one extra thing is that can you make it so NPCs can deal extra damage to others? Thank you!

1 Like
if (Boss := Players[0], FortBoss := Boss.GetFortCharacter[]):
            

Replace it with this

for (Player : Players):
   if(FC:Player.GetFortCharacter[]):
      FC.DamagedEvent.Subscribe(HandlePlayerHit)
            

As for the npcs idk

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