You need to write the function you are calling. Subscribe binds to a function called OnAIDeath, but there is no function by that name. The function should probably look something like this:
OnAIDeath(Agent:agent): void =
Print(“Guard has been eliminated.”)
In the above, you would put whatever expressions you wanted to happen after the guard is eliminated. In the Documentation, there is an elimination game example you can study to understand this more.
If you’d like another example of this in action you can look at the Stronghold Template from within the UEFN Feature Examples.
Here’s a snippet from the stronghold_bark_manager.verse script that shows handling the Eliminated Event and declaring the OnGuardEliminated which would be the same as your OnAIDeath function.
Many of your typical applicated can be found in this project and it’s various verse scripts.
Hope this helps.
#call this SubscribeToGuardSpawnerEvents function in your OnBegin function
SubscribeToGuardSpawnerEvents(GuardSpawnerDevice:guard_spawner_device):void =
GuardSpawnerDevice.DamagedEvent.Subscribe(OnGuardDamaged)
GuardSpawnerDevice.EliminatedEvent.Subscribe(OnGuardEliminated)
GuardSpawnerDevice.EliminatingEvent.Subscribe(OnPlayerEliminated)
#an example of doing something when a guard is eliminated, like playing a sound effect device
OnGuardEliminated(InteractionResult:device_ai_interaction_result):void=
if (EliminatedGuard := InteractionResult.Target?):
# Find closest alive guard to play this bark
var ClosestGuard:?agent = false
if:
set ClosestGuard = option{StrongholdGameManager.AlertedGuards[0]}
EliminatedGuardCharacter := EliminatedGuard.GetFortCharacter[]
then:
for (AlertedGuard : StrongholdGameManager.AlertedGuards, AlertedGuardCharacter := AlertedGuard.GetFortCharacter[]):
if:
not ClosestGuard? = AlertedGuard
ClosestGuardCharacter := ClosestGuard?.GetFortCharacter[]
DistanceSquaredToAlertedGuard := DistanceSquared(AlertedGuardCharacter.GetTransform().Translation, EliminatedGuardCharacter.GetTransform().Translation)
DistanceSquaredToClosestGuard := DistanceSquared(ClosestGuardCharacter.GetTransform().Translation, EliminatedGuardCharacter.GetTransform().Translation)
DistanceSquaredToAlertedGuard < DistanceSquaredToClosestGuard
then:
set ClosestGuard = option{AlertedGuard}
if (Guard := ClosestGuard?):
spawn {BarkNPCDown.PlayBark(Guard)}