Skip to content

Commit

Permalink
Merge pull request #220 from TGRCdev/stinger-fix
Browse files Browse the repository at this point in the history
Fixed stinger grenades causing massive lag spikes
  • Loading branch information
formlessnameless authored Sep 7, 2024
2 parents ce00dc5 + 152c8b8 commit f89d488
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Content.Shared.Explosion.Components;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Timing;

namespace Content.Server.Explosion.EntitySystems;

Expand Down Expand Up @@ -114,8 +115,12 @@ public override void Update(float frameTime)
RaiseLocalEvent(uid, ref ev);
}
}
// delete the empty shell of the clusterbomb
Del(uid);
// move the exploded grenade to null space
if (TryComp(uid, out TransformComponent? xform))
_transformSystem.DetachEntity(uid, xform);

// wait a second before deleting to prevent a flood of errors from projectiles
Timer.Spawn(TimeSpan.FromSeconds(1), () => QueueDel(uid));
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Content.Shared/Sound/Components/BaseEmitSoundComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public abstract partial class BaseEmitSoundComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField(required: true)]
public SoundSpecifier? Sound;

[AutoNetworkedField]
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool Detach = false;
}
16 changes: 14 additions & 2 deletions Content.Shared/Sound/SharedEmitSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,24 @@ protected void TryEmitSound(EntityUid uid, BaseEmitSoundComponent component, Ent

if (predict)
{
_audioSystem.PlayPredicted(component.Sound, uid, user);
if (component.Detach)
{
if (TryComp(uid, out TransformComponent? xform))
_audioSystem.PlayPredicted(component.Sound, xform.Coordinates, user);
}
else
_audioSystem.PlayPredicted(component.Sound, uid, user);
}
else if (_netMan.IsServer)
{
// don't predict sounds that client couldn't have played already
_audioSystem.PlayPvs(component.Sound, uid);
if (component.Detach)
{
if (TryComp(uid, out TransformComponent? xform))
_audioSystem.PlayPvs(component.Sound, xform.Coordinates);
}
else
_audioSystem.PlayPvs(component.Sound, uid);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
- type: EmitSoundOnTrigger
sound:
path: "/Audio/Effects/flash_bang.ogg"
detach: true
- type: SpawnOnTrigger
proto: GrenadeFlashEffect
- type: TimerTriggerVisuals
Expand Down

0 comments on commit f89d488

Please sign in to comment.