(RPGMXP) have the player respawn at a set location after death in random battle

hello everyone what I would like for my game is to have a machine which re-spawns the player if he dies in certain rooms and I would like to have it switch activated. so if someone could write a script which says if the player dies in room A and switch 1 is on he will be teleported to room B with 1 health.
also if you could write a second version which also changes character aswell I would be super grateful thanks in advance everyone

Original thread: https://forums.rpgmakerweb.com/threads/rpgmxp-have-the-player-respawn-at-a-set-location-after-death-in-random-battle.36617/