I have a looping function that heals the player when they enter a zone but it’s healing when they leave the zone and it stacks on itself if they reenter which I don’t want, how can I make the loop stop once they trigger the AgentExitsEvent? I think I use the race expression for this but I’m not really sure, thanks!
The race keyword is used when starting multiple asynchronous functions at the same time. I think an easier solution might be to create a variable that stores data on the player being inside the area. Basically, create a boolean (logic) variable that says whether or not the player is inside, and change that variable anytime the player either enters or exits. Then you can do the healing as long as the variable is true (which will change anytime the event is fired off) For example:
IsPlayerInsideHealZone : logic = false
HealPlayer(Agent : agent)<suspends> : void =
loop:
if (IsPlayerInsideHealZone = false):
break
Sleep(1.0)
if (Player := player[Agent]):
if (FortniteCharacter : fort_character = Player.GetFortCharacter[]):
FortniteCharacter.Heal(5.0)
HandleAgentEnter( Agent : agent ) : void =
set IsPlayerInsideHealZone = true
spawn:
HealPlayer
# Then create the function for agent exiting field
HandleAgentExit( Agent : agent ) : void =
set IsPlayerInsideZone = false
OnBegin<override>()<suspends>:void=
HealZone.AgentEntersEvent.Subscribe(HandleAgentEnter)
HealZone.AgentExitsEvent.Subscribe(HandleAgentExit)