Give player item on Custom Zombie elimination

Can’t figure out how to give a player anything after eliminating a custom zombie. I understand that the CustomPlayer.Collect would fail at the the end because the agent here is the custom zombie. Am I misunderstanding that? The code that displays the message from the HUD_Message_Device only displays if set to show all instead of triggering player.

CustomZombie_Manager := class(creative_device):

    GameManager : Game_Manager = Game_Manager{}

    @editable ZombieSpawners : []creature_spawner_device = array{}
    @editable CustomProp1 : creative_prop_asset = DefaultCreativePropAsset
    @editable ZombieElimCurrency : float = 5.0
    @editable ElimMessage : hud_message_device = hud_message_device{}

    @editable ElimTrigger : trigger_device = trigger_device{}


    OnBegin<override>()<suspends>:void=
        for(Spawner : ZombieSpawners):
            Spawner.SpawnedEvent.Subscribe(OnSpawned)
        ElimTrigger.TriggeredEvent.Subscribe(OnTriggered)

    OnSpawned(ZombieAgent : agent) : void=
        if(FC := ZombieAgent.GetFortCharacter[]):
            FC.Hide()
            if(NewProp := SpawnProp(CustomProp1 , FC.GetTransform().Translation, FC.GetTransform().Rotation)(0)?):
                spawn:
                    TrackZombie(NewProp , ZombieAgent)

    TrackZombie(Prop : creative_prop, Agent : agent)<suspends> : void=
        if(FC := Agent.GetFortCharacter[]):
            race:
                block:
                    FC.EliminatedEvent().Await()
                    ElimTrigger.Trigger(Agent)
                    Prop.Dispose()
                    return
                loop:
                    Sleep(0.0)
                    ZombiePos := FC.GetTransform().Translation
                    ZombieRot := FC.GetTransform().Rotation
                    spawn{Prop.MoveTo(ZombiePos,ZombieRot , 0.1)}

    OnTriggered(Agent : ?agent):void=
        ElimMessage.Show()
        if(Player:= player[Agent?], CustomPlayer := GameManager.PlayersMap[Player]):
            CustomPlayer.Collect(ZombieElimCurrency, "Resource2")

When using the .Show Function for the Hud Message Device if you want it to show for a specific player you will need to provide the player as a paremeter eg .Show(Agent)
since you have an agent optional which means when the function is run there may or may not be a provided player you will need to handle that and place it under an if condition that checks for the player

if(RealAgent:=Agent?):
    ElimMessage.Show(Agent)

Essentially inside the if runs the elimmessage.show only if there is an agent provided and if there is it names that as a constant named RealEgent (You can change that name)

Thank you for explaining that. The code that comes after for CustomPlayer.Collect does not do what it should. I am testing it out and I get nothing after eliminating my custom zombies.

Would you happen to know why and what I can do to fix that?

I did try to add Agent to the ElimMessage.Show() and got an error. I’m not too concerned with this part as I am with giving the eliminating player currencies for the elimination. How can I get the eliminating player so that I can give them stuff?

if(RealAgent:=Agent?):

You need to have this ^ and then whenever an agent is needed you pass RealAgent instead