I've set up some scripting in a mod of mine where copies of an enemy spawn in OnHit. I have no problem with this--the problem is with trying to clean up after them. I'd like to be able to Kill and/or Delete all of them once I'm done, so that they're not cluttering up the place.
What I have on each of the enemies (applied to the base NPC, so that each enemy spawns with a copy of the script):
Scriptname EnemyScript extends ObjectReference
Function KillAllEnemies()
Self.Delete()
endFunction
And then, from there, I want to use another script to delete them from afar. What I tried was:
Scriptname KillScript extends EnemyScript
Event OnActivate(ObjectReference akActionRef)
KillAllEnemies()
EndEvent
While I didn't get any actual errors, the problem was that when I called KillAllEnemies, it used Self on the activator I had attached KillScript to, not on the enemies. I know that I could accomplish this with SKSE and a GetNumRefs/GetNthRef script, but for reasons of compatibility, I'm trying to figure out some way to do this without using SKSE functions. The difficult part is that I can't, say, set properties that point to the enemies, because of the way they'll spawn in.
At the moment, I'm using an OnCellDetach event in the EnemyScript to handle it, and while it works, I'd like to find a way to make this more flexible.