math.round = function(num, decimals) if (not decimals or decimals <= 0) then return math.floor(num + 0.5) else local mod = 10 ^ decimals return math.floor((num * mod) + 0.5) / mod end end function ReloadOnHit(damage, activator, caller) if not caller:IsValid() then return end if ( not caller:IsBot() ) and ( not caller:IsObject() ) and ( not caller:IsNPC() ) then return end if caller.m_iTeamNum == 1 then return end if caller.m_iTeamNum == activator.m_iTeamNum then return end local upgradeLevel = nil if activator:GetPlayerItemBySlot(0):GetAttributeValue("purchased") ~= nil then upgradeLevel = activator:GetPlayerItemBySlot(0):GetAttributeValue("purchased") elseif activator:GetPlayerItemBySlot(1):GetAttributeValue("purchased") ~= nil then upgradeLevel = activator:GetPlayerItemBySlot(1):GetAttributeValue("purchased") elseif activator:GetPlayerItemBySlot(2):GetAttributeValue("purchased") ~= nil then upgradeLevel = activator:GetPlayerItemBySlot(2):GetAttributeValue("purchased") end if upgradeLevel == nil then return end local BASE_CLIP = 4 local weapon = activator:GetPlayerItemBySlot(0) if IsValid( activator:GetPlayerItemBySlot(0) ) and ( activator:GetPlayerItemBySlot(0):GetItemName() == "Sticky Situation" ) then weapon = activator:GetPlayerItemBySlot(0) BASE_CLIP = 4 else weapon = activator:GetPlayerItemBySlot(1) BASE_CLIP = 8 end if IsValid(weapon) and ( weapon:GetItemName() ~= "The Cow Mangler 5000" ) then local clipBonusMult = weapon:GetAttributeValueByClass("mult_clipsize", 1) local clipBonusMult = clipBonusMult * weapon:GetAttributeValueByClass("mult_clipsize_upgrade", 1) local clipBonusAtomic = weapon:GetAttributeValueByClass("mult_clipsize_upgrade_atomic", 0) local airstrikeKills = 0 local overloadRefundAmount = 0 if weapon:GetItemName() == "The Air Strike" then airstrikeKills = activator.m_Shared.m_iDecapitations + 1 end local maxClip = math.round( ( BASE_CLIP * clipBonusMult ) + clipBonusAtomic + airstrikeKills, 0 ) if activator:IsRealPlayer() == true then activator.m_iAmmo[TF_AMMO_weapon] = activator.m_iAmmo[TF_AMMO_weapon] - upgradeLevel if activator.m_iAmmo[TF_AMMO_weapon] < 0 then upgradeLevel = upgradeLevel + activator.m_iAmmo[TF_AMMO_weapon] activator.m_iAmmo[TF_AMMO_weapon] = 0 end end weapon.m_iClip1 = weapon.m_iClip1 + upgradeLevel if weapon.m_iClip1 > maxClip then overloadRefundAmount = weapon.m_iClip1 - maxClip overloadRefundAmount = overloadRefundAmount + upgradeLevel activator.m_iAmmo[TF_AMMO_weapon] = activator.m_iAmmo[TF_AMMO_weapon] + overloadRefundAmount weapon.m_iClip1 = maxClip end else local clipBonusMult = weapon:GetAttributeValueByClass("mult_clipsize_upgrade", 1) local maxClip = (BASE_CLIP * 5) * clipBonusMult weapon.m_flEnergy = weapon.m_flEnergy + ( ( maxClip * upgradeLevel ) ) if weapon.m_flEnergy > maxClip then weapon.m_flEnergy = maxClip end if ( weapon.m_flEnergy / 5 ) ~= ( math.floor( weapon.m_flEnergy / 5 ) ) then local newClip = math.max( math.round( weapon.m_flEnergy / 100, 1 ), 5 ) --gotta love number theory newClip = newClip * 100 weapon.m_flEnergy = newClip --How this works: lets say energy = 47 --47/5 ~= floor(47/5) --47/100 = 0.47 --round to nearest tenth: 0.5 --* by 100 to undo /: 50 --energy = 50 --note that this is called after adding, this can make it go from 45 -> 60 when upgradeLevel = 0.2 end end end