Two Entities doing something together

im having a tad of a problem.
How can i make a code that says this-
If (first entity) touches (second entity)then remove (first entity) then Add up the number of (first entity[s])that have touched it and been removed. and when 3 of the (first entity[s]) have touched (second entity) and has been removed,run (a function) and then set the number of entities that it has touched, to 0.

Can someone tell me how exactly i would make something like this?

As much gibberish as that was;

**[ENT.Touch

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=ENT.Touch)**

Let’s hope you’re trying to do this to entities…

Only somewhat helpful.
function ENT:Touch( hitEnt )
if hitEnt = NormDrugs then
hitEnt.Remove (Add Ent function here)
end
end

More along the lines of this:

[lua]
function ENT:Touch(hitEnt)
local TimesHit = 0
if hitEnt:IsValid() and !hitEnt:IsPlayer() and hitEnt:GetClass() == “NormDrugs” then
hitEnt:Remove()
local TimesHit = TimesHit + 1
end
if TimesHit >= 3 then
local TimesHit = 0
end
end
[/lua]

[lua]
function ENT:Touch(hitEnt)
local TimesHit = 0
local TimesHitM = 0
if hitEnt:IsValid() and hitEnt:GetName() == “NormDrugs” then
hitEnt:Remove()
local TimesHit = TimesHit + 1
else if hitEnt:IsValid() and hitEnt:GetName() == “mixed drugs” then
hitEnt:Remove()
local TimesHitM = TimesHitM + 1
end

if TimesHit >= 3 then do
function ENT:MakeMixed
timer.Create( “DMtimer”, 120, 1, function()
self.Entity.CanUse = true
local userb = self.drug_user
local drugPos = self:GetPos()
drug = ents.Create(“mixed_drugs”)
drug:SetPos(Vector(drugPos.x,drugPos.y,drugPos.z + 35))
drug.dt.owning_ent = userb
drug.SID = userb.SID
drug.ShareGravgun = true
drug.nodupe = true
drug:Spawn()
self.sparking = false
local TimesHit = 0
end
end
else if TimesHitM >= 3 then do
function ENT:MakeSuper
timer.Create( “DStimer”, 350, 1, function()
self.Entity.CanUse = true
local userb = self.drug_user
local drugPos = self:GetPos()
drug = ents.Create(“super_drugs”)
drug:SetPos(Vector(drugPos.x,drugPos.y,drugPos.z + 35))
drug.dt.owning_ent = userb
drug.SID = userb.SID
drug.ShareGravgun = true
drug.nodupe = true
drug:Spawn()
self.sparking = false
local TimesHitM = 0
end

					end  
			end  
		end
	end
end

end

[/lua]

This Should tell it that if it hits three norm drugs, it makes ONE mixed drugs after 2 mins (120 seconds). and if three mixed drugs, makes a super drug after 5 mins.

Please edit this for me, because i got confused with all of the ends and such. there also might be syntax errrs but i get the general gist of it.
thanks!

[editline]05:02AM[/editline]

Heres the Entire LUA for the ENT im making:
[lua]
AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)

include(“shared.lua”)

function ENT:Initialize()
self:SetModel(“models/props_lab/powerbox02b.mdl”)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys and phys:IsValid() then phys:Wake() end
self.sparking = false
self.damage = 100
local ply = self.dt.owning_ent
self.Entity.SID = ply.SID
self.SID = ply.SID
self.Entity.CanUse = false
self.ShareGravgun = true
end

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

function ENT:Destruct()
local vPoint = self:GetPos()
local effectdata = EffectData()
effectdata:SetStart(vPoint)
effectdata:SetOrigin(vPoint)
effectdata:SetScale(1)
util.Effect(“Explosion”, effectdata)
end

function ENT:Use(activator,caller)
if not self.Entity.CanUse then return false end
self.Entity.CanUse = false
self.drug_user = activator
if activator.maxDrugs and activator.maxDrugs >=
GetConVarNumber(“maxdrugs”) then
Notify(activator, 1, 3, “You can’t make anymore drugs as the
limit is reached.”)
timer.Simple(0.5, function() self.Entity.CanUse = true end)
else
self.sparking = true
timer.Create(self:EntIndex() … “drug”, 1, 1,
self.createDrug, self)
end
end

function ENT:Touch(hitEnt)
local TimesHit = 0
local TimesHitM = 0
if hitEnt:IsValid() and hitEnt:GetName() == “NormDrugs”
then
hitEnt:Remove()
local TimesHit = TimesHit + 1

            else if hitEnt:IsValid() and 
            hitEnt:GetName() == "mixed drugs" then
            hitEnt:Remove()

            local TimesHitM = TimesHitM + 1

end

if TimesHit >= 3 then do

function ENT:MakeMixed
timer.Create( “DMtimer”, 120, 1, function()
self.Entity.CanUse = true
local userb = self.drug_user
local drugPos = self:GetPos()
drug = ents.Create(“mixed_drugs”)
drug:SetPos(Vector(drugPos.x,drugPos.y,drugPos.z + 35))
drug.dt.owning_ent = userb
drug.SID = userb.SID
drug.ShareGravgun = true
drug.nodupe = true
drug:Spawn()
self.sparking = false
local TimesHit = 0
end
end
end
end
end
end

if TimesHitM >= 3 then do
function ENT:MakeSuper
timer.Create( “DStimer”, 350, 1, function()
self.Entity.CanUse = true
local userb = self.drug_user
local drugPos = self:GetPos()
drug = ents.Create(“super_drugs”)

          drug:SetPos(Vector(drugPos.x,drugPos.y,drugPos.z + 35))
          drug.dt.owning_ent = userb
          drug.SID = userb.SID

drug.ShareGravgun = true
drug.nodupe = true
drug:Spawn()
self.sparking = false
    local TimesHitM = 0
   end

end
end
end
end

function ENT:OnRemove()
self:Destruct()
timer.Destroy(self)
end
[/lua]