That script does work to some extent:
If I attack someone for 5 damage and my opponent has 1 HP remaining. ->
Opponent does not take damage.If I attack someone for 5 damage and my opponent has 2 HP remaining. ->
Opponent dies because of damage.Problem is that
ply:Health() returns the player’s health
before damage is taken.
Suggestion: check if the damage is lethal instead.
Tip #1: You can get damage info and suppress damage with the
GM:EntityTakeDamage hook.
Tip #2: Example of how to use the hook to detect and suppress lethal damage:
hook.Add( "EntityTakeDamage", "SurrenderHook", function ( target, dmg )
if target:Health() <= dmg:GetDamage() then
-- TODO: Strip player
-- TODO: Apply slowness
ply:SetHealth( 1 )
return true -- Suppress lethal damage
end
end )