Quick Question



function ENT:Initialize()
	self:SetModel("models/props_c17/consolebox03a.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
	local phys = self:GetPhysicsObject()
	if phys:IsValid() then phys:Wake() end
	self.damage = 100
end

function ENT:OnTakeDamage(dmg)
	self.damage = (self.damage or 100) - dmg:GetDamage()
	if self.damage <= 0 then
			self:Remove()
	end
end

function ENT:OnRemove()
	if attacker then
		print( "Yay!" )
		else
		print( "Nay!" )
	end
end


The entity is made to say “Yay!” if the “attacker” destroy it and if the attacker didn’t destroy it it will say “Nay!”. I looked up on Garry’s mod Wiki and I couldn’t find a answer to “attacker.”
Thanks!

But the person destroying the entity is ALWAYS going to be the attacker?

Also, you can’t get the attacker in the OnRemove function, only in the OnTakeDamage function, using



dmg:GetAttacker()


As far as I know

How about this?



function ENT:OnRemove(attacker)
	if self:GetOwner() == ply then 
		print( "Nay!" )
	else (attacker:IsPlayer()) then
		print( "Yay!" )
	end
end


Well, Ent:OnRemove() doesn’t actually have an attacker argument so the else statement wouldn’t work

This might though:



function ENT:OnTakeDamage(dmg)
	self.damage = (self.damage or 100) - dmg:GetDamage()
	if self.damage <= 0 then

		if self:GetOwner() == ply then 
			print( "Nay!" )
		elseif (dmg:GetAttacker():IsPlayer()) then
			print( "Yay!" )
		end

	self:Remove()
	end
end


Note you’d need to actually DEFINE what ply was, though.

So what should I do make it work?

Well, to get it to work you just need to define ply and make sure you’re trying to get the attacker in the OnTakeDamage function… but what are you actually trying to do with this?

Are you trying to check if the owner of the entity killed it or something? If so, you could just do



if dmg:GetAttacker() == self:GetOwner() then


In the OnTakeDamage function

Thank U solved my problems :slight_smile: