private void OnEntityDeath(BaseCombatEntity victimEntity, HitInfo hitInfo) { // Ignore - there is no victim for some reason if (victimEntity == null) { return; } var data = new DeathData { VictimEntity = victimEntity, KillerEntity = victimEntity.lastAttacker ?? hitInfo?.Initiator, VictimEntityType = GetCombatEntityType(victimEntity), KillerEntityType = GetCombatEntityType(victimEntity.lastAttacker), DamageType = victimEntity.lastDamage, HitInfo = hitInfo }; // Handle inconsistencies/exceptions HandleExceptions(ref data); #if DEBUG LogDebug("[DEATHNOTES DEBUG]"); LogDebug($"VictimEntity: {data.VictimEntity?.GetType().Name ?? "NULL"} / {data.VictimEntity?.name ?? "NULL"}"); LogDebug($"KillerEntity: {data.KillerEntity?.GetType().Name ?? "NULL"} / {data.KillerEntity?.name ?? "NULL"}"); LogDebug($"VictimEntityType: {data.VictimEntityType}"); LogDebug($"KillerEntityType: {data.KillerEntityType}"); LogDebug($"DamageType: {data.DamageType}"); LogDebug($"Bodypart: {GetCustomizedBodypartName(data.HitInfo)}"); LogDebug($"Weapon: {hitInfo?.WeaponPrefab?.ShortPrefabName ?? "NULL"}"); #endif // Ignore deaths of other entities if (data.KillerEntityType == CombatEntityType.Other || data.VictimEntityType == CombatEntityType.Other) { return; } // Ignore deaths which don't involve players or the helicopter which usually does not track a player as killer if (data.VictimEntityType != CombatEntityType.Player && data.KillerEntityType != CombatEntityType.Player && data.VictimEntityType != CombatEntityType.Helicopter) { return; } // Populate the variables in the message string message = PopulateMessageVariables( // Find the best matching death message for this death GetDeathMessage(data), data ); if (message == null) { return; } Interface.Call("OnDeathNotice", data.ToDictionary(), message); if (_configuration.ShowInChat) { foreach (var player in BasePlayer.activePlayerList) { if (_configuration.MessageRadius != -1 && player.Distance(data.VictimEntity) > _configuration.MessageRadius) { continue; } Player.Reply( player, _configuration.ChatFormat.Replace("{message}", message), ulong.Parse(_configuration.ChatIcon) ); } } if (_configuration.ShowInConsole) { Puts(StripRichText(message)); } }
private void OnEntityDeath(BaseCombatEntity victimEntity, HitInfo hitInfo) { // Ignore - there is no victim for some reason if (victimEntity == null) { return; } // Try to avoid error when entity was destroyed if (victimEntity.gameObject == null) { return; } BaseEntity killer = victimEntity.lastAttacker ?? hitInfo?.Initiator; var data = new DeathData { VictimEntity = victimEntity, KillerEntity = killer, VictimEntityType = GetCombatEntityType(victimEntity), KillerEntityType = GetCombatEntityType(victimEntity.lastAttacker), DamageType = victimEntity.lastDamage, HitInfo = hitInfo, PositionStr = ((AshTools && victimEntity != null) ? $"{(string)AshTools?.Call("CoordinateToSquare", victimEntity.ServerPosition)} ({victimEntity.ServerPosition.ToString().Replace(",", "")})" : "NotAvailable"), PositionKillerStr = ((AshTools && killer != null) ? $"{(string)AshTools?.Call("CoordinateToSquare", killer.ServerPosition)} ({killer.ServerPosition.ToString().Replace(",", "")})" : "NotAvailable") }; // Handle inconsistencies/exceptions HandleInconsistencies(ref data); #if DEBUG LogDebug("[DEATHNOTES DEBUG]"); LogDebug($"VictimEntity: {data.VictimEntity?.GetType().Name ?? "NULL"} / {data.VictimEntity?.ShortPrefabName ?? "NULL"} / {data.VictimEntity?.PrefabName ?? "NULL"}"); LogDebug($"KillerEntity: {data.KillerEntity?.GetType().Name ?? "NULL"} / {data.KillerEntity?.ShortPrefabName ?? "NULL"} / {data.KillerEntity?.PrefabName ?? "NULL"}"); LogDebug($"VictimEntityType: {data.VictimEntityType}"); LogDebug($"KillerEntityType: {data.KillerEntityType}"); LogDebug($"DamageType: {data.DamageType}"); LogDebug($"Bodypart: {GetCustomizedBodypartName(data.HitInfo)}"); LogDebug($"Weapon: {hitInfo?.WeaponPrefab?.ShortPrefabName ?? "NULL"}"); LogDebug($"PositionStr: {data.PositionStr}"); LogDebug($"PositionKillerStr: {data.PositionKillerStr}"); #endif // Ignore deaths of other entities if (data.KillerEntityType == CombatEntityType.Other || data.VictimEntityType == CombatEntityType.Other) { return; } // Ignore deaths which don't involve players or the helicopter which usually does not track a player as killer if (data.VictimEntityType != CombatEntityType.Player && data.KillerEntityType != CombatEntityType.Player && data.VictimEntityType != CombatEntityType.Helicopter) { return; } // Populate the variables in the message string message = PopulateMessageVariables( // Find the best matching death message for this death GetDeathMessage(data), data ); if (message == null) { return; } object hookResult = Interface.Call("OnDeathNotice", data.ToDictionary(), message); if (hookResult?.Equals(false) ?? false) { return; } if (_configuration.ShowInChat) { foreach (var player in BasePlayer.activePlayerList) { if (_configuration.RequirePermission && !permission.UserHasPermission(player.UserIDString, CanSeePermission)) { continue; } if (_configuration.MessageRadius != -1 && player.Distance(data.VictimEntity) > _configuration.MessageRadius) { continue; } Player.Reply( player, _configuration.ChatFormat.Replace("{message}", message), ulong.Parse(_configuration.ChatIcon) ); } } if (_configuration.ShowInConsole) { Puts(StripRichText(message)); } }