Skip to content

Commit

Permalink
Update v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Feb 11, 2024
1 parent b9fb931 commit 24a03eb
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 190 deletions.
5 changes: 2 additions & 3 deletions source/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Timers;
using System.Drawing;
using System.ComponentModel;

namespace Deathmatch
{
Expand All @@ -29,9 +28,9 @@ private void AddCustomCommands(string cmd_weapon, string weapon_name)
}
string weaponName = info.GetArg(0).ToLower();
weaponName = weaponName.Replace("css_", "");
if (customShortcuts.ContainsValue(weaponName))
if (customShortcuts.ContainsKey(weaponName))
{
string weaponID = customShortcuts.FirstOrDefault(x => x.Value == weaponName).Key;
string weaponID = customShortcuts.FirstOrDefault(x => x.Key == weaponName).Value;
SetupPlayerWeapons(player!, weaponID, info);
}
});
Expand Down
2 changes: 2 additions & 0 deletions source/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ public class DeathmatchConfig : BasePluginConfig
[JsonPropertyName("check_enemies_distance")] public bool CheckDistance { get; set; } = true;
[JsonPropertyName("distance_from_enemies_for_respawn")] public int DistanceRespawn { get; set; } = 500;
[JsonPropertyName("default_weapons")] public int DefaultModeWeapons { get; set; } = 2;
[JsonPropertyName("switch_weapons")] public bool SwitchWeapons { get; set; } = true;
[JsonPropertyName("respawn_players_after_new_mode")] public bool g_bRespawnPlayersAtNewMode { get; set; } = false;
[JsonPropertyName("hide_round_seconds")] public bool g_bHideRoundSeconds { get; set; } = true;
[JsonPropertyName("block_radio_messages")] public bool g_bBlockRadioMessage { get; set; } = true;
[JsonPropertyName("remove_breakable_entities")] public bool g_bRemoveBreakableEntities { get; set; } = true;
[JsonPropertyName("remove_decals_after_death")] public bool g_bRemoveDecals { get; set; } = true;
[JsonPropertyName("force_map_end")] public bool ForceMapEnd { get; set; } = true;
[JsonPropertyName("weapons_select_shortcuts")] public string CustomShortcuts { get; set; } = "weapon_ak47:ak,weapon_m4a1:m4,weapon_awp:awp,weapon_usp_silencer:usp,weapon_glock:glock,weapon_deagle:deagle";
[JsonPropertyName("Players Settings")] public PlayersSettings PlayersSettings { get; set; } = new PlayersSettings();
}
Expand Down
31 changes: 24 additions & 7 deletions source/Deathmatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Cvars;
using Newtonsoft.Json.Linq;
using CounterStrikeSharp.API.Modules.Entities.Constants;

namespace Deathmatch;

