I have recently been trying to make a plugin where a player is able to decide whether or not they would like to sit through the freeze cam zoom or instantly respawn. To choose the instant respawn, the player needs to go into the class menu and choose a class (even the class they are currently, if they'd like to remain that class). My first solution was to have a forced respawn when they changed classes, which works fine, but doesn't allow the player to instantly respawn if they don't want to change their class. I added a few lines that would make the player become a Civilian/Unknown class when they die, so that way they'd always be changing classes when picking a class from the menu.
public Action:OnPlayerDeath(Handle:event, const String:name, bool:dontBroadcast)
new client = GetClientOfUserId(GetEventInt(event, "userid"));
TF2_SetPlayerClass(client, TFClass_Unknown, false, false);
This seemed to work initially, with a harmless bug of all class models turning into the scout model on death... but then it turns out that when a spy dies with the dead ringer, the game counts the fake death as a "true" death. When the spy decloaked they could no longer move and had the other Civilian class afflictions. I attempted adding a IsPlayerAlive() check to the OnPlayerDeath event to ensure that the player is definitely truly dead, but that check was ignored by the game. I found that there was a freezecam_started hook event on the AM wiki, but it seems to have been depreciated or something, as it no longer works.
I played around with the idea of using the _cl_classmenuopen convar to detect when a player was opening the class menu and using that to change class before a class was picked from the menu. The problem is that I couldn't figure out a way to save the player's original class, just in case they decided to sit through the death cam and cancelled instead. I was also looking to see if maybe there was an option to see if a player was in the death-spectator mode, but it doesn't seem like there's much of anything in TF2 that differentiates between the team spectate mode and death spectate, or when these might be triggered outside of player_death. There may be other signals that trigger after a player is dead or tell the game whether a death was a dead ring or not, but I'm having trouble finding these.
Are there any other triggers/convar changes that I could use to know when it is an appropriate time to set a player's class to the civilian class? Or is there any other type of work-around to allow a player to select the class that they currently are and have it count as some sort of change class, but still allow a player to naturally respawn if they so choose?
Thank you so much for any and all help!