Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minplayers #10

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build -c Release
11 changes: 7 additions & 4 deletions .github/workflows/dotnet.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name: Build and Release

on: push
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout all the submodules
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
Expand All @@ -32,7 +35,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
submodules: recursive

- name: Setup .NET
uses: actions/setup-dotnet@v4
Expand Down Expand Up @@ -105,4 +108,4 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./plugin/${{ github.event.repository.name }}-${{ github.sha }}.zip
asset_name: ${{ github.event.repository.name }}.zip
asset_content_type: application/zip
asset_content_type: application/zip
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "Menu"]
path = Menu
url = https://github.com/oscar-wos/Menu.git
[submodule "CSSharpUtils"]
path = CSSharpUtils
url = https://github.com/oscar-wos/CSSharpUtils
8 changes: 7 additions & 1 deletion AntiRush.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntiRush", "src\AntiRush.csproj", "{9B2DEBE8-1EEF-47E8-B890-D15A3F0FF109}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menu", ".\Menu\src\Menu.csproj", "{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menu", "Menu\src\Menu.csproj", "{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSSharpUtils", "CSSharpUtils\CSSharpUtils\CSSharpUtils.csproj", "{794D24A4-83A3-4F67-94DE-09087FC9554E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,6 +23,10 @@ Global
{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Release|Any CPU.Build.0 = Release|Any CPU
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions CSSharpUtils
Submodule CSSharpUtils added at 4291c7
4 changes: 4 additions & 0 deletions src/AntiRush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using AntiRush.Enums;
using CSSharpUtils.Extensions;

namespace AntiRush;

public partial class AntiRush : BasePlugin, IPluginConfig<AntiRushConfig>
{
public void OnConfigParsed(AntiRushConfig config)
{
if (config.Update())
config.Reload();

Config = config;
_countdown = Config.Countdown.Select(c => (float)c).ToArray();
}
Expand Down
6 changes: 1 addition & 5 deletions src/AntiRush.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="*" ExcludeAssets="runtime" />
<ProjectReference Include="..\CSSharpUtils\CSSharpUtils\CSSharpUtils.csproj" />
<ProjectReference Include="..\Menu\src\Menu.csproj" />
</ItemGroup>

Expand All @@ -18,9 +19,4 @@
</Content>
</ItemGroup>

<Target Name="CopyCustomContent" AfterTargets="AfterBuild" Condition=" '$(Configuration)' == 'Debug' ">
<Copy SourceFiles="$(OutputPath)AntiRush.dll" DestinationFolder="\\wsl.localhost\Debian\home\user\cs2\game\csgo\addons\counterstrikesharp\plugins\AntiRush" />
<Copy SourceFiles="$(OutputPath)lang\en.json" DestinationFolder="\\wsl.localhost\Debian\home\user\cs2\game\csgo\addons\counterstrikesharp\plugins\AntiRush\lang" />
</Target>

</Project>
7 changes: 4 additions & 3 deletions src/Config.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using CounterStrikeSharp.API.Core;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
using CounterStrikeSharp.API.Core;

namespace AntiRush;

public class AntiRushConfig : BasePluginConfig
{
public override int Version { get; set; } = 5;
public override int Version { get; set; } = 6;
[JsonPropertyName("Messages")] public string Messages { get; set; } = "simple";
[JsonPropertyName("DrawZones")] public bool DrawZones { get; set; } = false;
[JsonPropertyName("Warmup")] public bool Warmup { get; set; } = false;
Expand All @@ -16,4 +16,5 @@ public class AntiRushConfig : BasePluginConfig
[JsonPropertyName("RushZones")] public int[] RushZones { get; set; } = [0, 2, 3];
[JsonPropertyName("CampZones")] public int[] CampZones { get; set; } = [1];
[JsonPropertyName("Countdown")] public int[] Countdown { get; set; } = [60, 30, 15, 10, 5, 3, 2, 1];
[JsonPropertyName("MinPlayers")] public int MinPlayers { get; set; } = 1;
}
6 changes: 4 additions & 2 deletions src/Events.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using CSSharpUtils.Utils;

namespace AntiRush;

Expand All @@ -11,7 +12,8 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
_roundStart = Server.CurrentTime;
_bombPlanted = false;

_gameRules ??= Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules!;
_gameRules = GameUtils.GetGameRules();
_minPlayers = Utilities.GetPlayers().Where(p => p.Team == (CsTeam.Terrorist | CsTeam.CounterTerrorist)).ToList().Count >= Config.MinPlayers;

foreach (var zone in _zones)
{
Expand All @@ -26,7 +28,7 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)

private HookResult OnBombPlanted(EventBombPlanted @event, GameEventInfo info)
{
if (!Config.DisableOnBombPlant)
if (!Config.DisableOnBombPlant || !_minPlayers)
return HookResult.Continue;

_bombPlanted = true;
Expand Down
3 changes: 2 additions & 1 deletion src/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AntiRush;
public partial class AntiRush
{
public override string ModuleName => "AntiRush";
public override string ModuleVersion => "1.0.7";
public override string ModuleVersion => "1.0.8";
public override string ModuleAuthor => "https://github.com/oscar-wos/AntiRush";
public AntiRushConfig Config { get; set; } = new();
public Menu.Menu Menu { get; } = new();
Expand All @@ -20,4 +20,5 @@ public partial class AntiRush
private bool _bombPlanted;
private float[] _countdown = [];
private CCSGameRules? _gameRules;
private bool _minPlayers;
}
4 changes: 2 additions & 2 deletions src/Json.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CounterStrikeSharp.API.Modules.Utils;
using System.Text.Json;
using System.Text.Json;
using CounterStrikeSharp.API.Modules.Utils;
using AntiRush.Enums;

namespace AntiRush;
Expand Down
4 changes: 3 additions & 1 deletion src/Listeners.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CounterStrikeSharp.API;
using AntiRush.Enums;

namespace AntiRush;

Expand All @@ -10,6 +9,9 @@ private void OnTick()
if (_gameRules is { WarmupPeriod: true } && !Config.Warmup)
return;

if (!_minPlayers)
return;

if (Config.NoRushTime != 0 && !_bombPlanted)
{
var diff = (Config.NoRushTime + _roundStart) - Server.CurrentTime;
Expand Down
4 changes: 2 additions & 2 deletions src/Zone.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Drawing;
using Microsoft.Extensions.Localization;
using System.Drawing;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Localization;
using AntiRush.Enums;

namespace AntiRush;
Expand Down
Loading