From 6a66bf900e466b23b45d7b6ef1f2701c669c3eb2 Mon Sep 17 00:00:00 2001 From: destoer Date: Sat, 25 Nov 2023 18:58:56 +0000 Subject: [PATCH] port over more sds --- README.md | 10 +--- src/Jail.cs | 11 +++- src/LastRequest/Dodgeball.cs | 36 +----------- src/LastRequest/Grenade.cs | 16 +----- src/Lib.cs | 39 +++++++++++++ src/SpecialDay/Dodgeball.cs | 59 +++++++++++++++++++ src/SpecialDay/FriendlyFire.cs | 1 - src/SpecialDay/Grenade.cs | 46 +++++++++++++++ src/SpecialDay/HeadshotOnly.cs | 55 ++++++++++++++++++ src/SpecialDay/Juggernaut.cs | 1 - src/SpecialDay/Knife.cs | 39 +++++++++++++ src/SpecialDay/SDBase.cs | 11 +++- src/SpecialDay/SpecialDay.cs | 100 +++++++++++++++++++++++++++++---- 13 files changed, 353 insertions(+), 71 deletions(-) create mode 100644 src/SpecialDay/Dodgeball.cs create mode 100644 src/SpecialDay/Grenade.cs create mode 100644 src/SpecialDay/HeadshotOnly.cs create mode 100644 src/SpecialDay/Knife.cs diff --git a/README.md b/README.md index 2f4823f..0eda320 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,5 @@ Improve damage blocking # SD TODO Waiting on player colour issues fixed for alot of these -Tank, Hide and Seek - -Dodgeball, Grenade, Zombie - -Gun game, Knife, - -Spectre, Headshot, Laser wars - +Tank, Hide and Seek, Zombie +Gun game, Spectre, Laser wars diff --git a/src/Jail.cs b/src/Jail.cs index 2857a04..e4897e4 100644 --- a/src/Jail.cs +++ b/src/Jail.cs @@ -67,6 +67,12 @@ public static void end_event() public override void Load(bool hotReload) { + if(Lib.is_windows()) + { + Console.WriteLine("This plugin only works on linux - (OnTakeDamage and others are broken)"); + return; + } + global_ctx = this; register_commands(); @@ -83,6 +89,7 @@ void register_listener() RegisterListener(entity => { lr.ent_created(entity); + sd.ent_created(entity); }); } @@ -104,7 +111,8 @@ void register_commands() AddCommand("lr_stats","list lr stats",lr.lr_stats.lr_stats_cmd); // reg sd commands - AddCommand("sd","start and sd",sd.sd_cmd); + AddCommand("sd","start a sd",sd.sd_cmd); + AddCommand("sd_ff","start a ff sd",sd.sd_ff_cmd); AddCommand("cancel_sd","cancel an sd",sd.cancel_sd_cmd); // debug @@ -152,6 +160,7 @@ HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) if(player != null && player.is_valid()) { lr.grenade_thrown(player); + sd.grenade_thrown(player); } return HookResult.Continue; diff --git a/src/LastRequest/Dodgeball.cs b/src/LastRequest/Dodgeball.cs index 911757d..07a1810 100644 --- a/src/LastRequest/Dodgeball.cs +++ b/src/LastRequest/Dodgeball.cs @@ -58,42 +58,12 @@ public override void player_hurt(int damage, int health, int hitgroup) public override void grenade_thrown() { - if(JailPlugin.global_ctx == null) - { - return; - } - - JailPlugin.global_ctx.AddTimer(1.4f,() => - { - CCSPlayerController? player = Utilities.GetPlayerFromSlot(player_slot); - - if(player != null && player.is_valid_alive()) - { - player.GiveNamedItem("weapon_flashbang"); - } - }); + CCSPlayerController? player = Utilities.GetPlayerFromSlot(player_slot); + Lib.give_weapon_delay(player,1.4f,"weapon_flashbang"); } public override void ent_created(CEntityInstance entity) { - if(JailPlugin.global_ctx == null) - { - return; - } - - // remove projectile - if(entity.DesignerName == "flashbang_projectile") - { - if(JailPlugin.global_ctx != null) - { - JailPlugin.global_ctx.AddTimer(1.4f,() => - { - if(entity.IsValid) - { - entity.Remove(); - } - }); - } - } + Lib.remove_ent_delay(entity,1.4f,"flashbang_projectile"); } } \ No newline at end of file diff --git a/src/LastRequest/Grenade.cs b/src/LastRequest/Grenade.cs index ebcfaa5..f4cfca1 100644 --- a/src/LastRequest/Grenade.cs +++ b/src/LastRequest/Grenade.cs @@ -48,19 +48,7 @@ public override void init_player(CCSPlayerController player) public override void grenade_thrown() { - if(JailPlugin.global_ctx == null) - { - return; - } - - JailPlugin.global_ctx.AddTimer(1.4f,() => - { - CCSPlayerController? player = Utilities.GetPlayerFromSlot(player_slot); - - if(player != null && player.is_valid_alive()) - { - player.GiveNamedItem("weapon_hegrenade"); - } - }); + CCSPlayerController? player = Utilities.GetPlayerFromSlot(player_slot); + Lib.give_weapon_delay(player,1.4f,"weapon_hegrenade"); } } \ No newline at end of file diff --git a/src/Lib.cs b/src/Lib.cs index 1a71790..a9dc904 100644 --- a/src/Lib.cs +++ b/src/Lib.cs @@ -91,6 +91,45 @@ static public int get_health(this CCSPlayerController? player) return player.PlayerPawn.Value.Health; } + static public void give_weapon_delay(CCSPlayerController? player,float delay, String name) + { + if(JailPlugin.global_ctx == null) + { + return; + } + + JailPlugin.global_ctx.AddTimer(delay,() => + { + if(player != null && player.is_valid_alive()) + { + player.GiveNamedItem(name); + } + }); + } + + static public void remove_ent_delay(CEntityInstance entity, float delay, String name) + { + if(JailPlugin.global_ctx == null) + { + return; + } + + // remove projectile + if(entity.DesignerName == name) + { + if(JailPlugin.global_ctx != null) + { + JailPlugin.global_ctx.AddTimer(delay,() => + { + if(entity.IsValid) + { + entity.Remove(); + } + }); + } + } + } + static public void set_movetype(this CCSPlayerController? player, MoveType_t type) { if(player == null || !player.is_valid()) diff --git a/src/SpecialDay/Dodgeball.cs b/src/SpecialDay/Dodgeball.cs new file mode 100644 index 0000000..bc160f8 --- /dev/null +++ b/src/SpecialDay/Dodgeball.cs @@ -0,0 +1,59 @@ +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Events; +using CounterStrikeSharp.API.Modules.Memory; +using CounterStrikeSharp.API.Modules.Menu; +using CounterStrikeSharp.API.Modules.Utils; +using CounterStrikeSharp.API.Modules.Entities.Constants; +using CSTimer = CounterStrikeSharp.API.Modules.Timers; + + +public class SDDodgeball : SDBase +{ + public override void setup() + { + announce("Dodgeball started"); + announce("Please 15 seconds for damage be enabled"); + } + + public override void start() + { + announce("Fight!"); + } + + public override void end() + { + announce("Dodgeball is over"); + } + + public override void setup_player(CCSPlayerController player) + { + player.strip_weapons(true); + player.GiveNamedItem("weapon_flashbang"); + weapon_restrict = "flashbang"; + } + + public override void grenade_thrown(CCSPlayerController? player) + { + Lib.give_weapon_delay(player,1.4f,"weapon_flashbang"); + } + + public override void player_hurt(CCSPlayerController? player,int damage, int health, int hitgroup) + { + if(player != null && player.is_valid_alive()) + { + player.PlayerPawn.Value.CommitSuicide(true, true); + } + } + + public override void ent_created(CEntityInstance entity) + { + Lib.remove_ent_delay(entity,1.4f,"flashbang_projectile"); + } + +} \ No newline at end of file diff --git a/src/SpecialDay/FriendlyFire.cs b/src/SpecialDay/FriendlyFire.cs index 219efd8..e4f8df4 100644 --- a/src/SpecialDay/FriendlyFire.cs +++ b/src/SpecialDay/FriendlyFire.cs @@ -31,7 +31,6 @@ public override void start() public override void end() { announce("Friendly fire day is over"); - Lib.disable_friendly_fire(); } public override void setup_player(CCSPlayerController? player) diff --git a/src/SpecialDay/Grenade.cs b/src/SpecialDay/Grenade.cs new file mode 100644 index 0000000..b7d6b2c --- /dev/null +++ b/src/SpecialDay/Grenade.cs @@ -0,0 +1,46 @@ +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Events; +using CounterStrikeSharp.API.Modules.Memory; +using CounterStrikeSharp.API.Modules.Menu; +using CounterStrikeSharp.API.Modules.Utils; +using CounterStrikeSharp.API.Modules.Entities.Constants; +using CSTimer = CounterStrikeSharp.API.Modules.Timers; + + +public class SDGrenade : SDBase +{ + public override void setup() + { + announce("Grenade started"); + announce("Please 15 seconds for damage be enabled"); + } + + public override void start() + { + announce("Fight!"); + } + + public override void end() + { + announce("Grenade is over"); + } + + public override void setup_player(CCSPlayerController player) + { + player.strip_weapons(true); + player.set_health(175); + player.GiveNamedItem("weapon_hegrenade"); + weapon_restrict = "hegrenade"; + } + + public override void grenade_thrown(CCSPlayerController? player) + { + Lib.give_weapon_delay(player,1.4f,"weapon_hegrenade"); + } +} \ No newline at end of file diff --git a/src/SpecialDay/HeadshotOnly.cs b/src/SpecialDay/HeadshotOnly.cs new file mode 100644 index 0000000..2afeb1e --- /dev/null +++ b/src/SpecialDay/HeadshotOnly.cs @@ -0,0 +1,55 @@ +// base lr class +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Events; +using CounterStrikeSharp.API.Modules.Memory; +using CounterStrikeSharp.API.Modules.Menu; +using CounterStrikeSharp.API.Modules.Utils; +using CounterStrikeSharp.API.Modules.Entities.Constants; +using CSTimer = CounterStrikeSharp.API.Modules.Timers; + + +public class SDHeadshotOnly : SDBase +{ + public override void setup() + { + announce("Headshot only started"); + announce("Please 15 seconds for damage be enabled"); + } + + public override void start() + { + announce("Fight!"); + } + + public override void end() + { + announce("Headshot only is over"); + } + + public override void setup_player(CCSPlayerController player) + { + player.strip_weapons(true); + player.GiveNamedItem("weapon_deagle"); + weapon_restrict = "deagle"; + } + + public override void player_hurt(CCSPlayerController? player,int health,int damage, int hitgroup) + { + if(player == null || !player.is_valid_alive()) + { + return; + } + + // dont allow damage when its not to head + if(hitgroup != Lib.HITGROUP_HEAD) + { + Lib.restore_hp(player,damage,health); + } + } +} \ No newline at end of file diff --git a/src/SpecialDay/Juggernaut.cs b/src/SpecialDay/Juggernaut.cs index 6185d20..5708aab 100644 --- a/src/SpecialDay/Juggernaut.cs +++ b/src/SpecialDay/Juggernaut.cs @@ -30,7 +30,6 @@ public override void start() public override void end() { announce("Juggernaut is over"); - Lib.disable_friendly_fire(); } public override void death(CCSPlayerController? player, CCSPlayerController? attacker) diff --git a/src/SpecialDay/Knife.cs b/src/SpecialDay/Knife.cs new file mode 100644 index 0000000..2c1e854 --- /dev/null +++ b/src/SpecialDay/Knife.cs @@ -0,0 +1,39 @@ +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Events; +using CounterStrikeSharp.API.Modules.Memory; +using CounterStrikeSharp.API.Modules.Menu; +using CounterStrikeSharp.API.Modules.Utils; +using CounterStrikeSharp.API.Modules.Entities.Constants; +using CSTimer = CounterStrikeSharp.API.Modules.Timers; + + +public class SDKnifeWarday : SDBase +{ + public override void setup() + { + announce("knife warday started"); + announce("Please 15 seconds for damage be enabled"); + } + + public override void start() + { + announce("Fight!"); + } + + public override void end() + { + announce("knife warday is over"); + } + + public override void setup_player(CCSPlayerController player) + { + player.strip_weapons(); + weapon_restrict = "knife"; + } +} \ No newline at end of file diff --git a/src/SpecialDay/SDBase.cs b/src/SpecialDay/SDBase.cs index e0f15a3..4b6d061 100644 --- a/src/SpecialDay/SDBase.cs +++ b/src/SpecialDay/SDBase.cs @@ -48,6 +48,8 @@ public void end_common() state = SDState.INACTIVE; end(); + Lib.disable_friendly_fire(); + cleanup_players(); } @@ -56,6 +58,13 @@ public virtual bool weapon_equip(String name) return weapon_restrict == "" || name.Contains(weapon_restrict); } + public virtual void player_hurt(CCSPlayerController? player,int health,int damage, int hitgroup) {} + + public virtual void ent_created(CEntityInstance entity) {} + public virtual void grenade_thrown(CCSPlayerController? player) {} + + + public virtual void death(CCSPlayerController? player, CCSPlayerController? attacker) {} public abstract void setup_player(CCSPlayerController player); @@ -97,6 +106,6 @@ public enum SDState }; public bool restrict_damage = false; - String weapon_restrict = ""; + public String weapon_restrict = ""; public SDState state = SDState.INACTIVE; } \ No newline at end of file diff --git a/src/SpecialDay/SpecialDay.cs b/src/SpecialDay/SpecialDay.cs index 873fbc6..2a0343e 100644 --- a/src/SpecialDay/SpecialDay.cs +++ b/src/SpecialDay/SpecialDay.cs @@ -83,6 +83,35 @@ public void setup_sd(CCSPlayerController? player, ChatMenuOption option) type = SDType.SCOUT_KNIFE; break; } + + case "Headshot only": + { + active_sd = new SDHeadshotOnly(); + type = SDType.HEADSHOT_ONLY; + break; + } + + case "Knife warday": + { + active_sd = new SDKnifeWarday(); + type = SDType.KNIFE_WARDAY; + break; + } + + case "Dodgeball": + { + active_sd = new SDDodgeball(); + type = SDType.DODGEBALL; + break; + } + + case "Grenade": + { + active_sd = new SDGrenade(); + type = SDType.GRENADE; + break; + } + } // call the intiail sd setup @@ -116,6 +145,23 @@ public void weapon_equip(CCSPlayerController? player,String name) } } + public void grenade_thrown(CCSPlayerController? player) + { + if(active_sd != null) + { + active_sd.grenade_thrown(player); + } + } + + public void ent_created(CEntityInstance entity) + { + if(active_sd != null) + { + active_sd.ent_created(entity); + } + } + + public void death(CCSPlayerController? player, CCSPlayerController? attacker) { if(active_sd != null) @@ -124,10 +170,25 @@ public void death(CCSPlayerController? player, CCSPlayerController? attacker) } } + public void player_hurt(CCSPlayerController? player, CCSPlayerController? attacker, int damage,int health, int hitgroup) + { + if(active_sd != null && player != null && player.is_valid()) + { + active_sd.player_hurt(player,damage,health,hitgroup); + } + } + public void start_sd() { if(active_sd != null) { + // force ff active + if(override_ff) + { + Lib.announce(SPECIALDAY_PREFIX,"Friendly fire enabled!"); + Lib.enable_friendly_fire(); + } + active_sd.start_common(); } } @@ -145,24 +206,13 @@ public void take_damage(CCSPlayerController? player, CCSPlayerController? attack } } - public void player_hurt(CCSPlayerController? player,CCSPlayerController? attacker, int damage,int health, int hitgroup) - { - if(active_sd == null || player == null || !player.is_valid()) - { - return; - } - - - } - [RequiresPermissions("@css/generic")] public void cancel_sd_cmd(CCSPlayerController? player,CommandInfo command) { end_sd(true); } - [RequiresPermissions("@css/generic")] - public void sd_cmd(CCSPlayerController? player,CommandInfo command) + public void sd_cmd_internal(CCSPlayerController? player) { if(player == null || !player.is_valid()) { @@ -178,14 +228,34 @@ public void sd_cmd(CCSPlayerController? player,CommandInfo command) } ChatMenus.OpenMenu(player, sd_menu); + } + + + [RequiresPermissions("@css/generic")] + public void sd_cmd(CCSPlayerController? player,CommandInfo command) + { + override_ff = false; + + sd_cmd_internal(player); } + [RequiresPermissions("@css/generic")] + public void sd_ff_cmd(CCSPlayerController? player,CommandInfo command) + { + override_ff = true; + + sd_cmd_internal(player); + } public enum SDType { FREIENDLY_FIRE, JUGGERNAUT, + DODGEBALL, + GRENADE, SCOUT_KNIFE, + HEADSHOT_ONLY, + KNIFE_WARDAY, NONE }; @@ -194,11 +264,17 @@ public enum SDType static String[] SD_NAME = { "Friendly fire", "Juggernaut", + "Dodgeball", + "Grenade", "Scout knife", + "Headshot only", + "Knife warday", "None" }; SDBase? active_sd = null; + bool override_ff = false; + SDType type = SDType.NONE; }; \ No newline at end of file