Skip to content

Commit

Permalink
0.8.7: Random spawns in dryrun
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhit-pathak committed Dec 4, 2024
1 parent 4e2cac9 commit c410caa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MatchZy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class MatchZy : BasePlugin
{

public override string ModuleName => "MatchZy";
public override string ModuleVersion => "0.8.6";
public override string ModuleVersion => "0.8.7";

public override string ModuleAuthor => "WD- (https://github.com/shobhit-pathak/)";

Expand Down
2 changes: 1 addition & 1 deletion MatchZy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.263">
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.291">
<PrivateAssets>none</PrivateAssets>
<ExcludeAssets>runtime</ExcludeAssets>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
13 changes: 13 additions & 0 deletions PracticeMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,26 @@ public class Position

public Vector PlayerPosition { get; private set; }
public QAngle PlayerAngle { get; private set; }

// Copy constructor
public Position(Position other)
{
PlayerPosition = other.PlayerPosition;
PlayerAngle = other.PlayerAngle;
}

public Position(Vector playerPosition, QAngle playerAngle)
{
// Create deep copies of the Vector and QAngle objects
PlayerPosition = new Vector(playerPosition.X, playerPosition.Y, playerPosition.Z);
PlayerAngle = new QAngle(playerAngle.X, playerAngle.Y, playerAngle.Z);
}

public void Teleport(CCSPlayerController player)
{
player!.PlayerPawn.Value!.Teleport(PlayerPosition, PlayerAngle, new Vector(0, 0, 0));
}

public override bool Equals(object? obj)
{
if (obj == null || GetType() != obj.GetType())
Expand Down
27 changes: 27 additions & 0 deletions Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ private int GetRoundNumer()

public void HandlePostRoundStartEvent(EventRoundStart @event)
{
if (isDryRun) RandomizeSpawns();
if (!matchStarted) return;
playerHasTakenDamage = false;
HandleCoaches();
Expand Down Expand Up @@ -2013,5 +2014,31 @@ public void DropWeaponByDesignerName(CCSPlayerController player, string weaponNa
player.DropActiveWeapon();
}
}

public void RandomizeSpawns()
{
List<CCSPlayerController> players = Utilities.GetPlayers();

Dictionary<byte, List<Position>> teamSpawns = new()
{
{ (byte)CsTeam.CounterTerrorist, spawnsData[(byte)CsTeam.CounterTerrorist].Select(position => new Position(position)).ToList() },
{ (byte)CsTeam.Terrorist, spawnsData[(byte)CsTeam.Terrorist].Select(position => new Position(position)).ToList() }
};

Random random = new();

foreach (var player in players)
{
if (!IsPlayerValid(player)) continue;

if (teamSpawns[player.TeamNum].Count == 0) break;

int randomIndex = random.Next(teamSpawns[player.TeamNum].Count);
Position spawnPosition = teamSpawns[player.TeamNum][randomIndex];
teamSpawns[player.TeamNum].RemoveAt(randomIndex);

spawnPosition.Teleport(player);
}
}
}
}

0 comments on commit c410caa

Please sign in to comment.