Provides more options for both games, such as when the screen should turn black and white and how many revives are allowed.
Options to control when the heartbeat sound plays and when survivors should start vocalizing that they're about to die.
This plugins cvar l4d_heartbeat_revives overwrites the games survivor_max_incapacitated_count cvar, so set your desired value in this plugins cvar config.
Cvar default values of "2" is what the game uses by default.
This fixes L4D1 players going from black and white on the 2nd revive to normal color after subsequent revives when increasing the survivor_max_incapacitated_count cvar value.
In L4D1 this plugin overwrites and controls "m_currentReviveCount" netprop. Because this variable can no longer be relied on, plugins using that must change to use the 2 natives provided for accurate revive counts.
In L4D2 this plugin overwrites and controls "m_bIsOnThirdStrike". This netprop and the one above are used to make players screen black and white.
Natives: (for 3rd party revive/respawn style plugins)
Spoiler
3rd party plugins (especially revive/respawn plugins) can use the following natives to get and set the revive count, when not reverting to 0 revives on player spawn.
Use the get native if required, then revive/respawn the player, then call the set native with your desired value, otherwise it will be set to 0.
PHP Code:
/**
* @brief Gets the revive count of a client.
* @remarks Because this plugin overwrites "m_currentReviveCount" netprop in L4D1, this native allows you to get the actual revive count for clients.
*
* @param client Client index to affect.
*
* @return Number or revives
*/
native int Heartbeat_GetRevives(int client);
/**
* @brief Sets the revive count on a client.
*
* @param client Client index to affect.
* @param reviveCount The Survivors revive count.
* @param reviveLogic Triggers the revive logic which determines if someones screen is black and white, if the heartbeat should play etc.
* Setting to false would only set their revive count and the Heartbeat settings would not be followed. Should probably always be default: true.
*
* @noreturn
*/
native void Heartbeat_SetRevives(int client, int reviveCount, bool reviveLogic = true);
The following code can be copy pasted into your plugin and adapted for usage.
PHP Code:
// Globals
native void Heartbeat_SetRevives(int client, int reviveCount, bool reviveLogic = true); // To allow calling the native, instead of using an include file.
bool g_bHeartbeatPlugin;
// Plugin start detect.
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
MarkNativeAsOptional("Heartbeat_SetRevives");
}
// Code to put in your function.
void YourRespawnFunction()
{
if( g_bHeartbeatPlugin )
{
// Set to specific value;
Heartbeat_SetRevives(client, 2); // Set the number of current revives, 0 or greater
// ===== OR =====
// Get current revive count
int revives = Heartbeat_GetRevives(client);
"Dragokas" - For the inspiration and help testing.
Admin Command:
PHP Code:
// Set someone as black and white health status or toggle their state. Usage: sm_heartbeat [#userid|name] [state: 0=Healed. 1=Black and white.]
sm_heartbeat
CVars:
Saved to l4d_heartbeat.cfg in your servers \cfg\sourcemod\ folder.
PHP Code:
// 0=Plugin off, 1=Plugin on.
l4d_heartbeat_allow "1"
// Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).
l4d_heartbeat_modes ""
// Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).
l4d_heartbeat_modes_off ""
// Turn on the plugin in these game modes. 0=All, 1=Coop, 2=Survival, 4=Versus, 8=Scavenge. Add numbers together.
l4d_heartbeat_modes_tog "0"
// 0=Off. 1=Set black and white status when someone is incapped, not after revive.
l4d_heartbeat_incap "0"
// How many revives are allowed before a player is killed (wrapper to survivor_max_incapacitated_count cvar).
l4d_heartbeat_revives "2"
// How many revives until the black and white screen overlay starts.
l4d_heartbeat_screen "2"
// How many revives until the heartbeat sound starts playing.
l4d_heartbeat_sound "2"
// How many revives until the player starts vocalizing that they're about to die.
l4d_heartbeat_vocalize "2"
1.16 (21-Apr-2024)
- Fixed revive count increasing by 2 instead of 1 under certain circumstances. Thanks to "S.A.S" for reporting.
1.15 (16-Apr-2024)
- Removed gamedata method patching the game which created a health bug. Thanks to "S.A.S" for reporting.
- Fixed issues with "m_isGoingToDie" being set to 0 not damaging the player.
1.14a (26-Mar-2024)
- Fixed the GameData file for Linux servers. Thanks to "S.A.S" for reporting.
1.14 (12-Mar-2024)
- Fixed native "Heartbeat_SetRevives" not setting the correct revive count if "reviveLogic" bool was set to false. Thanks to "little_froy" for reporting and testing.
- Fixed clients not receiving damage from behind when on Easy difficulty, due to "m_isGoingToDie" being est to 0. Thanks to "little_froy" for reporting and testing.
- Fixed client not in game error. Thanks to "HarryPotter" for reporting.
- New GameData file required for the plugin to operate.
1.13 (10-Mar-2023)
- Delayed revive logic by 1 frame to fix settings sometimes not being applied due to self revive plugins. Thanks to "Shao" for reporting.
1.12 (19-Feb-2023)
- Added cvar "l4d_heartbeat_incap" to set black and white status when someone is incapped, not after revive. Requested by "Jestery".
- Fixed heartbeat sound being stopped when other players respawn.
1.11 (03-Dec-2022)
- Plugin now resets the heartbeat sound for spectators.
1.10 (15-Nov-2022)
- Fixed the revive count not carrying over when switching to/from idle state. Thanks to "NoroHime" for reporting.
1.9 (02-Nov-2022)
- Fixed screen turning black and white when they're not read to die. Thanks to "Iciaria" for reporting and lots of help testing.
- Various changes to simplify the code.
1.8 (25-Aug-2022)
- Changes to fix warnings when compiling on SM 1.11.
- Fixed native "Heartbeat_GetRevives" return type wrongfully set as void instead of int.
1.7 (31-Mar-2021)
- Added command "sm_heartbeat" to toggle or specify someone as black and white health status.
1.6 (15-Feb-2021)
- Fixed heartbeat sound playing when replacing a bot. Thanks to "Endoyurei Shirokuro" for reporting.
1.5 (15-Jul-2020)
- Added more StopSound calls on player spawn. Thanks to "Endoyurei Shirokuro" for reporting.
1.4 (10-May-2020)
- Various changes to tidy up code.
1.3 (26-Apr-2020)
- Added native "Heartbeat_GetRevives" for 3rd party plugins to get a players current incap count.
- Added native "Heartbeat_SetRevives" for 3rd party plugins to set a players current incap count.
- Changes to prevent duplicate heartbeat sounds playing.
- Extra checks to prevent "IsAllowedGameMode" throwing errors.
1.2 (11-Apr-2020)
- Fixed not resetting the heartbeat sound on player death.
1.1 (01-Apr-2020)
- Fixed "IsAllowedGameMode" from throwing errors when the "_tog" cvar was changed before MapStart.
1.0 (17-Mar-2020)
- Initial release.
Installation:
Click "Get Plugin" and put the .smx file into your servers \addons\sourcemod\plugins\ folder.