From b5603fafbcea65c6381d72d578ad4abbe453b9aa Mon Sep 17 00:00:00 2001 From: MSWS Date: Mon, 4 Aug 2025 00:21:15 -0700 Subject: [PATCH] Fix C4 behavior --- .gitignore | Bin 88 -> 116 bytes mod/Jailbreak.Rebel/C4Bomb/C4Behavior.cs | 58 ++++++++++-------- .../Jailbreak.Public/Jailbreak.Public.csproj | 2 +- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index aad3b715154f799d87dc5454c8cca3ad824e455e..ddb152a7e7f8c5b1c70def972df8ef69d9b03f86 100644 GIT binary patch literal 116 zcmaFAdp|FivO-X5L4I*&Nq$kKLQ-jFPKrWWW=?7`FBh1j52Q2mfMkAB7LerSa!E}p zO$V}qQgc!hi&Md3$_kz?t}tzSnJKA>Kw-VIVj!u-pvO?kP|T3ZP{hE?z{LOnK@uM) literal 88 zcmaFAdq0=5LQrZ!esN|=eo>`DQfX#Rib7guPHHh1n61y1l$oc`m7kQQ&&B1EnpB#u i&lQxKlbTqZ3KURQ@N{v7D%Z detonate(player, bombEntity)); + tryEmitSound(player, "jb.jihad", 1); } public void TryGiveC4ToRandomTerrorist() { @@ -111,18 +118,21 @@ public class C4Behavior(IC4Locale ic4Locale, IRebelService rebelService, public void Start(BasePlugin basePlugin) { plugin = basePlugin; - plugin.RegisterListener(playerUseC4ListenerCallback); + plugin.RegisterListener( + playerButtonsChanged); } - private void playerUseC4ListenerCallback() { + private void playerButtonsChanged(CCSPlayerController player, + PlayerButtons pressed, PlayerButtons released) { + if ((pressed & PlayerButtons.Use) == 0) return; + foreach (var (bomb, meta) in bombs) { - if (!bomb.IsValid) continue; - if (meta.IsDetonating) continue; + if (!bomb.IsValid || meta.IsDetonating) continue; var bombCarrier = bomb.OwnerEntity.Value?.As() .Controller.Value?.As(); if (bombCarrier == null || !bombCarrier.IsValid - || (bombCarrier.Buttons & PlayerButtons.Use) == 0) + || bombCarrier.Slot != player.Slot) continue; var activeWeapon = bombCarrier.PlayerPawn.Value?.WeaponServices @@ -231,6 +241,7 @@ public class C4Behavior(IC4Locale ic4Locale, IRebelService rebelService, } private void detonate(CCSPlayerController player, CC4 bomb) { + Server.PrintToChatAll("detonation started"); if (!player.IsValid || !player.IsReal() || !player.PawnIsAlive) { if (bomb.IsValid) bomb.Remove(); bombs.Remove(bomb); @@ -239,17 +250,6 @@ public class C4Behavior(IC4Locale ic4Locale, IRebelService rebelService, if (Server.TickCount - roundStart < CV_C4_DELAY.Value * 64) return; - tryEmitSound(player, "jb.jihadExplosion", 1, 1f, 0f); - var particleSystemEntity = - Utilities.CreateEntityByName("info_particle_system")!; - particleSystemEntity.EffectName = - "particles/explosions_fx/explosion_c4_500.vpcf"; - particleSystemEntity.StartActive = true; - - particleSystemEntity.Teleport(player.PlayerPawn.Value!.AbsOrigin!, - new QAngle(), new Vector()); - particleSystemEntity.DispatchSpawn(); - var killed = 0; /* Calculate damage here, only applies to alive CTs. */ var lrs = provider.GetRequiredService(); @@ -280,6 +280,10 @@ public class C4Behavior(IC4Locale ic4Locale, IRebelService rebelService, } } + // If they didn't have the C4 make sure to remove it. + player.CommitSuicide(true, true); + bombs.Remove(bomb); + if (API.Gangs != null && killed > 0) { var eco = API.Gangs.Services.GetService(); if (eco != null) { @@ -289,17 +293,23 @@ public class C4Behavior(IC4Locale ic4Locale, IRebelService rebelService, } } - API.Stats?.PushStat(new ServerStat("JB_BOMB_EXPLODED", killed.ToString())); + tryEmitSound(player, "jb.jihadExplosion", 1); + var particleSystemEntity = + Utilities.CreateEntityByName("info_particle_system")!; + particleSystemEntity.EffectName = + "particles/explosions_fx/explosion_c4_500.vpcf"; + particleSystemEntity.StartActive = true; - // If they didn't have the C4 make sure to remove it. - player.CommitSuicide(true, true); - bombs.Remove(bomb); + particleSystemEntity.Teleport(player.PlayerPawn.Value!.AbsOrigin!, + new QAngle(), new Vector()); + particleSystemEntity.DispatchSpawn(); + + API.Stats?.PushStat(new ServerStat("JB_BOMB_EXPLODED", killed.ToString())); } private void tryEmitSound(CBaseEntity entity, string soundEventName, - int pitch, float volume, float delay) { - CBaseEntity_EmitSoundParamsLinux.Invoke(entity, soundEventName, pitch, - volume, delay); + int pitch) { + entity.EmitSound(soundEventName, pitch: pitch); } private class C4Metadata(bool isDetonating) { diff --git a/public/Jailbreak.Public/Jailbreak.Public.csproj b/public/Jailbreak.Public/Jailbreak.Public.csproj index 2dc5838..9fb0d0c 100644 --- a/public/Jailbreak.Public/Jailbreak.Public.csproj +++ b/public/Jailbreak.Public/Jailbreak.Public.csproj @@ -8,7 +8,7 @@ - +