Skip to content

Commit

Permalink
Add customizations to noscope
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 27, 2024
1 parent 828ee97 commit 12d63dd
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public override void Execute() {
}

override protected HookResult
OnEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.OnEnd(@event, info);
onEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.onEnd(@event, info);
foreach (var restrictor in Restrictors) restrictor.Kill();
Restrictors.Clear();
return result;
Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ private HookResult OnDeath(EventPlayerDeath @event, GameEventInfo info) {
}

override protected HookResult
OnEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.OnEnd(@event, info);
onEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.onEnd(@event, info);

Plugin.DeregisterEventHandler<EventPlayerDeath>(OnDeath, HookMode.Pre);
Plugin.DeregisterEventHandler<EventPlayerSpawn>(OnRespawn);
Expand Down
26 changes: 12 additions & 14 deletions mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

namespace Jailbreak.SpecialDay.SpecialDays;

public class InfectionDay : AbstractArmoryRestrictedDay,
ISpecialDayMessageProvider {
public class InfectionDay(BasePlugin plugin, IServiceProvider provider)
: AbstractArmoryRestrictedDay(plugin, provider, CsTeam.CounterTerrorist),
ISpecialDayMessageProvider {
private readonly ICollection<int> swappedPrisoners = new HashSet<int>();

public InfectionDay(BasePlugin Plugin, IServiceProvider provider) : base(
Plugin, provider, CsTeam.CounterTerrorist) { }

public override SDType Type => SDType.INFECTION;

public override SpecialDaySettings Settings => new InfectionSettings();
Expand All @@ -40,12 +38,12 @@ public override void Setup() {
foreach (var ct in PlayerUtil.FromTeam(CsTeam.CounterTerrorist))
ct.SetColor(Color.LimeGreen);

Plugin.RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
Plugin.RegisterEventHandler<EventPlayerSpawn>(OnRespawn);
Plugin.RegisterEventHandler<EventPlayerDeath>(onPlayerDeath);
Plugin.RegisterEventHandler<EventPlayerSpawn>(onRespawn);
}

private HookResult
OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) {
onPlayerDeath(EventPlayerDeath @event, GameEventInfo info) {
var player = @event.Userid;
if (player == null || !player.IsValid) return HookResult.Continue;
if (player.Team != CsTeam.Terrorist) return HookResult.Continue;
Expand Down Expand Up @@ -101,7 +99,7 @@ private HookResult
return HookResult.Continue;
}

public HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) {
private HookResult onRespawn(EventPlayerSpawn @event, GameEventInfo info) {
var player = @event.Userid;
if (player == null || !player.IsValid) return HookResult.Continue;
if (player.Team != CsTeam.CounterTerrorist) return HookResult.Continue;
Expand All @@ -117,15 +115,15 @@ public HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) {
}

override protected HookResult
OnEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.OnEnd(@event, info);
Plugin.DeregisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
Plugin.DeregisterEventHandler<EventPlayerSpawn>(OnRespawn);
onEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.onEnd(@event, info);
Plugin.DeregisterEventHandler<EventPlayerDeath>(onPlayerDeath);
Plugin.DeregisterEventHandler<EventPlayerSpawn>(onRespawn);

Plugin.AddTimer(0.1f, () => {
foreach (var index in swappedPrisoners) {
var player = Utilities.GetPlayerFromSlot(index);
if (player == null) continue;
if (player == null || !player.IsValid) continue;
player.SwitchTeam(CsTeam.Terrorist);
}
});
Expand Down
49 changes: 39 additions & 10 deletions mod/Jailbreak.SpecialDay/SpecialDays/NoScopeDay.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Cvars.Validators;
using Jailbreak.English.SpecialDay;
using Jailbreak.Formatting.Views.SpecialDay;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.SpecialDay;
using Jailbreak.Public.Mod.SpecialDay.Enums;
using Jailbreak.Public.Utils;
using Jailbreak.Validator;

namespace Jailbreak.SpecialDay.SpecialDays;

Expand All @@ -17,20 +20,42 @@ public override ISDInstanceLocale Locale
=> new SoloDayLocale("No Scope",
"Your scope broke! Fight against everyone else. No camping!");

public override SpecialDaySettings Settings => new NoScopeSettings();
public override SpecialDaySettings Settings => new NoScopeSettings(this);

public readonly FakeConVar<string> CvWeapon = new("jb_sd_noscope_weapon",
"Weapon to give to all players, recommended it be a weapon with a scope (duh)",
"weapon_ssg08", ConVarFlags.FCVAR_NONE,
new ItemValidator(allowMultiple: true));

public readonly FakeConVar<string> CvWeaponWhitelist = new(
"jb_sd_noscope_allowedweapons",
"Weapons to allow players to use, empty for no restrictions",
string.Join(",",
Tag.UTILITY.Union(new[] { "weapon_ssg08", "weapon_knife" }.ToHashSet())),
ConVarFlags.FCVAR_NONE, new ItemValidator(allowMultiple: true));

public readonly FakeConVar<int> CvKnifeDelay = new(
"jb_sd_noscope_knife_delay",
"Time delay in seconds to give knives at, 0 to disable", 120,
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 500));

public readonly FakeConVar<float> CvGravity = new("jb_sd_noscope_gravity",
"Gravity to set during the special day, default is 800", 200f);

public override void Setup() {
Timers[120] += () => {
foreach (var player in PlayerUtil.GetAlive())
player.GiveNamedItem("weapon_knife");
};
if (CvKnifeDelay.Value > 0)
Timers[CvKnifeDelay.Value] += () => {
foreach (var player in PlayerUtil.GetAlive())
player.GiveNamedItem("weapon_knife");
};
base.Setup();
}

public override void Execute() {
foreach (var player in PlayerUtil.GetAlive()) {
player.RemoveWeapons();
player.GiveNamedItem("weapon_ssg08");
foreach (var weapon in CvWeapon.Value.Split(","))
player.GiveNamedItem(weapon);
}

base.Execute();
Expand All @@ -50,18 +75,22 @@ private void disableScope(CCSPlayerController player) {
if (activeWeapon == null || !activeWeapon.IsValid) return;
activeWeapon.NextSecondaryAttackTick = Server.TickCount + 500;

if (activeWeapon.DesignerName is "weapon_ssg08" or "weapon_knife") return;
if (Tag.UTILITY.Contains(activeWeapon.DesignerName)) return;
if (CvWeaponWhitelist.Value.Contains(activeWeapon.DesignerName,
StringComparison.CurrentCultureIgnoreCase))
return;
activeWeapon.NextPrimaryAttackTick = Server.TickCount + 500;
}

private class NoScopeSettings : FFASettings {
public NoScopeSettings() {
private readonly NoScopeDay day;

public NoScopeSettings(NoScopeDay day) {
this.day = day;
CtTeleport = TeleportType.RANDOM;
TTeleport = TeleportType.RANDOM;
RestrictWeapons = true;

ConVarValues["sv_gravity"] = (float)200;
ConVarValues["sv_gravity"] = day.CvGravity.Value;
ConVarValues["sv_infinite_ammo"] = 2;
}

Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ private HookResult
}

override protected HookResult
OnEnd(EventRoundEnd @event, GameEventInfo info) {
onEnd(EventRoundEnd @event, GameEventInfo info) {
Plugin.DeregisterEventHandler<EventPlayerHurt>(OnPlayerDamage);
Plugin.DeregisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
return base.OnEnd(@event, info);
return base.onEnd(@event, info);
}
}

Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ private void announceTimes() {
}

override protected HookResult
OnEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.OnEnd(@event, info);
onEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.onEnd(@event, info);

Plugin.RemoveListener<Listeners.OnTick>(checkFinishers);
bestTrail?.Kill();
Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.SpecialDay/SpecialDays/TeleportDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ private HookResult onDamage(EventPlayerHurt @event, GameEventInfo info) {
}

override protected HookResult
OnEnd(EventRoundEnd @event, GameEventInfo info) {
onEnd(EventRoundEnd @event, GameEventInfo info) {
Plugin.DeregisterEventHandler<EventPlayerHurt>(onDamage);
return base.OnEnd(@event, info);
return base.onEnd(@event, info);
}

public class TeleportSettings : SpecialDaySettings {
Expand Down
6 changes: 3 additions & 3 deletions public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public abstract class AbstractSpecialDay(BasePlugin plugin,
/// </summary>
public virtual void Setup() {
Plugin.RegisterFakeConVars(this);
Plugin.RegisterEventHandler<EventRoundEnd>(OnEnd);
Plugin.RegisterEventHandler<EventRoundEnd>(onEnd);

foreach (var entry in Settings.ConVarValues) {
var cv = ConVar.Find(entry.Key);
Expand Down Expand Up @@ -335,7 +335,7 @@ private void disableWeapon(CCSPlayerController player,
activeWeapon.NextPrimaryAttackTick = Server.TickCount + 500;
}

virtual protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) {
virtual protected HookResult onEnd(EventRoundEnd @event, GameEventInfo info) {
foreach (var entry in previousConvarValues) {
var cv = ConVar.Find(entry.Key);
if (cv == null || entry.Value == null) continue;
Expand All @@ -347,7 +347,7 @@ virtual protected HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) {
if (Settings.RestrictWeapons)
Plugin.RemoveListener<Listeners.OnTick>(OnTick);

Plugin.DeregisterEventHandler<EventRoundEnd>(OnEnd);
Plugin.DeregisterEventHandler<EventRoundEnd>(onEnd);
return HookResult.Continue;
}

Expand Down

0 comments on commit 12d63dd

Please sign in to comment.