Raised This Month: $12 Target: $400
 3% 

Solved [TF2] Optional Instant Respawn Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zebirb
New Member
Join Date: Jul 2018
Old 07-22-2018 , 01:41   [TF2] Optional Instant Respawn Help
Reply With Quote #1

Hi everybody,

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.

Quote:
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!

Last edited by Zebirb; 07-24-2018 at 02:01. Reason: making my paragraphs a little more spaced out and ez to read
Zebirb is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 07-22-2018 , 04:17   Re: [TF2] Optional Instant Respawn Help
Reply With Quote #2

For the Dead Ringer portion, check if the event's death_flags property has TF_DEATHFLAG_DEADRINGER set:

Code:
if (event.GetInt("death_flags") & TF_DEATHFLAG_DEADRINGER) {
    // player feigned death
}
No idea about the class menu detection, other than polling the ConVar you mentioned. Any VGUI events I'd hook into are handled directly on the client's side without the server doing any work.

Would triggering the instant respawn with the Medic! voice keybind be sufficient? You could force the respawn at that point and open up the class select menu to allow class selection. Not 100% sure if it's blocked by the freezecam, though.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Zebirb
New Member
Join Date: Jul 2018
Old 07-23-2018 , 00:45   Re: [TF2] Optional Instant Respawn Help
Reply With Quote #3

Thanks so much for the help!! Using the flag worked. I'm still trying to figure out how to make the ragdolls of players match up with what their original class was, but your help has made the plugin actually usable! I'm super new to sourcemod and C++ in general, so having the direct names of what I should be looking for (like you gave) is incredibly useful. Thanks again!

Figured out the ragdoll issue: just add a delay before changing classes (and before the respawn!) so brief that nobody but the game notices it's happening.
For Example:
Quote:
/*Sets player class to civilian so that instant respawn can be triggered via selecting
the same class as was being previously used*/
public Action:OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));

new booleadRingered = GetEventInt(event, "death_flags") & TF_DEATHFLAG_DEADRINGER;
if (!DeadRingered){
//use a timer to make sure ragdolls are the correct class
CreateTimer(0.1, ClassChangeDelay, client);
}
}

/*Sets class after extremely short delay*/
public Action ClassChangeDelay(Handle timer, any client)
{
TF2_SetPlayerClass(client, TFClass_Unknown, false, false);

return Plugin_Stop;
}
note: if you don't do it for the respawn, and you have code similar to what i wrote, your players will turn into civilians if they change classes while still alive.

Last edited by Zebirb; 07-24-2018 at 01:59. Reason: updated with new info, didn't want to bump :)
Zebirb is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:54.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode