How to get a prop to remove itself after taking too much damage

I’m putting the finishing touches on a custom TTT wep, all that I need it to do is remove itself from the world once it takes a certain amount of damage. The way the weapon works is that the player can left click to attach a prop to a surface, then right click to detonate the prop.

Here’s the significant code



function SWEP:plant_bomb(model_file)
	if not self:CanPrimaryAttack() then return end
	 local trace = {}
        trace.start = self.Owner:GetShootPos()
        trace.endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 64
        trace.mask = MASK_NPCWORLDSTATIC
        trace.filter = self.Owner
        local tr = util.TraceLine( trace )
 
        if ( tr.Hit ) then
                if SERVER then
                        local ent = ents.Create ("prop_ragdoll")
						ent:SetModel("models/glowstick/stick.mdl")
                        if IsValid(ent) then
                                ent:SetPos(tr.HitPos)
                                ent:SetOwner(self.Owner)
                                ent:Spawn()
								bomb = ent
								bomb.OurHealth = 25
                                ent:Activate()
                                ent.fingerprints = self.fingerprints
                                self.Owner:EmitSound( "weapons/c4/c4_plant.wav" )
                                self.Owner:SetAnimation(PLAYER_ATTACK1)
                                self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
								canExplode = true
								self:TakePrimaryAmmo(1)
								
                        end
                end
        end
end

	


function SWEP:PrimaryAttack()
	if ( !self:CanPrimaryAttack() ) then return end
	
	self:plant_bomb("downloads/models/glowstick/stick.mdl")

	self:SetNextSecondaryFire( CurTime() + 10 )
end

function SWEP:SecondaryAttack(ent)
	if(canExplode == true) then
	ent = bomb
	local explode = ents.Create("env_explosion")
	explode:SetPos(ent:GetLocalPos())
	explode:SetOwner(self.Owner)
	explode:Spawn()
	explode:SetKeyValue("iMagnitude", "2200")
	explode:Fire("Explode", 0, 0)
	explode:EmitSound("BaseExplosionEffect.Sound", 400, 400)
	util.BlastDamage(ent, self.Owner, ent:GetLocalPos(), 600, 50)
	bomb:Remove()
	canExplode = false
	else
	print("No bomb in world")
	end

end

function bomb:OnTakeDamage(dmg)
	bomb:TakePhysicsDamage(dmg)
	if(bomb.OurHealth <= 0) then return end
	bomb.OurHealth = bomb.OurHealth - dmg:GetDamage()
	if(bomb.OurHealth <= 0) then
		bomb:Remove()
	end
end


Everything works fine except for the OnTakeDamage method and I’m not sure what to do.

[editline]3rd June 2013[/editline]

bump

this thread goes here.