[MinimumApiVersion(142)]
[MinimumApiVersion(163)]
public partial class DeathmatchCore : BasePlugin, IPluginConfig<DeathmatchConfig>
{
public override string ModuleName => "Deathmatch Core";
public override string ModuleAuthor => "Nocky";
public override string ModuleVersion => "1.0.3";
public override string ModuleVersion => "1.0.4";

public class ModeInfo
{
Expand All @@ -29,9 +30,9 @@ public class ModeInfo
}

public static CounterStrikeSharp.API.Modules.Timers.Timer? modeTimer;
public static string respawnWindowsSig = "\\x44\\x88\\x4C\\x24\\x2A\\x55\\x57";
public static string respawnLinuxSig = "\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x41\\x55\\x41\\x54\\x49\\x89\\xFC\\x53\\x48\\x89\\xF3\\x48\\x81\\xEC\\xC8\\x00\\x00\\x00";
internal static PlayerCache<deathmatchPlayerData> playerData = new PlayerCache<deathmatchPlayerData>();
//public static string respawnWindowsSig = "\\x44\\x88\\x4C\\x24\\x2A\\x55\\x57";
//public static string respawnLinuxSig = "\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x41\\x55\\x41\\x54\\x49\\x89\\xFC\\x53\\x48\\x89\\xF3\\x48\\x81\\xEC\\xC8\\x00\\x00\\x00";
internal static PlayerCache<DeathmatchPlayerData> playerData = new PlayerCache<DeathmatchPlayerData>();
public static ModeInfo ModeData = new ModeInfo();
public DeathmatchConfig Config { get; set; } = null!;
public static int g_iTotalModes = 0;
Expand Down Expand Up @@ -74,7 +75,7 @@ public override void Load(bool hotReload)
string[] Value = weapon.Split(':');
if (Value.Length == 2)
{
customShortcuts.Add(Value[0], Value[1]);
customShortcuts.Add(Value[1], Value[0]);
AddCustomCommands(Value[1], Value[0]);
}
}
Expand Down Expand Up @@ -105,6 +106,22 @@ public override void Load(bool hotReload)
}
}, TimerFlags.REPEAT);
}
if (Config.ForceMapEnd)
{
var timelimit = ConVar.Find("mp_timelimit")!.GetPrimitiveValue<float>() * 60;
AddTimer(10.0f, () =>
{
var gameStart = GameRules().GameStartTime;
var currentTime = Server.CurrentTime;
var timeleft = timelimit - (currentTime - gameStart);

if (timeleft < 0)
{
GameRules().TerminateRound(0.1f, RoundEndReason.RoundDraw);
}

}, TimerFlags.REPEAT);
}
AddTimer(1.0f, () =>
{
RemoveEntities();
Expand All @@ -131,7 +148,7 @@ public override void Load(bool hotReload)
{
if (ModeData.CenterMessage && !string.IsNullOrEmpty(ModeData.CenterMessageText))
{
if (playerData.ContainsPlayer(p) && playerData[p].showHud)
if (playerData.ContainsPlayer(p) && playerData[p].ShowHud)
{
p.PrintToCenterHtml($"{ModeData.CenterMessageText}");
}
Expand Down
2 changes: 1 addition & 1 deletion source/Deathmatch.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.142" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.164" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
25 changes: 0 additions & 25 deletions source/Deathmatch.sln

This file was deleted.

53 changes: 29 additions & 24 deletions source/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventIn
{
if (!playerData.ContainsPlayer(player))
{
deathmatchPlayerData setupPlayerData = new deathmatchPlayerData
DeathmatchPlayerData setupPlayerData = new DeathmatchPlayerData
{
primaryWeapon = "",
secondaryWeapon = "",
killStreak = 0,
onlyHS = false,
killFeed = false,
spawnProtection = false,
showHud = true,
lastSpawn = "0"
PrimaryWeapon = "",
SecondaryWeapon = "",
KillStreak = 0,
OnlyHS = false,
KillFeed = false,
SpawnProtection = false,
ShowHud = true,
LastSpawn = "0"
};
playerData[player] = setupPlayerData;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
{
if (playerData.ContainsPlayer(player))
{
playerData[player].killStreak = 0;
playerData[player].KillStreak = 0;
}

if (!player.IsBot && AdminManager.PlayerHasPermissions(player, Config.PlayersSettings.VIPFlag))
Expand Down Expand Up @@ -140,7 +140,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
}
if (playerData.ContainsPlayer(attacker))
{
playerData[attacker].killStreak++;
playerData[attacker].KillStreak++;
if (attacker.Pawn.Value != null)
{
int giveHP = 0;
Expand Down Expand Up @@ -216,7 +216,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)

foreach (var p in Utilities.GetPlayers().Where(p => p is { IsBot: false, IsHLTV: false, IsValid: true }))
{
if (playerData.ContainsPlayer(p) && playerData[p].killFeed && (attacker != p || player != p))
if (playerData.ContainsPlayer(p) && playerData[p].KillFeed && (attacker != p || player != p))
{
@event.FireEventToClient(p);
}
Expand Down Expand Up @@ -260,28 +260,33 @@ private HookResult OnPlayerRadioMessage(CCSPlayerController? player, CommandInfo
}
private HookResult OnTakeDamage(DynamicHook hook)
{
var entindex = hook.GetParam<CEntityInstance>(0).Index;
if (entindex == 0)
{
var p = hook.GetParam<CEntityInstance>(0).Index;
if (p == 0)
return HookResult.Continue;

var playerPawn = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)p);
if (playerPawn.OriginalController.Value is not { } player)
return HookResult.Continue;
}

var pawn = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)entindex);
if (pawn.OriginalController.Value is not { } player)
{
var damageInfo = hook.GetParam<CTakeDamageInfo>(1);
var a = damageInfo.Attacker.Index;

if (a == 0)
return HookResult.Continue;

var attackerPawn = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)a);
if (attackerPawn.OriginalController.Value is not { } attacker)
return HookResult.Continue;
}

if (player != null && player.IsValid && player.PawnIsAlive)
if (player != null && player.IsValid && attacker != null && attacker.IsValid)
{
var damageInfo = hook.GetParam<CTakeDamageInfo>(1);
if (playerData.ContainsPlayer(player) && playerData[player].spawnProtection)
if (playerData.ContainsPlayer(player) && playerData[player].SpawnProtection)
{
damageInfo.Damage = 0;
}
if (!ModeData.KnifeDamage && damageInfo.Ability.IsValid && damageInfo.Ability.Value!.DesignerName.Contains("knife"))
{
player.PrintToCenter(Localizer["Knife_damage_disabled"]);
attacker.PrintToCenter(Localizer["Knife_damage_disabled"]);
damageInfo.Damage = 0;
}
}
Expand Down
Loading

0 comments on commit 24a03eb

Please sign in to comment.