local DAMAGE_MULT = 0.02 -- remember that shield takes full rampup damage regardless of distance local MIN_DAMAGE_METER = 0 -- damage cannot bring shield below this threshold. put at 0 to disable this grace period local function handleShield(shieldEnt) local owner = shieldEnt.m_hOwnerEntity shieldEnt:Color("18 255 0") local lastDamageTick = TickCount() shieldEnt:AddCallback(ON_DEATH, function(_, damageinfo) -- util.PrintToChatAll("Shield down, removing attribute!") local medigun = owner:GetPlayerItemBySlot(1) medigun:SetAttributeValue("generate rage on heal",0) end) shieldEnt:AddCallback(ON_DAMAGE_RECEIVED_POST, function(_, damageinfo) if owner.m_flRageMeter < MIN_DAMAGE_METER then return end local curTick = TickCount() lastDamageTick = curTick shieldEnt:Color("0 100 0") local damage = damageinfo.Damage * DAMAGE_MULT owner.m_flRageMeter = owner.m_flRageMeter - damage if owner.m_flRageMeter <= MIN_DAMAGE_METER then owner.m_flRageMeter = MIN_DAMAGE_METER --Shield is dead, remove attribute from owner local medigun = owner:GetPlayerItemBySlot(1) medigun:SetAttributeValue("generate rage on heal",0) end -- owner:Print(PRINT_TARGET_CHAT, "Shield taken damage for: " .. damage) timer.Simple(0.1, function() if not IsValid(shieldEnt) then return end -- prevents constant flickering on constant damage if lastDamageTick ~= curTick then return end shieldEnt:Color("18 255 0") end) end) end ents.AddCreateCallback("entity_medigun_shield", function(ent) timer.Simple(0, function() if ent.m_iTeamNum ~= 3 then -- util.PrintToChatAll("Shield is not team 3...") return end local owner = ent.m_hOwnerEntity if owner:GetAttributeValue("hidden string attribute 1") ~= "destructible" then -- util.PrintToChatAll("Shield doesn't have the right attribute...") return end handleShield(ent) end) end)