local HEALTH_PER_METAL_RATIO = 4 local METAL_PER_HIT = 20 local HEAL_PARTICLE_OFFSET = Vector(0, 0, 220) local HEAL_SOUND = "Weapon_Wrench.HitBuilding_Success" local worldspawn = First() PopExtUtil.PrecacheParticle("healthgained_red_giant") PopExtUtil.PrecacheParticle("healthgained_blu_giant") //add to popext namespace so it gets cleaned up with everything else PopExt._TankRepair <- { function OnScriptHook_OnTakeDamage(params) { local victim = params.const_entity // avoids infinite loop if (victim.IsEFlagSet(EFL_USER)) return local attacker = params.attacker local oldhealth = victim.GetHealth() local weapon = params.weapon if ( !attacker || !weapon || !attacker.IsPlayer() || victim.GetClassname() != "tank_boss" || victim.GetHealth() >= victim.GetMaxHealth() ) return local is_wrench = weapon.GetClassname() == "tf_weapon_wrench" || weapon.GetClassname() == "tf_weapon_robot_arm" local metal = GetPropIntArray(attacker, "m_iAmmo", TF_AMMO_METAL) if ( is_wrench && attacker.GetTeam() == victim.GetTeam() && metal > 0) { local newmetal = metal - METAL_PER_HIT if (newmetal < 0) newmetal = 0 local repair_mult = weapon.GetAttribute("Repair rate decreased", 1.0) // if (weapon.GetAttribute("Repair rate increased", 0)) // repair_mult = repair_mult * (1 + weapon.GetAttribute("Repair rate increased", 0)) // if some weird custom weapon has both just use the increased one if (weapon.GetAttribute("Repair rate increased", 0.0)) repair_mult = weapon.GetAttribute("Repair rate increased", 1.0) local newhealth = oldhealth + ( ( (metal - newmetal) * HEALTH_PER_METAL_RATIO ) * repair_mult ) victim.SetHealth(newhealth > victim.GetMaxHealth() ? victim.GetMaxHealth() : newhealth) SetPropIntArray(attacker, "m_iAmmo", newmetal, TF_AMMO_METAL) // fire takedamage so the healthbar updates victim.AddEFlags(EFL_USER) victim.TakeDamage(0, DMG_GENERIC, worldspawn) victim.RemoveEFlags(EFL_USER) local particle = victim.GetTeam() == TF_TEAM_PVE_INVADERS ? "healthgained_blu_giant" : "healthgained_red_giant" DispatchParticleEffect(particle, victim.GetOrigin() + HEAL_PARTICLE_OFFSET, HEAL_PARTICLE_OFFSET) StopSoundOn("Weapon_Wrench.HitWorld", attacker) EmitSoundOn(HEAL_SOUND, weapon) EmitSoundOnClient(HEAL_SOUND, attacker) } } } __CollectGameEventCallbacks(PopExt._TankRepair)