[IDEA] Add disruptor's exploded projectiles to ProjectileExplod(ed/ing)Event
Goal Description
π [IDEA] Add support for non-grenade projectiles in ProjectileExplodedEventArgs
π Goal
Enhance the LabAPI ProjectileExplodedEventArgs to support more projectile types beyond just TimedGrenadeProjectile (HE grenade). Currently, any projectile that isn't grenade-like - such as disruptors, Jailbird, or SCP018 - cannot be handled with this event. This causes logic like explosion reactions and blackout sensitivity to fail for non-grenade weapons.
π Example Code Demonstrating the Limitation
/// <summary>
/// Handles the projectile explosion event, enabling lights and playing a global sound
/// if a dangerous projectile explodes in a dark room during an active blackout.
/// </summary>
public void OnProjectileExploded(ProjectileExplodedEventArgs ev)
{
if (!_plugin.Npc.Methods.IsDangerousToScp575(ev.TimedGrenade))
return;
Exiled.API.Features.Room room = Exiled.API.Features.Room.Get(ev.Position);
if (room == null || !room.AreLightsOff || !_plugin.Npc.Methods.IsBlackoutActive)
return;
Library_ExiledAPI.LogDebug("OnProjectileExploded", $"Grenade, Flash or disruptor used in dark SCP-575 room: {room.Name}");
Library_ExiledAPI.EnableAndFlickerRoomAndNeighborLights(room);
AudioManager.PlayGlobalAngrySound();
}
/// <summary>
/// Determines if a projectile is dangerous to SCP-575.
/// </summary>
public bool IsDangerousToScp575(Projectiles.Projectile projectile)
{
if (projectile == null) return false;
return projectile.Type switch
{
ItemType.GrenadeHE => true,
ItemType.GrenadeFlash => true,
ItemType.SCP018 => true,
ItemType.Jailbird => true,
ItemType.ParticleDisruptor => true,
_ => false
};
}
Notes
I'd like to catch ItemType.ParticleDisruptor => true, here too.
You can use ExplosionSpawning/ed event for this case as it handles any kind of explosion
Thank you, I'll try it tomorrow :3
Workaround
Okay, I've confirmed that OnExplosionSpawned won't work for flashbangs.
A hybrid approach is necessary as a workaround:
OnProjectileExplodedneeds to handle flashbang explosions.OnExplosionSpawnedshould handle damageable explosives.
So yes, the workaround is:
OnExplosionSpawnedlistens forExplosionType, but excludesGrenadeFlashbang. (ExplosionType.Grenadedoes not cover this kind of explosion.)OnProjectileExplodedspecifically watches forItemType.GrenadeFlashbang.
Example:
/// <summary>
/// Handles the explosion spawned event, enabling lights and playing a global sound if a dangerous
/// projectile explodes in a dark room during an active blackout.
/// </summary>
/// <param name="ev">The event arguments for the projectile explosion event.</param>
public void OnExplosionSpawned(LabApi.Events.Arguments.ServerEvents.ExplosionSpawnedEventArgs ev)
{
if (!_plugin.Npc.Methods.IsDangerousToScp575(ev.ExplosionType))
{
return;
}
Exiled.API.Features.Room room = Exiled.API.Features.Room.Get(ev.Position);
if (room == null || !room.AreLightsOff || !_plugin.Npc.Methods.IsBlackoutActive)
{
return;
}
Library_ExiledAPI.LogDebug("OnProjectileExploded", $"Grenade, Flash or disruptor used in dark SCP-575 room: {room.Name}");
Library_ExiledAPI.EnableAndFlickerRoomAndNeighborLights(room);
AudioManager.PlayGlobalAngrySound();
}
/// <summary>
/// Handles the projectile explosion event, enabling lights and playing a global sound if a dangerous
/// projectile explodes in a dark room during an active blackout.
/// </summary>
/// <param name="ev">The event arguments for the projectile explosion event.</param>
public void OnProjectileExploded(LabApi.Events.Arguments.ServerEvents.ProjectileExplodedEventArgs ev)
{
return; // todo testing
if (!_plugin.Npc.Methods.IsDangerousToScp575(ev.TimedGrenade))
{
return;
}
Exiled.API.Features.Room room = Exiled.API.Features.Room.Get(ev.Position);
if (room == null || !room.AreLightsOff || !_plugin.Npc.Methods.IsBlackoutActive)
{
return;
}
Library_ExiledAPI.LogDebug("OnProjectileExploded", $"Grenade, Flash or disruptor used in dark SCP-575 room: {room.Name}");
Library_ExiledAPI.EnableAndFlickerRoomAndNeighborLights(room);
AudioManager.PlayGlobalAngrySound();
}
}
Question
Do you plan to enhance the API by adding Flashbangs to the OnExplosionSpawned event, or do you intend to limit it to damageable explosions only?
Ah yes, sorry.. the flashbang won't fire this event as it triggers for only destructible explosions. I do not plan to change this as of right now as the ExplosionSpawned is designed for destructable explosions.
But yes, this combination of events will get you what you wanted. I suggest making a single processing method for both of these events like this:
/// <summary>
/// Handles the explosion spawned event, enabling lights and playing a global sound if a dangerous
/// projectile explodes in a dark room during an active blackout.
/// </summary>
/// <param name="ev">The event arguments for the projectile explosion event.</param>
public void OnExplosionSpawned(LabApi.Events.Arguments.ServerEvents.ExplosionSpawnedEventArgs ev)
{
HandleExplosion(ev.Position, ev.Settings.ItemId.TypeId);
}
/// <summary>
/// Handles the projectile explosion event, enabling lights and playing a global sound if a dangerous
/// projectile explodes in a dark room during an active blackout.
/// </summary>
/// <param name="ev">The event arguments for the projectile explosion event.</param>
public void OnProjectileExploded(LabApi.Events.Arguments.ServerEvents.ProjectileExplodedEventArgs ev)
{
if (ev.TimedGrenade is not FlashbangProjectile)
{
return;
}
HandleExplosion(ev.Position, ev.TimedGrenade.Type);
}
public void HandleExplosion(Vector3 position, ItemType type)
{
if (!_plugin.Npc.Methods.IsDangerousToScp575(type))
{
return;
}
Exiled.API.Features.Room room = Exiled.API.Features.Room.Get(position);
if (room == null || !room.AreLightsOff || !_plugin.Npc.Methods.IsBlackoutActive)
{
return;
}
Library_ExiledAPI.LogDebug("OnProjectileExploded", $"Grenade, Flash or disruptor used in dark SCP-575 room: {room.Name}");
Library_ExiledAPI.EnableAndFlickerRoomAndNeighborLights(room);
AudioManager.PlayGlobalAngrySound();
}
Side note: Is there any specific reason why are you using LabAPI events with combination of Exiled's Room? Are you missing something from the wrappers? If so, please make a comment or another issue about it. I would like to hear your feedback.
First, I use this approach because it's what I used to do.
Controlling lights this way is more comfortable, and I donβt need to loop through all the controllers manually. I discovered that Room.LightController from LabAPI returns only the first light controller. However, some rooms like SCP-049βs or the warhead room may contain multiple controllers.
That means I can skip the typical for each loop like this:
foreach (LightsController lc in room.AllLightControllers)
lc.FlickerLights(float.MaxValue);
Thank you for your suggestion! We've logged this issue in our internal git system for further review and tracking. Please note that this doesn't guarantee acceptance or implementation at this stage. If we need any additional information or clarification, we'll be sure to reach out to you.
We've reopened this suggestion to prevent confusion and duplicate posts. As stated before, the issue has been added to our internal tracker, but that does not guarantee acceptance nor implementation.
Handled in comments