How do I grab the instigator of AgentEntersEvent in a function?

Plz no judgement i have very little experience with code, I can stutter my way through html and css, and the best I can do is a console calculator in c++…

What I’m trying to make is Basically a mutator zone, which, every 2 seconds heals the player inside it with 45 health. What I’m struggling with is the last part of the code (what any experienced programmer would probably notice). I originally wanted to write this like this:

Heal(Agent : agent) : void =
Instigator : agent = HealingZone.GetInstigatorAgent()
        HealthPowerup.Pickup(Instigator)

but then I found some simmilar forum question, and i tried applying the responses to it in my own code, but it still doesnt work.

Heal(Agent : agent) : void =
        if (Agent := Heal.GetInstigatorAgent[]):
            HealthPowerup.Pickup(Agent)

I tried every possible combination i could think of haha (like HealingZone.AgentEntersEvent.GetInstigatorAgent() and so on), but I honestly have no idea what I’m doing. I took the time to learn the very basics of this language, and I got that, but only that.

Here’s my full code for more context:

using { /Fortnite.com/Playspaces }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# TODO: Heal players inside the zone 45 health per 2 seconds, excluding hero classes
        

medical_droid_device := class(creative_device):
    #A zone, within all Players will receive health
    @editable
    HealingZone : mutator_zone_device = mutator_zone_device{}
    #the poweup, which wil be activated for players inside the zone
    @editable
    HealthPowerup : health_powerup_device = health_powerup_device{}

    OnBegin<override>()<suspends>:void=
        HealingZone.AgentEntersEvent.Subscribe(Heal)
    
    Heal(Agent : agent) : void =
        if (Agent : agent := HealingZone.GetInstigatorAgent[]):
            HealthPowerup.Pickup(Agent)

Here’s my errors

and if anyone would be kind enough, I also need to make a loop with sleep 2, to make the every 2 seconds healing thing, but I have no idea how can I make the AgentExitsEvent break the loop? do i cal it in the loop? On begin? (this came to my mind as of writing this) can I write:

loop:
HealingZone.AgentExitsEvent.Subscribe(break)
#heal
#sleep

?
I’m asking because I cant check it right now. thanks to anyone who takes the time to read this and responds. I just really wanna learn this language

Not sure what I’m overlooking in your main question here.

Re: instigator:

The docs says this:

# Signaled when an `agent` enters this zone.
# Sends the `agent` entering this zone.
AgentEntersEvent<public>:listenable(agent) = external {}

The important part is “Sends the agent entering this zone.”.

Therefore here’s your instigator agent.

Heal(Agent: agent): void = { ... }
   # ^~~~~~~~~~~~

Re: healing.

  • Create a custom data structure that tracks it per instigator (probably fort_character after you obtained it from the agent). That could be var TaskMap: [fort_character]?task() = map {}
  • there’s no explicit cancellation in verse yet, so you have to workaround it, add another map that tracks the active healing state var FlagMap: [fort_character]logic = map {}
  • when your player enter the zone, spawn a new async task which would loop the healing, but you also have to add a way to break it

Quick pseudocode:

Heal(Agent: agent): void = {
  ForChar := # obtain `fort_character` from `agent`
  # set the healing flag
  if (set FlagMap[ForChar] = true) {}

  # create a new task, NOTE, the previous task must be cancelled by now, that's
  # up to you to guarantee, or you will double heal
  Task := spawn { HealLoopForChar(ForChar) }
  # save it
  if (set TaskMap[FortChar] = option { Task }) {}
}

HealLoopForChar(FortChar: fort_character)<suspends>: void = {
  loop {
    # check if the flag is rest, to break the loop
    if (ShouldHeal := FlagMap[FortChar], not ShouldHeal?) {
      break
    }

    # heal `FortChar`
   
    # sleep 2 seconds until next iteration
    Sleep(2.0)
  }
}
  • when your player exists the zone just reset FlagMap for your instigator player to false
StopHeal(Agent: agent): void = {
  FortChar := # obtain `fort_character` from `agent`
  # reset the healing flag
  if (set FlagMap[FortChar] = false) {}

  # Throw away the task
  if (set TaskMap[FortChar] = false) {}
}

Note: All of this is written from memory, not tested, not compiled, could contain typos. You’ll figure out the rest. :wink:

1 Like