diff --git a/src/Jail.cs b/src/Jail.cs index 4bcd79c..9ffe859 100644 --- a/src/Jail.cs +++ b/src/Jail.cs @@ -12,6 +12,7 @@ using CounterStrikeSharp.API.Modules.Utils; using CounterStrikeSharp.API.Modules.Entities.Constants; using CSTimer = CounterStrikeSharp.API.Modules.Timers; +using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; // main plugin file, controls central hooking // defers to warden, lr and sd @@ -103,6 +104,7 @@ void register_commands() // reg sd commands AddCommand("sd","start and sd",sd.sd_cmd); + AddCommand("cancel_sd","cancel an sd",sd.cancel_sd_cmd); // debug if(Debug.enable) @@ -128,13 +130,20 @@ void register_hook() RegisterEventHandler(OnSwitchTeam); RegisterEventHandler(OnMapChange); RegisterEventHandler(OnPlayerDeath); - RegisterEventHandler(OnPlayerHurt); RegisterEventHandler(OnItemEquip); RegisterEventHandler(OnGrenadeThrown); + RegisterEventHandler(OnPlayerHurt); + VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(OnTakeDamage,HookMode.Pre); + // TODO: need to hook weapon drop } + public override void Unload(bool hotReload) + { + VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Unhook(OnTakeDamage,HookMode.Pre); + } + HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) { CCSPlayerController? player = @event.Userid; @@ -172,14 +181,33 @@ HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) if(player != null && player.is_valid()) { - lr.take_damage(player,attacker,damage,health,hitgroup); - warden.take_damage(player,attacker,damage,health); - sd.take_damage(player,attacker,damage,health,hitgroup); + lr.player_hurt(player,attacker,damage,health,hitgroup); + warden.player_hurt(player,attacker,damage,health); + sd.player_hurt(player,attacker,damage,health,hitgroup); } return HookResult.Continue; } + HookResult OnTakeDamage(DynamicHook handle) + { + CEntityInstance victim = handle.GetParam(0); + CTakeDamageInfo damage_info = handle.GetParam(1); + + CHandle dealer = damage_info.Attacker; + + // get player and attacker + CCSPlayerController? player = victim.player(); + CCSPlayerController? attacker = dealer.player(); + + + + sd.take_damage(player,attacker,ref damage_info.Damage); + lr.take_damage(player,attacker,ref damage_info.Damage); + + return HookResult.Continue; + } + HookResult OnMapChange(EventMapTransition @event, GameEventInfo info) { warden.map_start(); diff --git a/src/LastRequest/Dodgeball.cs b/src/LastRequest/Dodgeball.cs index 74d9b77..7772b51 100644 --- a/src/LastRequest/Dodgeball.cs +++ b/src/LastRequest/Dodgeball.cs @@ -46,7 +46,7 @@ public override void init_player(CCSPlayerController player) } } - public override bool take_damage(int damage, int health, int hitgroup) + public override void player_hurt(int damage, int health, int hitgroup) { CCSPlayerController? player = Utilities.GetPlayerFromSlot(player_slot); @@ -54,8 +54,6 @@ public override bool take_damage(int damage, int health, int hitgroup) { player.PlayerPawn.Value.CommitSuicide(true, true); } - - return true; } public override void grenade_thrown() diff --git a/src/LastRequest/HeadshotOnly.cs b/src/LastRequest/HeadshotOnly.cs index 17df629..4877022 100644 --- a/src/LastRequest/HeadshotOnly.cs +++ b/src/LastRequest/HeadshotOnly.cs @@ -25,8 +25,13 @@ public override void init_player(CCSPlayerController player) player.GiveNamedItem("weapon_deagle"); } - public override bool take_damage(int health,int damage, int hitgroup) + public override void player_hurt(int health,int damage, int hitgroup) { - return hitgroup == Lib.HITGROUP_HEAD; + // dont allow damage when its not to head + if(hitgroup != Lib.HITGROUP_HEAD) + { + CCSPlayerController? player = Utilities.GetPlayerFromSlot(player_slot); + Lib.restore_hp(player,damage,health); + } } } \ No newline at end of file diff --git a/src/LastRequest/LRBase.cs b/src/LastRequest/LRBase.cs index 186a3db..3897c98 100644 --- a/src/LastRequest/LRBase.cs +++ b/src/LastRequest/LRBase.cs @@ -154,12 +154,17 @@ public void activate() public virtual void weapon_fire(String name) {} public virtual void ent_created(CEntityInstance entity) {} - - public virtual bool take_damage(int health,int damage, int hitgroup) + + public virtual bool take_damage() { return !restrict_damage; } + public virtual void player_hurt(int health,int damage, int hitgroup) + { + + } + public virtual bool weapon_drop(String name) { return !restrict_drop; diff --git a/src/LastRequest/LastRequest.cs b/src/LastRequest/LastRequest.cs index ad6f1eb..622675e 100644 --- a/src/LastRequest/LastRequest.cs +++ b/src/LastRequest/LastRequest.cs @@ -302,7 +302,29 @@ bool is_pair(CCSPlayerController? v1, CCSPlayerController? v2) return lr1.slot == lr2.slot; } - public void take_damage(CCSPlayerController? player, CCSPlayerController? attacker, int damage,int health, int hitgroup) + + + public void player_hurt(CCSPlayerController? player, CCSPlayerController? attacker, int damage,int health, int hitgroup) + { + // check no damage restrict + LRBase? lr = find_lr(player); + + // no lr + if(lr == null) + { + return; + } + + // not a pair + if(!is_pair(player,attacker)) + { + return; + } + + lr.player_hurt(damage,health,hitgroup); + } + + public void take_damage(CCSPlayerController? player, CCSPlayerController? attacker, ref float damage) { // neither player is in lr we dont care if(!in_lr(player) && !in_lr(attacker)) @@ -313,20 +335,22 @@ public void take_damage(CCSPlayerController? player, CCSPlayerController? attack // not a pair restore hp if(!is_pair(player,attacker)) { - Lib.restore_hp(player,damage,health); + damage = 0.0f; return; } // check no damage restrict LRBase? lr = find_lr(player); - if(lr != null) + if(lr == null) { - if(!lr.take_damage(damage,health,hitgroup)) - { - Lib.restore_hp(player,damage,health); - } + return; } + + if(!lr.take_damage()) + { + damage = 0.0f; + } } public void weapon_equip(CCSPlayerController? player,String name) diff --git a/src/Lib.cs b/src/Lib.cs index 14870c9..ed8ba45 100644 --- a/src/Lib.cs +++ b/src/Lib.cs @@ -156,6 +156,7 @@ static public bool is_generic_admin(this CCSPlayerController? player) static public void draw_laser(CCSPlayerController? player) { + /* CEnvBeam? laser = Utilities.CreateEntityByName("env_beam"); CEnvBeam? end = Utilities.CreateEntityByName("env_beam"); @@ -180,6 +181,53 @@ static public void draw_laser(CCSPlayerController? player) laser.Teleport(player.PlayerPawn.Value.AbsOrigin, player.PlayerPawn.Value.AbsRotation, player.PlayerPawn.Value.AbsVelocity); laser.DispatchSpawn(); + */ + } + + static public CCSPlayerController? player(this CEntityInstance? instance) + { + if(instance == null) + { + return null; + } + + // grab the pawn index + CEntityIndex? ent_index = instance.EntityIndex; + + if(ent_index == null) + { + return null; + } + + int player_index = (int)ent_index.Value.Value; + + // grab player controller from pawn + CCSPlayerPawn? player_pawn = Utilities.GetEntityFromIndex(player_index); + + // pawn valid + if(player_pawn == null || !player_pawn.IsValid) + { + return null; + } + + // controller valid + if(player_pawn.OriginalController == null || !player_pawn.OriginalController.IsValid) + { + return null; + } + + // any further validity is up to the caller + return player_pawn.OriginalController.Value; + } + + static public CCSPlayerController? player(this CHandle handle) + { + if(handle.IsValid && handle.Value.IsValid) + { + return handle.Value.player(); + } + + return null; } static public void mute(this CCSPlayerController? player) diff --git a/src/SpecialDay/SpecialDay.cs b/src/SpecialDay/SpecialDay.cs index e74138d..987fc33 100644 --- a/src/SpecialDay/SpecialDay.cs +++ b/src/SpecialDay/SpecialDay.cs @@ -27,13 +27,13 @@ public void end_sd(bool forced = false) JailPlugin.end_event(); active_sd.end_common(); active_sd = null; - } - - // restore all players if from a cancel - if(forced) - { - } + // restore all players if from a cancel + if(forced) + { + Lib.announce(SPECIALDAY_PREFIX,"Special day cancelled"); + } + } } public void round_end() @@ -53,6 +53,12 @@ public void setup_sd(CCSPlayerController? player, ChatMenuOption option) return; } + if(active_sd != null) + { + player.announce(SPECIALDAY_PREFIX,"You cannot call two SD's at once"); + return; + } + String name = option.Text; switch(name) @@ -111,7 +117,7 @@ public void start_sd() } } - public void take_damage(CCSPlayerController? player,CCSPlayerController? attacker, int damage,int health, int hitgroup) + public void take_damage(CCSPlayerController? player, CCSPlayerController? attacker, ref float damage) { if(active_sd == null || player == null || !player.is_valid()) { @@ -120,8 +126,24 @@ public void take_damage(CCSPlayerController? player,CCSPlayerController? attacke if(active_sd.restrict_damage) { - Lib.restore_hp(player,damage,health); + damage = 0.0f; + } + } + + 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")] diff --git a/src/Warden/JailPlayer.cs b/src/Warden/JailPlayer.cs index 3f186dc..698cce5 100644 --- a/src/Warden/JailPlayer.cs +++ b/src/Warden/JailPlayer.cs @@ -77,7 +77,7 @@ public void rebel_weapon_fire(CCSPlayerController? player, String weapon) } } - public void take_damage(CCSPlayerController? player, CCSPlayerController? attacker, int health, int damage) + public void player_hurt(CCSPlayerController? player, CCSPlayerController? attacker, int health, int damage) { if(player == null || attacker == null || !player.is_valid() || !attacker.is_valid()) { diff --git a/src/Warden/Warden.cs b/src/Warden/Warden.cs index 14a8da2..998a893 100644 --- a/src/Warden/Warden.cs +++ b/src/Warden/Warden.cs @@ -381,13 +381,13 @@ public void death(CCSPlayerController? player, CCSPlayerController? killer) } - public void take_damage(CCSPlayerController? player, CCSPlayerController? attacker, int damage,int health) + public void player_hurt(CCSPlayerController? player, CCSPlayerController? attacker, int damage,int health) { var jail_player = jail_player_from_player(player); if(jail_player != null) { - jail_player.take_damage(player,attacker,damage, health); + jail_player.player_hurt(player,attacker,damage, health); } }