ENT:Touch(hitEnt) help

My entitys name is Metal and the entity I’m trying to create when two metal’s touch is pistol_bullet. So my problem is when I try and touch two metal’s together it creates three pistol_bullet’s and I only want it to create one pistol_bullet. If someone could help me make it so it only spawns one pistol_bullet that would be great.

[LUA]
function ENT:Touch(hitEnt)

if hitEnt:GetClass() == "metal" then
hitEnt:Remove()
RunConsoleCommand("SpawnMyEnt6")
end

end
– My function to create pistol_bullet
[/LUA]

My Spawn function for pistol_bullet

[LUA]
local function SpawnMyEnt6(ply,cmd,args)
local tr = ply:GetEyeTrace()
local ent = ents.Create(“pistol_bullet”)
ent:SetPos( tr.HitPos + tr.HitNormal * 16 )
ent:SetAngles(ply:GetAngles())
ent:Spawn()
end
concommand.Add(“SpawnMyEnt6”,SpawnMyEnt6)
[/LUA]

Possibly, the metal touches the other entity 3 times before the “frame”, talking about FPS, reacts or what the hell you wanna call it.

Try this:



Craft = 0
function ENT:Touch(hitEnt)
	if (CurTime() >= Craft) then
	if (hitEnt:GetClass() == "metal") then
		Craft = CurTime() + 1
	hitEnt:Remove()
	RunConsoleCommand("SpawnMyEnt6")
		end
	end
end


Untested.

It works but only one gets removed. Any ideas how to get both of them to be removed?

Try this:



Craft = 0
function ENT:Touch(self, hitEnt)
	if (CurTime() >= Craft) then
	if (hitEnt:GetClass() == "metal") then
		Craft = CurTime() + 1
	hitEnt:Remove()
        self:Remove()
	RunConsoleCommand("SpawnMyEnt6")
		end
	end
end


Untested.



Craft = 0
function ENT:Touch(self, hitEnt)
    if (CurTime() >= Craft) and hitEnt:GetClass() == "metal" then
        Craft = CurTime() + 1
        hitEnt:Remove()
        **self.Entity**:Remove()
    RunConsoleCommand("SpawnMyEnt6")
    end
end


Little correction there.



Craft = 0
function ENT:Touch(self, hitEnt)
    if (CurTime() >= Craft) and hitEnt:GetClass() == "metal" then
        Craft = CurTime() + 1
        hitEnt:Remove()
        **self**:Remove()
    RunConsoleCommand("SpawnMyEnt6")
    end
end


How do people still not understand you only need to use self, it already knows it’s a god damn entity. Proper correction.

Also it should be either ENT.Touch(self, hitEnt) or ENT:Touch(hitEnt). I don’t know where ENT:Touch(self, hitEnt) is coming from.

[LUA]
Craft = 0
function ENT.Touch(self, hitEnt)
if (CurTime() >= Craft) and hitEnt:GetClass() == “metal” then
Craft = CurTime() + 1
hitEnt:Remove()
self:Remove()
RunConsoleCommand(“SpawnMyEnt6”)
end
end
[/LUA]
Worked, Thanks for the help guys!

Yea, I dont know when/where to put a colon or a single.