• No health loss while the player has armor
    2 replies, posted
I wanted to make it so if the player has greater than 1 armor, then his health will remain the same until his armor is 100% depleted. It is meant to be used with godmode, faking damage. [lua] local damage function Damagestuff(ply,hitbox,dmginfo) damage = dmginfo:GetDamage if ply:IsAlive() and ply:Armor() > 1 and dmginfo:IsDamageType( DMG_BULLET ) then ply:SetArmor(ply:Armor() - damage) elseif ply:Alive() and ply:Armor() < 1 do ply:SetHealth(ply:Health() - damage) end end end end for k, v in pairs(player.GetAll()) do if v:Alive() and v:Armor() < 0 then v:SetArmor(0) end end [/lua]
[code]local function EntityTakeDamage( ent, inflictor, attacker, amount, info ) if not ent:IsPlayer( ) then return end if ent:Armor( ) < 1 then return end local protect protect = pl:Armor( ) - amount if protect <= 0 then pl:SetArmor( 0 ) info:SetDamage( math.abs( protect ) ) else pl:SetArmor( protect ) info:SetDamage( 0 ) end end hook.Add( "EntityTakeDamage", "Shield.EntityTakeDamage", EntityTakeDamage )[/code] Something like that is what you want to do, if you want it to be a shield like some shooters have.
I had to fix it just a tad, but it works, thanks! [lua] local function EntityTakeDamage( ent, inflictor, attacker, amount, info ) if not ent:IsPlayer( ) then return end if ent:Armor( ) < 1 then return end local protect protect = ent:Armor( ) - amount if protect <= 0 then ent:SetArmor( 0 ) info:SetDamage( math.abs( protect ) ) else ent:SetArmor( protect ) info:SetDamage( 0 ) end end hook.Add( "EntityTakeDamage", "Shield.EntityTakeDamage", EntityTakeDamage ) [/lua]
Sorry, you need to Log In to post a reply to this thread.