AddEventCallback("post_inventory_application", function(eventTable) local playerNetID = eventTable.userid local activator = ents.GetPlayerByUserId(playerNetID) if activator.m_iClass == 9 and activator:IsRealPlayer() == true then local disposableSentryTotal = 0 local disposableSentryLimit = activator:GetAttributeValueByClass("engy_disposable_sentries", 0) local buildingTable = ents.FindAllByClass("obj_*") for _, entity in pairs(buildingTable) do --print(entity.m_hBuilder) if entity.m_hBuilder == activator then --print("Max health is " .. entity.m_iMaxHealth) --print("Current health is " .. entity.m_iHealth) local entityRemainingHealthMultiplier = (entity.m_iHealth / entity.m_iMaxHealth) --object type is placed in a variable because it will be accessed multiple times local buildingObjectType = entity.m_iObjectType local buildingBaseHealth = 216 --if the activator has the gunslinger mini sentry attribute, or you're a disposable building, and you're a sentry, your base health is 100 if (activator:GetAttributeValue("mod wrench builds minisentry", true) or entity.m_bDisposableBuilding == 1) and buildingObjectType == 2 then buildingBaseHealth = 100 if entity.m_bDisposableBuilding == 1 then disposableSentryTotal = disposableSentryTotal + 1 end elseif entity.m_iUpgradeLevel == 1 then buildingBaseHealth = 150 elseif entity.m_iUpgradeLevel == 2 then buildingBaseHealth = 180 end --if none of the above checks pass, we will assume that we are a level 3 building local buildingMaxHealth = activator:GetAttributeValueByClass("mult_engy_building_health", 1) * buildingBaseHealth --print(buildingMaxHealth) local damageCalibration = -1 local sufferingTable = { Attacker = nil, -- Attacker Inflictor = nil, -- Direct cause of damage, usually a projectile Weapon = nil, Damage = damageCalibration, DamageType = nil, -- Damage type, see DMG_* globals. Can be combined with | operator DamageCustom = nil, -- Custom damage type, see TF_DMG_* globals CritType = 0, -- Crit type, 0 = no crit, 1 = mini crit, 2 = normal crit DamagePosition = nil, -- Where the target was hit at DamageForce = nil, -- Knockback force of the attack ReportedPosition = nil -- Where the attacker attacked from } entity.m_iMaxHealth = buildingMaxHealth entity.m_iHealth = buildingMaxHealth * entityRemainingHealthMultiplier entity:TakeDamage(sufferingTable) if disposableSentryTotal > disposableSentryLimit and entity.m_bDisposableBuilding == 1 then damageCalibration = 9000 entity:TakeDamage(sufferingTable) --print("Killed a disposable") end end end end end)