Infinite loop keeps happening when NPC dies. Damage works fine until death. HandlePlayerHit makes it so the NPC deals extra damage when it is hit. I need this to stop having errors.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/AI }
using { /Verse.org/Random }
using { /Fortnite.com/Game }
I’ve added a break condition to halt the loop when FortChar is Eliminated , which is a straightforward fix to prevent an infinite loop. Additionally, I moved the subscribe on DamagedEvent outside of the loop since it only needs to be subscribed to once. However, I believe there is room for improvement in the overall code structure. It would be beneficial to refactor the Npc Spawner and its related components into a separate class, enabling us to utilize subscriptions instead of the current await and loop approach, leading to more efficient and cleaner code.
DamageTracker(FortChar : fort_character,MaxHealth : float)<suspends>: void =
var Health : float = MaxHealth
FortChar.DamagedEvent().Subscribe(HandlePlayerHit)
loop:
LoopResult := race:
block:
FortChar.EliminatedEvent().Await()
1
block:
DamageStruct := FortChar.DamagedEvent().Await()
set Health -= DamageStruct.Amount
2
if (LoopResult = 1):
break
It is supposed to make it so when you select a npc spawner it makes all npcs on that spawner have the extra damage dealt. But when I eliminate the npc the verse breaks and gives an infinite loop error making it not be able to do extra damage anymore.
It still gives an error when the npc dies. It says it has something to do with my HandleHit event but that is not a loop and it keeps saying it is. I really dont know how to fix it.
Here is my modified script. But still the same error.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/AI }
using { /Verse.org/Random }
using { /Fortnite.com/Game }
Here’s a quick script I made/edited for guard spawners (might need some fine tuning for npc spawner) where it grabs their fort_character at their spawn and places it into an array then and only then when a player is damaged if the instigator is the guard it will do extra 40 damage, and I have also made it where if a non-arrayed fort_character who is not the same as the target it will do extra 4 dmg (can be removed).
As you can see in this video whenever the bot hits me for 21 dmg it deals an additional 40 and when I hit the player aside from the normal 30 the scar does it will also deal 5 more additional damage
@editable Spawners : []guard_spawner_device = array{}
@editable EnableTrigger : trigger_device = trigger_device{}
@editable DisableTrigger : trigger_device = trigger_device{}
@editable Enabled : logic = true
var CreatureArray : []fort_character = array{}
OnBegin<override>()<suspends>:void=
for (Spawner : Spawners):
Spawner.SpawnedEvent.Subscribe(CreatureSpawned)
Spawner.EliminatedEvent.Subscribe(CreatureDeSpawned)
for(Player:GetPlayspace().GetPlayers()):
if(FC:=Player.GetFortCharacter[]):
FC.DamagedEvent().Subscribe(HandlePlayerHit)
HandlePlayerHit(DamageResult : damage_result) : void =
Target := DamageResult.Target
Amount := DamageResult.Amount
if (FortCharacterWhoWasHit := fort_character[Target],Amount>=1.0):
Print("Was Hit for {Amount}")
if(TargetFC:=fort_character[DamageResult.Target],InstigFC:=fort_character[DamageResult.Instigator?],not TargetFC=InstigFC):
if(CreatureArray.Find[InstigFC]):
Print("MONSTER DAMAGE")
FortCharacterWhoWasHit.Damage(40.0)
else:
Print("HOOMAN DAMAGE")
FortCharacterWhoWasHit.Damage(5.0)
CreatureSpawned(Agent : agent): void =
if (Enabled = true):
if (FortChar := Agent.GetFortCharacter[]):
set CreatureArray += array{FortChar}
CreatureDeSpawned(Result : device_ai_interaction_result): void =
if (Target:=Result.Target?):
if (FortChar := Target.GetFortCharacter[]):
set CreatureArray = CreatureArray.RemoveAllElements(FortChar)
Print("CREATURE REMOVED")