diff --git a/Coroner/API.cs b/Coroner/API.cs index 36d9711..d3791ca 100644 --- a/Coroner/API.cs +++ b/Coroner/API.cs @@ -12,7 +12,7 @@ public class API /// You can set this to a default one (see `Coroner.AdvancedCauseOfDeath`) or a custom one (see `Register()`). /// /// The player to set the cause of death for. - /// The cause of death to use. Set to `null` to clear. + /// The cause of death to use. /// SetCauseOfDeath(player, AdvancedCauseOfDeath.Enemy_ForestGiant); public static void SetCauseOfDeath(PlayerControllerB player, AdvancedCauseOfDeath? causeOfDeath) { @@ -25,7 +25,7 @@ public static void SetCauseOfDeath(PlayerControllerB player, AdvancedCauseOfDeat /// You can set this to a default one (see `Coroner.AdvancedCauseOfDeath`) or a custom one (see `Register()`). /// /// The ID of the player. - /// The cause of death to use. Set to `null` to clear. + /// The cause of death to use. /// SetCauseOfDeath(0, AdvancedCauseOfDeath.Enemy_ForestGiant); public static void SetCauseOfDeath(int playerId, AdvancedCauseOfDeath? causeOfDeath) { @@ -56,6 +56,30 @@ public static void SetCauseOfDeath(int playerId, AdvancedCauseOfDeath? causeOfDe // Call the proper internal method. return AdvancedDeathTracker.GetCauseOfDeath(playerId); } + + /// + /// Resets the cause of death to null for a player object. + /// + /// The player to set the cause of death for. + /// The cause of death for the player. + /// GetCauseOfDeath(0); + public static void ResetCauseOfDeath(PlayerControllerB player) + { + // Call the proper internal method. + AdvancedDeathTracker.SetCauseOfDeath(player, null, true); + } + + /// + /// Resets the cause of death to null for a player with the given ID. + /// + /// The ID of the player. + /// The cause of death for the player. + /// GetCauseOfDeath(0); + public static void ResetCauseOfDeath(int playerId) + { + // Call the proper internal method. + AdvancedDeathTracker.SetCauseOfDeath(playerId, null, true); + } /// /// Register a new cause of death. Useful for mods. diff --git a/Coroner/NetworkRPC.cs b/Coroner/NetworkRPC.cs index 9474bc6..b02937b 100644 --- a/Coroner/NetworkRPC.cs +++ b/Coroner/NetworkRPC.cs @@ -30,6 +30,11 @@ public static void ReportCauseOfDeathServerRpc(int playerClientId, string? codLa [ClientRpc] public static void BroadcastCauseOfDeathClientRpc(int playerClientId, string? codLanguageTag, bool forceOverride) { Plugin.Instance.PluginLogger.LogDebug($"Client received cause of death via RPC: ({playerClientId}, {(codLanguageTag == null ? "null" : codLanguageTag)})"); + if (codLanguageTag == null && !forceOverride) + { + Plugin.Instance.PluginLogger.LogDebug("Resetting cause of death."); + AdvancedDeathTracker.StoreLocalCauseOfDeath(playerClientId,null, forceOverride); + } if (codLanguageTag == null || !AdvancedCauseOfDeath.IsTagRegistered(codLanguageTag)) { Plugin.Instance.PluginLogger.LogError($"Could not deserialize cause of death ({codLanguageTag})"); diff --git a/MODDING.md b/MODDING.md index 415190f..76eb034 100644 --- a/MODDING.md +++ b/MODDING.md @@ -107,11 +107,17 @@ In `BepInEx/config/EliteMasterEric-Coroner/` in your mod upload, create a file n - Retrieves the currently known cause of death for the player by reference, if any. - Returns: An `AdvancedCauseOfDeath`, or `null` if no cause of death is known. - `Coroner.API.SetCauseOfDeath(PlayerControllerB player, AdvancedCauseOfDeath? causeOfDeath)` - - Applies a given cause of death to the player by their client ID. + - Applies a given cause of death to the player by reference. - Provide the `AdvancedCauseOfDeath` via argument. `AdvancedCauseOfDeath` has static constants for all the vanilla causes of death, or you can use one created by `Coroner.API.Register()`. - `Coroner.API.SetCauseOfDeath(int playerId, AdvancedCauseOfDeath? causeOfDeath)` - - Applies a given cause of death to the player by reference. + - Applies a given cause of death to the player by their client ID. - Provide the `AdvancedCauseOfDeath` via argument. `AdvancedCauseOfDeath` has static constants for all the vanilla causes of death, or you can use one created by `Coroner.API.Register()`. +- `Coroner.API.ResetCauseOfDeath(PlayerControllerB player)` + - Resets the cause of death of the player by reference. + - Sets the cause of death to null. +- `Coroner.API.ResetCauseOfDeath(int playerId)` + - Resets the cause of death of the player by their client ID. + - Sets the cause of death to null. - `Coroner.API.StringifyCauseOfDeath(AdvancedCauseOfDeath causeOfDeath, Random? random)` - Translate a cause of death to the user's current language. - Pass this the result of `Coroner.API.GetCauseOfDeath()` for best results.