Skip to content

Commit

Permalink
Update v1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Mar 1, 2024
1 parent f23feeb commit 89e90bf
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 136 deletions.
5 changes: 5 additions & 0 deletions source/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public void OnStartMode_CMD(CCSPlayerController player, CommandInfo info)
[RequiresPermissions("@css/root")]
public void OnEditor_CMD(CCSPlayerController player, CommandInfo info)
{
if (Config.Gameplay.DefaultSpawns)
{
info.ReplyToCommand($"{Localizer["Prefix"]} The Spawn Editor cannot be used if you are using the default spawns!");
return;
}
g_bIsActiveEditor = !g_bIsActiveEditor;
info.ReplyToCommand($"{Localizer["Prefix"]} Spawn Editor has been {ChatColors.Green}{(g_bIsActiveEditor ? "Enabled" : "Disabled")}");
if (g_bIsActiveEditor)
Expand Down
1 change: 1 addition & 0 deletions source/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Gameplay
[JsonPropertyName("Default Weapons")] public int DefaultModeWeapons { get; set; } = 2;
[JsonPropertyName("Switch Weapons")] public bool SwitchWeapons { get; set; } = true;
[JsonPropertyName("Allow Buymenu")] public bool AllowBuyMenu { get; set; } = true;
[JsonPropertyName("Use Default Spawns")] public bool DefaultSpawns { get; set; } = false;
[JsonPropertyName("Respawn Players After New Mode")] public bool RespawnPlayersAtNewMode { get; set; } = false;
}
public class General
Expand Down
33 changes: 20 additions & 13 deletions source/Deathmatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

namespace Deathmatch;

