Is there any way to store the last target ID in a variable?

I would like to know if it is possible to store the ID of the last target in a variable. RPG Maker MZ has a function like this, but is there any way to apply this to XP?
I suspect that you'd need a script to allow you to do something like that. XD

Original thread: https://forums.rpgmakerweb.com/threads/is-there-any-way-to-store-the-last-target-id-in-a-variable.167645/