LabAPI icon indicating copy to clipboard operation
LabAPI copied to clipboard

[IDEA] Add disruptor's exploded projectiles to ProjectileExplod(ed/ing)Event

Open iomatix opened this issue 1 year ago β€’ 8 comments

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.

iomatix avatar Jul 18 '25 20:07 iomatix

You can use ExplosionSpawning/ed event for this case as it handles any kind of explosion

davidsebesta1 avatar Jul 18 '25 22:07 davidsebesta1

Thank you, I'll try it tomorrow :3

iomatix avatar Jul 18 '25 22:07 iomatix

Workaround

Okay, I've confirmed that OnExplosionSpawned won't work for flashbangs. A hybrid approach is necessary as a workaround:

  • OnProjectileExploded needs to handle flashbang explosions.
  • OnExplosionSpawned should handle damageable explosives.

So yes, the workaround is:

  • OnExplosionSpawned listens for ExplosionType, but excludes GrenadeFlashbang. (ExplosionType.Grenade does not cover this kind of explosion.)
  • OnProjectileExploded specifically watches for ItemType.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?

iomatix avatar Jul 19 '25 08:07 iomatix

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.

davidsebesta1 avatar Jul 19 '25 13:07 davidsebesta1

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);

iomatix avatar Jul 19 '25 19:07 iomatix

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.

Jesus-QC avatar Oct 14 '25 09:10 Jesus-QC

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.

Axwabo avatar Apr 27 '26 18:04 Axwabo

Handled in comments

davidsebesta1 avatar Nov 03 '26 18:11 davidsebesta1