[MinimumApiVersion(166)]
[MinimumApiVersion(178)]
public partial class DeathmatchCore : BasePlugin, IPluginConfig<DeathmatchConfig>
{
public override string ModuleName => "Deathmatch Core";
public override string ModuleAuthor => "Nocky";
public override string ModuleVersion => "1.0.7";
public override string ModuleVersion => "1.0.8";
public static DeathmatchCore Instance { get; set; } = new();
public class ModeInfo
{
Expand All @@ -27,7 +27,6 @@ public class ModeInfo
public bool OnlyHS { get; set; } = false;
public bool KnifeDamage { get; set; } = true;
public bool RandomWeapons { get; set; } = true;
public bool CenterMessage { get; set; } = false;
public string CenterMessageText { get; set; } = "";
}

Expand Down Expand Up @@ -66,6 +65,7 @@ public enum AcquireMethod : int
public static bool g_bIsActiveEditor = false;
public static bool g_bDefaultMapSpawnDisabled = false;
public static bool g_bWeaponRestrictGlobal;
public static bool IsCasualGamemode;

public MemoryFunctionWithReturn<CCSPlayer_ItemServices, CEconItemView, AcquireMethod, NativeObject, AcquireResult>? CCSPlayer_CanAcquireFunc;
public MemoryFunctionWithReturn<int, string, CCSWeaponBaseVData>? GetCSWeaponDataFromKeyFunc;
Expand Down Expand Up @@ -111,6 +111,7 @@ public override void Load(bool hotReload)
AddCustomCommands(cmd, "", 3);
foreach (string radioName in RadioMessagesList)
AddCommandListener(radioName, OnPlayerRadioMessage);
AddCommandListener("autobuy", OnRandomWeapons);

RegisterListener<Listeners.OnMapEnd>(() => { modeTimer?.Kill(); });
RegisterListener<Listeners.OnMapStart>(mapName =>
Expand Down Expand Up @@ -152,14 +153,11 @@ public override void Load(bool hotReload)
}, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
}
AddTimer(1.0f, () =>
{
RemoveEntities();
LoadMapSpawns(ModuleDirectory + $"/spawns/{mapName}.json", true);
SetupDeathMatchConfigValues();
SetupCustomMode(Config.Gameplay.MapStartMode.ToString());
SetupDeathmatchMenus();
});
RemoveEntities();
SetupDeathMatchConfigValues();
SetupCustomMode(Config.Gameplay.MapStartMode.ToString());
SetupDeathmatchMenus();
LoadMapSpawns(ModuleDirectory + $"/spawns/{mapName}.json", true);
});
});
RegisterListener<Listeners.OnTick>(() =>
Expand All @@ -177,7 +175,7 @@ public override void Load(bool hotReload)
{
foreach (var p in Utilities.GetPlayers().Where(p => playerData.ContainsPlayer(p) && playerData[p].HudMessages))
{
if (ModeData.CenterMessage && !string.IsNullOrEmpty(ModeData.CenterMessageText) && MenuManager.GetActiveMenu(p) == null)
if (!string.IsNullOrEmpty(ModeData.CenterMessageText) && MenuManager.GetActiveMenu(p) == null)
{
p.PrintToCenterHtml($"{ModeData.CenterMessageText}");
}
Expand Down Expand Up @@ -223,7 +221,6 @@ public void SetupCustomMode(string modetype)
ModeData.OnlyHS = modeValue["only_hs"]?.Value<bool>() ?? false;
ModeData.KnifeDamage = modeValue["allow_knife_damage"]?.Value<bool>() ?? true;
ModeData.RandomWeapons = modeValue["random_weapons"]?.Value<bool>() ?? false;
ModeData.CenterMessage = modeValue["allow_center_message"]?.Value<bool>() ?? false;
ModeData.CenterMessageText = modeValue["center_message_text"]?.ToString() ?? "";
g_iActiveMode = int.Parse(modetype);

Expand Down Expand Up @@ -298,6 +295,10 @@ public void SetupDeathmatchConfiguration(bool isNewMode)
}
public void SetupDeathMatchConfigValues()
{
var gameType = ConVar.Find("game_type")!.GetPrimitiveValue<int>();
Server.PrintToConsole($"gametype {gameType}");
IsCasualGamemode = gameType != 1;

var iHideSecond = Config.General.HideRoundSeconds ? 1 : 0;
var time = ConVar.Find("mp_timelimit")!.GetPrimitiveValue<float>();
var iFFA = Config.Gameplay.IsFFA ? 1 : 0;
Expand All @@ -310,6 +311,12 @@ public void SetupDeathMatchConfigValues()
Server.ExecuteCommand("mp_buy_anywhere 1;mp_buytime 60000;mp_buy_during_immunity 0");
else
Server.ExecuteCommand("mp_buy_anywhere 0;mp_buytime 0;mp_buy_during_immunity 0");

if (!IsCasualGamemode)
{
var TeamMode = Config.Gameplay.IsFFA ? 0 : 1;
Server.ExecuteCommand($"mp_dm_teammode {TeamMode}; mp_dm_bonus_length_max 0;mp_dm_bonus_length_min 0;mp_dm_time_between_bonus_max 9999;mp_dm_time_between_bonus_min 9999;mp_respawn_immunitytime 0");
}
}
public int GetModeType()
{
Expand Down
79 changes: 23 additions & 56 deletions source/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
timer = AdminManager.PlayerHasPermissions(player, Config.PlayersSettings.VIPFlag) ? Config.PlayersSettings.RespawnTimeVIP : Config.PlayersSettings.RespawnTime;
@event.FireEventToClient(player);
}

AddTimer(timer, () =>
{
if (player != null && player.IsValid)
{
string[] spawns = CheckAvaibleSpawns(player, player.TeamNum, IsBot);
if (!string.IsNullOrEmpty(spawns[0]))
{
switch (spawns[0])
{
case "not found":
RespawnPlayer(player, spawns, false);
SendConsoleMessage($"[Deathmatch] Player {player.PlayerName} was respawned, but no available spawn point was found! Therefore, a random spawn was selected.", ConsoleColor.DarkYellow);
break;
case "default":
RespawnPlayer(player, spawns, false);
break;
default:
RespawnPlayer(player, spawns);
break;
}
}
}
}, TimerFlags.STOP_ON_MAPCHANGE);
AddTimer(timer, () => { PerformRespawn(player, player.TeamNum, IsBot); }, TimerFlags.STOP_ON_MAPCHANGE);

if (attacker != player && playerData.ContainsPlayer(attacker) && attacker.PlayerPawn.Value != null)
{
Expand Down Expand Up @@ -191,37 +168,30 @@ private HookResult OnPlayerRadioMessage(CCSPlayerController? player, CommandInfo

return HookResult.Continue;
}

private HookResult OnRandomWeapons(CCSPlayerController? player, CommandInfo info)
{
return HookResult.Stop;
}
private HookResult OnTakeDamage(DynamicHook hook)
{
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 damageInfo = hook.GetParam<CTakeDamageInfo>(1);
var a = damageInfo.Attacker.Index;

if (a == 0)
return HookResult.Continue;
var player = new CCSPlayerController(new CCSPlayerPawn(hook.GetParam<CEntityInstance>(0).Handle).Controller.Value!.Handle);
var attacker = new CCSPlayerController(new CCSPlayerPawn(damageInfo.Attacker.Value!.Handle).Controller.Value!.Handle);

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

if (player != null && player.IsValid && attacker != null && attacker.IsValid)
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") || damageInfo.Ability.Value!.DesignerName.Contains("bayonet")))
{
attacker.PrintToCenter(Localizer["Knife_damage_disabled"]);
damageInfo.Damage = 0;
}
damageInfo.Damage = 0;
return HookResult.Continue;
}
if (!ModeData.KnifeDamage && damageInfo.Ability.IsValid && (damageInfo.Ability.Value!.DesignerName.Contains("knife") || damageInfo.Ability.Value!.DesignerName.Contains("bayonet")))
{
attacker.PrintToCenter(Localizer["Knife_damage_disabled"]);
damageInfo.Damage = 0;
}
return HookResult.Continue;
}
Expand All @@ -246,6 +216,12 @@ private HookResult OnWeaponCanAcquire(DynamicHook hook)
return HookResult.Continue;
}

if (!IsCasualGamemode && blockRandomWeaponsIntegeration.Contains(player))
{
hook.SetReturn(AcquireResult.AlreadyPurchased);
return HookResult.Stop;
}

if (ModeData.RandomWeapons)
{
if (!string.IsNullOrEmpty(Config.SoundSettings.CantEquipSound))
Expand All @@ -257,15 +233,6 @@ private HookResult OnWeaponCanAcquire(DynamicHook hook)

if (!AllowedPrimaryWeaponsList.Contains(vdata!.Name!) && !AllowedSecondaryWeaponsList.Contains(vdata.Name))
{
/*if (vdata.Name.Contains("knife") || vdata.Name.Contains("bayonet"))
{
if (player.IsBot)
{
hook.SetReturn(AcquireResult.AlreadyPurchased);
return HookResult.Stop;
}
return HookResult.Continue;
}*/
if (!player.IsBot)
{
if (!string.IsNullOrEmpty(Config.SoundSettings.CantEquipSound))
Expand Down
23 changes: 6 additions & 17 deletions source/Functions/Players.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Deathmatch
{
public partial class DeathmatchCore
{
public List<CCSPlayerController> blockRandomWeaponsIntegeration = new List<CCSPlayerController>();
public class DeathmatchPlayerData
{
public required string PrimaryWeapon { get; set; }
Expand Down Expand Up @@ -205,6 +206,11 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode)
playerData[player].SpawnProtection = true;
var timer = AdminManager.PlayerHasPermissions(player, Config.PlayersSettings.VIPFlag) ? Config.PlayersSettings.ProtectionTimeVIP : Config.PlayersSettings.ProtectionTime;
AddTimer(timer, () => playerData[player].SpawnProtection = false, TimerFlags.STOP_ON_MAPCHANGE);
if (!IsCasualGamemode && !blockRandomWeaponsIntegeration.Contains(player))
{
blockRandomWeaponsIntegeration.Add(player);
AddTimer(0.25f, () => blockRandomWeaponsIntegeration.Remove(player), TimerFlags.STOP_ON_MAPCHANGE);
}
}

int slot = IsHaveWeaponFromSlot(player, 0);
Expand Down Expand Up @@ -330,23 +336,6 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode)
}
}, TimerFlags.STOP_ON_MAPCHANGE);
}
public static void RespawnPlayer(CCSPlayerController player, string[] spawn, bool teleport = true)
{
if (!player.IsValid || !player.PlayerPawn.IsValid || player.PawnIsAlive)
return;

if (player.TeamNum == 2 || player.TeamNum == 3)
{
player.Respawn();

if (teleport)
{
var position = ParseVector(spawn[0]);
var angle = ParseQAngle(spawn[1]);
player.PlayerPawn.Value!.Teleport(position, angle, new Vector(0, 0, 0));
}
}
}
public static bool IsPlayerValid(CCSPlayerController player)
{
if (player is null || !player.IsValid || !player.PlayerPawn.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17)
Expand Down
Loading

0 comments on commit 89e90bf

Please sign in to comment.