Skip to content

Commit

Permalink
Disable respawns on Sudden Death / Arena mode
Browse files Browse the repository at this point in the history
Closes #25.
  • Loading branch information
nosoop committed Jul 14, 2021
1 parent 0e65be3 commit 7ce9e4b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions scripting/cwx.sp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void OnClientCustomLoadoutItemModified(int client, int modifiedClass) {
return;
}

if (IsPlayerInRespawnRoom(client) && IsPlayerAlive(client)) {
if (IsPlayerAllowedToRespawnOnLoadoutChange(client)) {
// see if the player is into being respawned on loadout changes
QueryClientConVar(client, "tf_respawn_on_loadoutchanges", OnLoadoutRespawnPreference);
} else {
Expand All @@ -453,7 +453,7 @@ void OnLoadoutRespawnPreference(QueryCookie cookie, int client, ConVarQueryResul
const char[] cvarName, const char[] cvarValue) {
if (result != ConVarQuery_Okay) {
return;
} else if (!StringToInt(cvarValue) || !IsPlayerInRespawnRoom(client)) {
} else if (!StringToInt(cvarValue) || !IsPlayerAllowedToRespawnOnLoadoutChange(client)) {
// the second check for respawn room is in case we're somehow not in one between
// the query and the callback
PrintToChat(client, "%t", "LoadoutChangesUpdate");
Expand Down Expand Up @@ -492,3 +492,21 @@ static bool IsPlayerInRespawnRoom(int client) {
AddVectors(vecOrigin, vecCenter, vecCenter);
return TF2Util_IsPointInRespawnRoom(vecCenter, client, true);
}

/**
* Returns whether or not the player is allowed to respawn on loadout changes.
*/
static bool IsPlayerAllowedToRespawnOnLoadoutChange(int client) {
if (!IsClientInGame(client) || !IsPlayerInRespawnRoom(client) || !IsPlayerAlive(client)) {
return false;
}

// prevent respawns on sudden death
// ideally we'd base this off of CTFGameRules::CanChangeClassInStalemate(), but that
// requires either gamedata or keeping track of the stalemate time ourselves
if (GameRules_GetRoundState() == RoundState_Stalemate) {
return false;
}

return true;
}

0 comments on commit 7ce9e4b

Please sign in to comment.