changing knockout/death

I wounder if anyone can help me with something.

i'm trying to make it so if a character is knocked out they are removed from the party. but if the main character is knocked out, you are teleported to town. I know (think) i can get a common event to do this, but i'm having trouble getting the common event to trigger before game over.

I've tried making a common event the runs parallel that says if actor 1 is knocked out, do this. I tried making a condition statement inside a troop event that said if actor 1 is knocked out call common event. neither of these have worked. any idea how to do this? 

thanks in advance
You can use this to transfer your player to certain map before game over. Maybe you can recover your party and transfer elsewhere, I don't know how it's work though.
Gameover Events
 
or use this snippet (select all the text, and save it as *.js file)

Spoiler
Code:
/*: * @plugindesc SSG Game Over Common Event *  * @help * * @param Common Event ID * @desc common event ID which you want to run before game over scene.  * Default value = 0 * @default 0 */ (function($) {// overwrite$.updateBattleEnd = function() {	var _params = $plugins.filter(function(plugin) {		return plugin.description.indexOf("SSG Game Over Common Event") != -1;	})[0].parameters;	var _id = Number(_params['Common Event ID']) || 0;	    if (this.isBattleTest()) {        AudioManager.stopBgm();        SceneManager.exit();    } else if ($gameParty.isAllDead()) {        if (this._canLose) {            $gameParty.reviveBattleMembers();            SceneManager.pop();        } else {			if (_id > 0) {				$gameParty.reviveBattleMembers();				$gameTemp.reserveCommonEvent(_id);				SceneManager.pop();			} else {				SceneManager.goto(Scene_Gameover);			}        }    } else {        SceneManager.pop();    }    this._phase = null;};})(BattleManager);
That's great thank you so much

Original thread: https://forums.rpgmakerweb.com/threads/changing-knockout-death.53181/